![](/img/trans.png)
[英]Binance API: APIError(code=-1111): Precision is over the maximum defined for this asset. Python
[英]How to place a futures market order using 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 手動檢查允許的 position 大小。 這樣做時,我發現所需的精度與通過 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':真,'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':[ '現貨','保證金']}
但是,通過手動檢查幣安,我可以看到它只允許最多三位小數的交易......我看不出如何通過使用上面返回的信息來達到這一點。
***** 編輯 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
感謝大家的幫助!
而是使用硬編碼精度,您可以調用 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)
您將設置期貨 position。 但要求現場的配對信息。 對於期貨對,您可以通過調用 .futures_exchange_info() 獲得精確度
為你們簡化,這里是 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
在您的通話中
client.futures_create_order(symbol=sym, side='BUY', type='MARKET', quantity=trade_quantity)
變量trade_quantity = 10 / 19000 = 0.0005263157894736842
所以它的精度是 19 位。
在trade_quantity_str = "{:0.0{}f}".format(trade_quantity, tick_size)
您將精度修剪為 6 位數字,但這只是打印而不發送到 Binance。
很可能是這樣的:
client.futures_create_order(symbol=sym, side='BUY', type='MARKET', quantity=float(trade_quantity_str))
將解決這種情況。
就我而言,我搞砸了 testnet 和實際 binance 平台的模塊導入......我同時為https://testnet.binancefuture.com和“from binance.client”導入了“from binance_f”。 因此,僅導入“從 binance_f”導致交易執行並發送正確的 header 信息:'client_SDK_Version':'binance_futures-1.0.1-py3.7'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.