Hi,
I want to retrieve my crypto buy transactions using the API, however when I try to retrieve it using the endpoint /sapi/v1/fiat/orders
I always have an empty response.
As you can see in the attached image I have two transactions between 2022-02-01 and 2022-04-19.
Here is the code sample I’m using to reproduce the issue.
#!/usr/bin/python3 -u
from urllib.parse import urlencode
import datetime
import requests
import hashlib
import hmac
import time
import json
class BinanceConnector:
def __init__(self, api_key, api_secret):
self.api_key = api_key
self.api_secret = api_secret
self.session = requests.Session()
self.session.headers.update({
"Content-Type": "application/json;charset=utf-8",
"X-MBX-APIKEY": self.api_key,
})
self.url = "https://api.binance.com"
def __request(self, method, path, payload={}, auth=False):
url = '%s%s' % (self.url, path)
if auth:
payload["timestamp"] = self.__get_timestamp()
query_string = self.__query_string(payload)
signature = self.__generate_signature(query_string)
payload['signature'] = signature
params = {"url": url}
if payload:
params["params"] = self.__query_string(payload)
print(payload)
response = self._dispatch_request(method)(**params)
return response
def _dispatch_request(self, http_method):
return {
"GET": self.session.get,
"DELETE": self.session.delete,
"PUT": self.session.put,
"POST": self.session.post,
}.get(http_method, "GET")
def __get_timestamp(self):
return int(time.time() * 1000)
def __generate_signature(self, data):
hash = hmac.new(self.api_secret.encode("utf-8"), data.encode("utf-8"), hashlib.sha256)
return hash.hexdigest()
def __query_string(self, query):
if query == None:
return ''
else:
filtered_query = {}
for key in query.keys():
if query[key] is not None:
filtered_query[key] = query[key]
return urlencode(filtered_query, True).replace("%40", "@")
def get_fiat_deposit(self):
begin_time = datetime.datetime(2022, 2, 1, 12, 0, 0)
begin_time_timestamp = int(round(begin_time.timestamp()))*1000
end_time = datetime.datetime(2022, 4, 19, 12, 0, 0)
end_time_timestamp = int(round(end_time.timestamp()))*1000
payload = {
"transactionType": 0,
"beginTime": begin_time_timestamp,
"endTime": end_time_timestamp,
}
response = self.__request("GET", "/sapi/v1/fiat/orders", payload=payload, auth=True)
return response
my_api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
my_secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
connector = BinanceConnector(my_api_key, my_secret_key)
response = connector.get_fiat_deposit()
print(json.dumps(response.json(), indent=4))
And here is the output
$ ./get_fiat_deposit_sample.py
{'transactionType': 0, 'beginTime': 1643713200000, 'endTime': 1650362400000, 'timestamp': 1658143239445, 'signature': '6499ce486918fe199dacfb6937ee8b09dd3808bfb672c58ab55fcbf31851a19f'}
{
"code": "000000",
"message": "success",
"data": [],
"total": 0,
"success": true
}
Both beginTime
and endTime
fields seems to be correctly composed, however the response doesn’t contains any order.
Does anybody knows why I don’t have any order returned ?
Thanks in advance.