如何使用python-binance下期货市场订单:APIError(code=-1111):Precisionisoverthemaximumdefinedforthisasset

感谢您抽出时间查看我的问题。我正在努力使用 python-binance 下订单,特别是永久期货市场订单。我不相信这是这里的重复,但是在 python-binance(以及其他包)上有几个关于相同错误代码的查询,所以我不相信这是一个 python-binance 问题,这是我的问题理解),不幸的是,似乎没有一个成功的解决方案。

https://github.com/sammchardy/python-binance/issues/57

https://github.com/sammchardy/python-binance/issues/184

错误代码表明精度超过了该符号所允许的最大值。据我所知(或至少对于我感兴趣的工具),baseAssetPrecision 始终为 8。但是,每个工具也有一个不同的 tickSize。

from binance.client import Client
from binance.enums import *
from binance.exceptions import BinanceAPIException, BinanceOrderException
from decimal import Decimal

api_key = 'YOURAPIKEY'
api_secret = 'YOURAPISECRET'

client = Client(api_key, api_secret)

#tick_size = {'BTCUSDT': 6, 'ETHUSDT': 5, 'XRPUSDT': 1, 'LINKUSDT': 2}

trade_size = 10 # The trade size we want in USDT
sym = 'BTCUSDT' # the symbol we want to place a market order on
tick_size = 6 # the tick_size as per binance API docs
price = 19000 # Just making this up for now to exemplify, this is fetched within the script

trade_quantity = trade_size / price # Work out how much BTC to order
trade_quantity_str = "{:0.0{}f}".format(trade_quantity, tick_size)

#print(trade_quantity_str)
#0.000526

#PLACING THE ORDER
client.futures_create_order(symbol=sym, side='BUY', type='MARKET', quantity=trade_quantity)

结果是...

BinanceAPIException:APIError(code=-1111):精度超过了为此资产定义的最大值。

我也试过包括十进制但无济于事。

在过去的 2 天里,这一直是我生活的祸根,任何帮助将不胜感激。如果我没有包含可能有帮助的细节,请告诉我。

编辑:我对此有一个不满意的解决方案,即通过币安手动检查允许的头寸大小。在这样做时,我发现所需的精度与通过 API 请求符号信息时返回的精度有很大不同。

例如,当请求信息时:

sym = 'BTCUSDT'
info = client.get_symbol_info(sym)
print(info)

它返回(在撰写本文时):

{'symbol':'BTCUSDT','status':'TRADING','baseAsset':'BTC','baseAssetPrecision':8,'quoteAsset':'USDT','quotePrecision':8,'quoteAssetPrecision':8 , 'baseCommissionPrecision': 8, 'quoteCommissionPrecision': 8, 'orderTypes': ['LIMIT', 'LIMIT_MAKER', 'MARKET', 'STOP_LOSS_LIMIT', 'TAKE_PROFIT_LIMIT'], 'icebergAllowed': True, '真, 'quoteOrderQtyMarketAllowed': True, 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': True, 'filters': [{'filterType': 'PRICE_FILTER', 'minPrice': '0.01000000', 'maxPrice'0000000000滴答大小':'0.01000000'},{'filterType':'PERCENT_PRICE','multiplierUp':'5','multiplierDown':'0.2','avgPriceMins':5},{'filterType':'LOT_SIZE','minQty':'0.00000100','maxQty' :'9000.00000000','stepSize':'0.00000100'},{'filterType':'MIN_NOTIONAL','minNotional':'10.00000000','applyToMarket':True,'avgPriceMins':'过滤器': ICEBERG_PARTS', 'limit': 10}, {'filterType': 'MARKET_LOT_SIZE', 'minQty': '0.00000000', 'maxQty': '247.36508140', 'stepSize': '0.000}0000filter' MAX_NUM_ORDERS', 'maxNumOrders': 200}, {'filterType': 'MAX_NUM_ALGO_ORDERS', 'maxNumAlgoOrders': 5}], 'permissions': ['SPOT', 'MARGIN']}

但是,通过手动检查币安,我可以看到它只允许最多三位小数的交易......我看不出如何通过使用上面返回的信息来实现这一点。

***** 编辑 2 *****

感谢下面的回复,我已经整理了一个解决方案,该解决方案足以满足我的需要

from binance.client import Client
from binance.enums import *
from binance.exceptions import BinanceAPIException, BinanceOrderException
from decimal import Decimal

api_key = 'YOURAPIKEY'
api_secret = 'YOURAPISECRET'

client = Client(api_key, api_secret)

#tick_size = {'BTCUSDT': 6, 'ETHUSDT': 5, 'XRPUSDT': 1, 'LINKUSDT': 2}

trade_size = 10 # The trade size we want in USDT
sym = 'BTCUSDT' # the symbol we want to place a market order on
tick_size = 6 # the tick_size as per binance API docs
price = 19000 # Just making this up for now to exemplify, this is fetched within the script

trade_quantity = trade_size / price # Work out how much BTC to order
trade_quantity_str = "{:0.0{}f}".format(trade_quantity, tick_size)

#print(trade_quantity_str)
#0.000526

#PLACING THE ORDER
client.futures_create_order(symbol=sym, side='BUY', type='MARKET', quantity=trade_quantity)

感谢大家的帮助!

回答

而是使用硬编码精度,您可以调用 api 来检索 stepSize:

symbol_info = client.get_symbol_info('BTCUSDT')
step_size = 0.0
for f in symbol_info['filters']:
  if f['filterType'] == 'LOT_SIZE':
    step_size = float(f['stepSize'])


precision = int(round(-math.log(stepSize, 10), 0))
quantity = float(round(quantity, precision))

client.futures_create_order(symbol=sym, side='BUY', type='MARKET', quantity=quantity)

参考


以上是如何使用python-binance下期货市场订单:APIError(code=-1111):Precisionisoverthemaximumdefinedforthisasset的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>