Last active
July 25, 2020 03:31
-
-
Save uneasyguy/1e63a9e29c45e6ffa192a1dbd076d267 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
import requests | |
import hashlib | |
import hmac | |
import os | |
test = True | |
start = time() | |
api_key = os.getenv("api_key") | |
api_secret = os.getenv("api_secret") | |
tld = "com" | |
market = "OMGUSDT" | |
side = "BUY" | |
trade_quantity = 90 | |
_timestamp = int(time()*1000) | |
params = { | |
"newOrderRespType":"FULL", | |
"quantity":trade_quantity, | |
"side":side, | |
"symbol":market, | |
"timestamp":_timestamp, | |
"type":"MARKET" | |
} | |
query_string = '&'.join(["{}={}".format(x, params[x]) for x in params.keys()]) | |
signature = hmac.new(api_secret.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest() | |
params["signature"] = signature | |
headers = { | |
"Accept-Encoding": "gzip, deflate", | |
"Accept":"application/json", | |
"X-MBX-APIKEY":api_key, | |
"User-Agent":"copymedotio/python" | |
} | |
if test: | |
url = f"https://us-central1-copyme.cloudfunctions.net/binance_order_api/{tld}" | |
headers["X-MBX-APISECRET"] = api_secret | |
else: | |
url=f"https://api.binance.{tld}/api/v3/order" | |
r = requests.post(url=url,headers=headers,data=params) | |
print(r.status_code) | |
print(r.json()) | |
end = time()-start | |
print(f"Process took {end} seconds to complete") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment