'Binance API Issue - Python

APIError(code=-2015): Invalid API-key, IP, or permissions for action

I keep getting the above issue.

I am not sure what the issue is.

I am able to access the client.get_all_tickers() command no problem but when I try to place an order or access user_data (both which require a signature) I get the error APIError(code=-2015): Invalid API-key, IP, or permissions for action

I think the issue has something to do with the signature. I checked to see if I have the relevant permissions enabled and I do. Furthermore, I tried to create a new API key and I still go the same issue.

NOTE: I am using binance.us not binance.com because I am located in the US so I cannot make an account on binance.com

Therefore, another idea I had was to create a VPN that places me in England so I can make an account through binance.com and maybe that will work.

import time
import datetime
import json
from time import sleep
from binance.client import Client 
from binance.enums import *
import sys
import requests, json, time, hashlib
import urllib3
import logging
from urllib3 import PoolManager
from binance.exceptions import BinanceAPIException, BinanceWithdrawException

r = requests.get('https://www.binance.us/en/home')


client = Client(API_key,Secret_key,tld="us")
prices = client.get_all_tickers()


#Def to get location
def crypto_location(sym):
    count = 0
    for i in prices:
        count += 1
        ticker = i.get('symbol')
        if ticker == sym:
            val = i.get('price')
            count = count-1
            return count
        
bitcoin_location = crypto_location('BTCUSDT')
ethereum_location = crypto_location('ETHUSDT')
stable_coin_location = crypto_location('BUSDUSDT')
bitcoin_as_BUSD_location = crypto_location('BTCBUSD')

#%% Where to quickly get bitcoin price

t_min = time.localtime().tm_min

prices = client.get_all_tickers()

bitcoin_price = prices[bitcoin_location].get('price')
print(bitcoin_price)

ethereum_price = prices[ethereum_location].get('price')
print(ethereum_price)

stable_coin_price = prices[stable_coin_location].get('price')
print(stable_coin_price)

bitcoin_as_BUSD = prices[bitcoin_as_BUSD_location].get('price')
print(bitcoin_as_BUSD)


client.session.headers.update({ 'X-MBX-APIKEY': API_key})

client.get_account()

error occurs at client.get_account()



Solution 1:[1]

I had the same problem, the binance APIs without any IP restrictions, expire every 90 days. I have restricted the API to my IP and it works!

Still, you're sure to find it all here: https://python-binance.readthedocs.io/en/latest/index.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 EMKA