Hi. I’m merchant. Support gave me api for p2p and i try to write bot for p2p trading. But some functions works, some not
This is work:
POST /sapi/v1/c2c/ads/getDetailByNo
Code below
import hmac
import time
import hashlib
import requests
from urllib.parse import urlencode
KEY = ""
SECRET = ""
BASE_URL = "https://api.binance.com"
def hashing(query_string):
return hmac.new(
SECRET.encode("utf-8"), query_string.encode("utf-8"), hashlib.sha256
).hexdigest()
def get_timestamp():
return int(time.time() * 1000)
def dispatch_request(http_method):
session = requests.Session()
session.headers.update(
{"Content-Type": "application/json;charset=utf-8", "X-MBX-APIKEY": KEY}
)
return {
"GET": session.get,
"DELETE": session.delete,
"PUT": session.put,
"POST": session.post,
}.get(http_method, "GET")
# used for sending request requires the signature
def send_signed_request(http_method, url_path, payload={}):
query_string = urlencode(payload, True)
if query_string:
query_string = "{}×tamp={}".format(query_string, get_timestamp())
else:
query_string = "timestamp={}".format(get_timestamp())
url = (
BASE_URL + url_path + "?" + query_string + "&signature=" + hashing(query_string)
)
print("{} {}".format(http_method, url))
params = {"url": url, "params": {}}
response = dispatch_request(http_method)(**params)
return response.json()
# used for sending public data request
def send_public_request(url_path, payload={}):
query_string = urlencode(payload, True)
url = BASE_URL + url_path
if query_string:
url = url + "?" + query_string
print("{}".format(url))
response = dispatch_request("GET")(url=url)
return response.json()
params = {
"adsNo":"11378191646449455104"
}
response = send_signed_request("POST", "/sapi/v1/c2c/ads/getDetailByNo", params)
print(response)
But when i try for example to change status of ad. I got an error
POST /sapi/v1/c2c/ads/updateStatus
code below
import hmac
import time
import hashlib
import requests
from urllib.parse import urlencode
KEY = ""
SECRET = ""
BASE_URL = "https://api.binance.com"
def hashing(query_string):
return hmac.new(
SECRET.encode("utf-8"), query_string.encode("utf-8"), hashlib.sha256
).hexdigest()
def get_timestamp():
return int(time.time() * 1000)
def dispatch_request(http_method):
session = requests.Session()
session.headers.update(
{"Content-Type": "application/json;charset=utf-8", "X-MBX-APIKEY": KEY}
)
return {
"GET": session.get,
"DELETE": session.delete,
"PUT": session.put,
"POST": session.post,
}.get(http_method, "GET")
# used for sending request requires the signature
def send_signed_request(http_method, url_path, payload={}):
query_string = urlencode(payload, True)
if query_string:
query_string = "{}×tamp={}".format(query_string, get_timestamp())
else:
query_string = "timestamp={}".format(get_timestamp())
url = (
BASE_URL + url_path + "?" + query_string + "&signature=" + hashing(query_string)
)
print("{} {}".format(http_method, url))
params = {"url": url, "params": {}}
response = dispatch_request(http_method)(**params)
return response.json()
# used for sending public data request
def send_public_request(url_path, payload={}):
query_string = urlencode(payload, True)
url = BASE_URL + url_path
if query_string:
url = url + "?" + query_string
print("{}".format(url))
response = dispatch_request("GET")(url=url)
return response.json()
params = {
"advNos": ["11378191646449455104"],
"advStatus": 0
}
response = send_signed_request("POST", "/sapi/v1/c2c/ads/updateStatus", params)
print(response)
I got an error
{'code': -1000, 'msg': 'An unknown error occurred while processing the request.'}
Please help. What am I doing wrong?