如何使用 python-binance 下期货市场订单:APIError(code=-1111): Precision is over the maximum defined for this asset

如何使用 python-binance 下期货市场订单:APIError(code=-1111): Precision is over the maximum defined for this asset

感谢您花时间查看我的问题。我正在努力使用 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): 精度超过为此资产定义的最大值。

我也试过包括 Decimal 但无济于事。

在过去的两天里,这一直是我生命中的祸根,我们将不胜感激任何帮助。如果我没有包含可能有帮助的详细信息,请告诉我。

编辑:我对此有一个不令人满意的解决方案,即通过 binance 手动检查允许的头寸规模。在这样做的过程中,我发现所需的精度与通过 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, ‘ocoAllowed’: True , ‘quoteOrderQtyMarketAllowed’: True, ‘isSpotTradingAllowed’: True, ‘isMarginTradingAllowed’: True, ‘filters’: [{‘filterType’: ‘PRICE_FILTER’, ‘minPrice’: ‘0.01000000’, ‘maxPrice’: ‘1000000.00000000’, ‘ tickSize’: ‘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’ : 5}, {‘filterType’: ‘ICEBERG_PARTS’, ‘limit’: 10}, {‘filterType’: ‘MARKET_LOT_SIZE’, ‘minQty’: ‘0.00000000’, ‘maxQty’: ‘ 247.36508140’,’stepSize’:’0.00000000’},{‘filterType’:’MAX_NUM_ORDERS’,’maxNumOrders’:200},{‘filterType’:’MAX_NUM_ALGO_ORDERS’,’maxNumAlgoOrders’:5}],’权限’:[ ‘现货’,’保证金’]}

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

\*\*\*\*\* 编辑 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)

info = client.futures_exchange_info() # request info on all futures symbols

for item in info['symbols']:

symbols_n_precision[item['symbol']] = item['quantityPrecision'] # not really necessary but here we are...

# Example $100 of BTCUSDT

trade_size_in_dollars = 100

symbol = "BTCUSDT"

price = 55000 # For example

order_amount = trade_size_in_dollars / price # size of order in BTC

precision = symbols_n_precision[symbol] # the binance-required level of precision

precise_order_amount = "{:0.0{}f}".format(order_amount, precision) # string of precise order amount that can be used when creating order

感谢大家的帮助!

原文由 Flipflop 发布,翻译遵循 CC BY-SA 4.0 许可协议


回答:

而是使用硬编码精度,您可以调用 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)

参考

原文由 Humberto Rodrigues 发布,翻译遵循 CC BY-SA 4.0 许可协议

以上是 如何使用 python-binance 下期货市场订单:APIError(code=-1111): Precision is over the maximum defined for this asset 的全部内容, 来源链接: utcz.com/p/938717.html

回到顶部