Python Binance Api "Signature for this request is not valid" error

Viewed 17

Im trying to get market info via the REST API. This is my code:

import requests
import hmac
import hashlib



def getServerTime():
    return requests.get("https://api.binance.com/api/v3/time").json()["serverTime"]

def getSignature():

    query_string = f"timestamp={getServerTime()}"
    secret = "--------MY SECRET KEY-----------"
return hmac.new(secret.encode("utf-8"), query_string.encode("utf-8"), hashlib.sha256).hexdigest()

def getApiKey():
    return "-------MY API KEY------------"





def getAllCoinsInformation():
    parameters = {'timestamp':getServerTime(),'signature':getSignature()}
    headers = {"Content-Type": "application/json;","X-MBX-APIKEY":getApiKey()}
    return requests.get('https://api.binance.com/sapi/v1/capital/config/getall',headers=headers, params=parameters).json()

print(getAllCoinsInformation())

When i run program return is {'code': -1022, 'msg': 'Signature for this request is not valid.'}

So how to create valid signature in python. Any kind of suggestions can be accepted.

0 Answers
Related