简体   繁体   English

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

[英]How to place a futures market order using python-binance: APIError(code=-1111): Precision is over the maximum defined for this asset

thanks for taking the time to check out my issue.感谢您花时间检查我的问题。 I'm struggling to place orders using python-binance, specifically a perpetual futures market order.我正在努力使用 python-binance 下订单,特别是永续期货市场订单。 I don't believe this is a duplicate on here but there have been several queries around the same error code on python-binance (as well as other packages so I don't believe it's a python-binance issue, it's an issue with my understanding), unfortunately, none seem to have a successful resolution.我不相信这是重复的,但是在 python-binance 上已经有几个关于相同错误代码的查询(以及其他包,所以我不相信这是 python-binance 问题,这是我的问题理解),不幸的是,似乎没有一个成功的解决方案。

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

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

The error code intimates that the precision is over the maximum allowed for that symbol.错误代码表明精度超过了该符号允许的最大值。 As far as I'm aware (or at least for the instruments I'm interested in) the baseAssetPrecision is always 8. However, each instrument also has a tickSize which varies.据我所知(或至少对于我感兴趣的工具),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)

Results in...结果是...

BinanceAPIException: APIError(code=-1111): Precision is over the maximum defined for this asset. BinanceAPIException: APIError(code=-1111): 精度超过为该资产定义的最大值。

I have also tried including Decimal but to no avail.我也尝试过包括 Decimal 但无济于事。

This has been the bane of my life for the last 2 days, any help would be gladly appreciated.在过去的两天里,这一直是我生命中的祸根,任何帮助将不胜感激。 If I've not included details that could help, please let me know.如果我没有提供可能有帮助的细节,请告诉我。

EDIT: I have an unsatisfactory solution to this which is to manually check the allowed position sizes via binance.编辑:对此我有一个不满意的解决方案,即通过 binance 手动检查允许的 position 大小。 In doing so I discovered that the required precision is vastly different to what is returned when requesting symbol info via the API.这样做时,我发现所需的精度与通过 API 请求符号信息时返回的精度大不相同。

For example, when requesting info:例如,在请求信息时:

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

it returns (at the time of writing):它返回(在撰写本文时):

{'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': ' {'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':真,'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}], 'permissions': ['SPOT', 'MARGIN']} 247.36508140','stepSize':'0.00000000'},{'filterType':'MAX_NUM_ORDERS','maxNumOrders':200},{'filterType':'MAX_NUM_ALGO_ORDERS','maxNumAlgoOrders':5}],'permissions':[ '现货','保证金']}

However, by checking on binance manually, I can see that it only allows trades up to three decimal places... I can't see how this could be arrived at by using the returned info above.但是,通过手动检查币安,我可以看到它只允许最多三位小数的交易......我看不出如何通过使用上面返回的信息来达到这一点。

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

Thanks to the responses below I've put together a solution which works well enough for what I need感谢下面的回复,我整理了一个解决方案,可以很好地满足我的需要

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

Thanks for the help everyone!感谢大家的帮助!

Instead use hardcode precision, you can call api to retrieve the stepSize:而是使用硬编码精度,您可以调用 api 来检索步长:

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)

Reference 参考

You are going to set futures position.您将设置期货 position。 But requesting pair info for spot.但要求现场的配对信息。 For futures' pairs you can get precision by calling.futures_exchange_info()对于期货对,您可以通过调用 .futures_exchange_info() 获得精确度

Simplified for you guys, here you go:为你们简化,这里是 go:

def get_quantity_precision(currency_symbol):    
    info = client.futures_exchange_info() 
    info = info['symbols']
    for x in range(len(info)):
        if info[x]['symbol'] == currency_symbol:
            return info[x]['pricePrecision']
    return None

In your call在您的通话中

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

variable trade_quantity = 10 / 19000 = 0.0005263157894736842 So its precision is 19 digits.变量trade_quantity = 10 / 19000 = 0.0005263157894736842所以它的精度是 19 位。

In trade_quantity_str = "{:0.0{}f}".format(trade_quantity, tick_size) you trim precision to 6 digits, but this is only printed not sent to Binance.trade_quantity_str = "{:0.0{}f}".format(trade_quantity, tick_size)您将精度修剪为 6 位数字,但这只是打印而不发送到 Binance。

Most probably something like:很可能是这样的:

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

will fix the situation.将解决这种情况。

In my case I messed up module imports for testnet and the actual binance platform...I imported "from binance_f" for https://testnet.binancefuture.com and "from binance.client" at the same time.就我而言,我搞砸了 testnet 和实际 binance 平台的模块导入......我同时为https://testnet.binancefuture.com和“from binance.client”导入了“from binance_f”。 So only importing "from binance_f" led to execution of the trade and sending the right header info: 'client_SDK_Version': 'binance_futures-1.0.1-py3.7'因此,仅导入“从 binance_f”导致交易执行并发送正确的 header 信息:'client_SDK_Version':'binance_futures-1.0.1-py3.7'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 币安 API:APIError(code=-1111):精度超过为该资产定义的最大值。 Python - Binance API: APIError(code=-1111): Precision is over the maximum defined for this asset. Python Binance API:APIError(code=-1111):精度超过了为该资产定义的最大值。 || Python - Binance API: APIError(code=-1111): Precision is over the maximum defined for this asset. || Python 精度超过为此资产定义的最大值。 python-binance 模块 - Precision is over the maximum defined for this asset. python-binance module 如何使用 python-binance 下达带有止盈和止损的期货市场订单 - How to place a Futures Market order with Take Profit and Stop Loss using python-binance 使用 python-binance 包装器放置 Binance 未来订单。 错误:APIError(代码=-1102):未发送强制参数“5e-05” - Place Binance Future Order using python-binance wrapper. Error: APIError(code=-1102): Mandatory parameter '5e-05' was not sent 精度超过为该资产定义的最大值。 币安? - Precision is over the maximum defined for this asset. Binance? 如何在 Binance API Python 上设置止盈止损的市场期货订单? - How to place a market futures order with take profit and stop loss on Binance API Python? Python Binance Futures - 创建止盈限价订单时出现问题 ->(APIError(代码=-2021):订单会立即触发。) - Python Binance Futures - problem creating Take Profit Limit order -> (APIError(code=-2021): Order would immediately trigger.) python-Binance api: APIError(code=-1013): Filter failure: LOT_SIZE - python-Binance api: APIError(code=-1013): Filter failure: LOT_SIZE Python-币安期货用户数据websocket - Python-binance futures user data websocket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM