Api 说余额不足,而我有足够的

时间:2021-07-13 12:50:23

标签: python api binance

我正在尝试创建与 binance-api 的连接。但是当我尝试购买某种硬币时,在这种情况下是 PANCAKESWAP,我收到以下错误:

binance.exceptions.BinanceAPIException: APIError(code=-2010): 账户余额不足,无法执行请求的操作。

我知道我有足够的可用余额,我可以购买其他硬币。我不知道我需要在这里更改什么,下限价订单给了我同样的错误,并且在他们的网站上手动填写订单可以很好地使用完全相同的值。这已经困扰了我几个小时,几个线程并没有让我更明智。这是我的代码:

url = "https://api.binance.com/api"

api_secret = "X"
api_key = "X"

client = Client(api_key, api_secret)
client.API_URL = url

# get latest price from Binance API
coin_price = client.get_symbol_ticker(symbol=stringShot)
price = coin_price['price']

#get precision
info = client.get_symbol_info(stringShot)
print(info['filters'][2]['minQty'])
test = info['filters'][2]['minQty']
deci = test.index('1')  # precision is noted as 0.00001, so the index of 1 is the precision.
print(deci)

#get amount of usdt
balance = client.get_asset_balance(asset='USDT')
print(balance['free'])

usdt = (float(11)/float(price))  # buy 11 dollars worth of coin
quantity = float(round(usdt,(deci - 1))) # get the right precision by rounding the numbers 
print(usdt)
print(quantity)

#Convert it in order to buy for a certain amount of USDT
if float(balance['free'])>float(11):  # if there is more than 11 usdt available, buy
        pass

else:
        print("Not enough USDT available.")
        

order = client.create_order(
        symbol=stringShot,
        side=Client.SIDE_BUY,
        type=Client.ORDER_TYPE_MARKET,
        quantity=quantity
)  #market order for buying the coin

0 个答案:

没有答案