Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem to use this version in python #1

Open
jaber-heidari opened this issue Jan 28, 2023 · 2 comments
Open

problem to use this version in python #1

jaber-heidari opened this issue Jan 28, 2023 · 2 comments

Comments

@jaber-heidari
Copy link

Please put a demo python code for using this version
I used the code that belong to spot api but it didn't work.
I get this response:
{"code":100001,"msg":"","success":false,"timestamp":1674818924644}

This is the code i use:
`
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()
`

@jaber-heidari jaber-heidari changed the title demo code this version problem to use this version in python Jan 28, 2023
@reza543momen
Copy link

Use this REZA
pip install bingX-connector # install from pypi
pip install -U bingX-connector # upgrade the package to the latest version

@reza543momen
Copy link

after all your program has two main problem:
first, "body" hasn't used in "def post"

def post(url, body ):
req = urllib.request.Request(url, ***data=body.encode("utf-8") ******,headers={'User-Agent': 'Mozilla/5.0','X-BX-APIKEY': APIKEY,}, method="POST")
return urllib.request.urlopen(req).read()
and second, How much do you want to BUY?
tradeOrder("BTC-USDT", "BUY", "MARKET", ***QUANTITY)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants