BingxAPI如何使用Python

问题描述 投票:0回答:2

这是我编写的代码,目的是从Bingx API获得用户平衡。
我认为我做的一切正确,但它无法正常工作。

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()
但是当我运行时,我会得到这个:

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

link

python trading
2个回答
0
投票

API_KEY

该数据将所有数据导入您的文件。我这样做是为了不将钥匙暴露在程序中。我用了
API_SECRET
config.p
。它不起作用!。

from config import *
当我使用

APIKEY=str(API_DETAILS.get('API_KEY'))

SECRETKEY=str(API_DETAILS.get('API_SECRET'))
中的代码中明确说明它时,它起作用了。我不知道为什么,因为在这两种情况下,
b'{"code":100413,"msg":"Incorrect apiKey","success":false,"timestamp":1688949058434}'

都是字符串。
APIKEY='XXX"

完美工作:
SECRETKEY="XXX"
    

type(APIKEY)

0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.