I'm trying to place a new order using BingX API in python but I get this response: {"code":100001,"msg":"","success":false,"timestamp":1674818924644}
I use the following code to trade a new order:
import urllib.request
import json
import base64
import hmac
import time
import json
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="POST")
return urllib.request.urlopen(req).read()
def tradeOrder(symbol, side, tradeType):
paramsMap = {
"symbol": symbol,
"side": side,
"type": tradeType,
"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/trade/order?%s" % (APIURL, paramsStr)
return post(url, paramsStr)
def main():
tradeOrder("BTC-USDT", "BUY", "MARKET")
if __name__ == "__main__":
main()
What's wrong with this code?
I'm using the api v2, here's the link
source https://stackoverflow.com/questions/75270248/bingx-api-how-to-trade-order-in-perpetual-swap-api-v2
Comments
Post a Comment