"code": -2014, "msg": "API-key format invalid." -- Binance API

248 Views Asked by At

I don't know how to solve this problem. I can run the code successfully, but the result is an empty Dataframe. On the webpage, the error is { "code": -2014, "msg": "API-key format invalid." }

code

'''

import requests
import time
import pandas as pd
pd.set_option('expand_frame_repr', False)

base_url = "https://api.binance.com"
api_path = "/sapi/v1/margin/allOrders"
timestamp = int(time.time()*1000)
limit = 500
timestamp = int(time.time()*1000)
end_time = int(time.time()//60*60*1000)
start_time = int(end_time-limit*60*1000)
API_KEY = 'my_api_key'
params = {
    'symbol': 'BTCUSDT',
    'startTime': str(start_time),
    'endTime': str(end_time),
    'timestamp': timestamp
}

headers = {
    'X-MBX-APIKEY': API_KEY
}

url = base_url+api_path

while True:

    print(url)
    response = requests.get(url, params = params, headers = headers)
    data=response.json()
    df=pd.DataFrame(data,columns={'clientOrderId':0, 'cummulativeQuoteQty':1, 'executedQty':2, 
                              'icebergQty':3, 'isWorking':4, 'orderId':5, 'origQty':6, 
                              'quoteQty':7, 'side':9,'status':10, 'stopPrice':11,
                              'symbol':12, 'isIsolated':13, 'time':14,
                              'timeInForce':15, 'type':16, 'selfTradePreventionMode':17, 
                              'updateTime':18})
    df.set_index('symbol', inplace= True)
    df.to_csv(("Query Margin Account's All Orders_1") + '.csv')
    print(df)

    if len(df)< 500:
        break
        end_time = start_time
        start_time = int(end_time - limit *60 * 1000)

'''

0

There are 0 best solutions below