Trying to start using binance API (zero python experience, some R, some java). First tried R - binance.R, binancer. Moved to python. Copied a python code from gemini. This is what gemini suggested to compute signature:
def get_assets_info():
“”"
Retrieves account information from the Binance API.
“”"
url = “https://api.binance.com/api/v3/account”
api_key = “your_api_key” # Replace with your actual API key
api_secret = “your_api_secret” # Replace with your actual API secret
headers = {
“X-MBX-APIKEY”: api_key
}
timestamp = int(time.time() * 1000) # Get timestamp in milliseconds
params = {“timestamp”: timestamp}
URL encode the parameters
encoded_params = urlencode(params)
Combine timestamp and encoded params for signature message
message = f"{timestamp}{encoded_params}"
Sign the message using HMAC-SHA256 with your API secret
signature = hmac.new(api_secret.encode(), message.encode(), hashlib.sha256).hexdigest()
params[“signature”] = signature
print(“Encoded params:”, encoded_params)
print(“Signature:”, signature)
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
return response.json()
else:
print(“Error:”, response.text)
print("Response headers:", response.headers)
return None
-
My python says, among other comments: Error: {“code”:-2014,“msg”:“API-key format invalid.”}
-
After I enter the python-computed signature value at Postman, it says: “code”: -1102,
“msg”: “Mandatory parameter ‘signature’ was not sent, was empty/null, or malformed.”
Would appreciate comments. Another question - apart from python what are other popular languages to start using binance API. Thanks in advance.