[Python] bingx api How to get user balance with python

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    This is the code I wrote to get user balance from BingX API.
    I think I do everything correct but it doesn't work properly.

    import urllib.request
    import json
    import base64
    import hmac
    import time

    APIURL = "https://open-api.bingx.com"
    APIKEY = "MyApiKey"
    SECRETKEY = "MySecretKey"

    def genSignature(paramsStr):
    return hmac.new(SECRETKEY.encode("utf-8"),
    paramsStr.encode("utf-8"), digestmod="sha256").digest()

    def post(url, body):
    req = urllib.request.Request(url, headers={
    'User-Agent': 'Mozilla/5.0',
    'X-BX-APIKEY': APIKEY,
    }, method="GET")
    return urllib.request.urlopen(req).read()

    def getBalance():
    paramsMap = {
    "timestamp": int(time.time()*1000)
    }
    paramsStr = "&".join(["%s=%s" % (k, paramsMap[k]) for k in paramsMap])
    paramsStr += "&signature=" + genSignature(paramsStr).hex()
    url = "%s/openApi/swap/v2/user/balance?%s" % (APIURL, paramsStr)
    return post(url, paramsStr)

    def main():
    print(getBalance())

    if __name__ == "__main__":
    main()


    But when I run it I get this:

    b'{"code":100001,"msg":"","success":false,"timestamp":1675069039381}'


    This is the doc link

    Continue reading...

Compartilhe esta Página