感谢您抽出时间查看我的问题。我正在努力使用python binance下订单,特别是永久期货市场订单。我不认为这是重复的,但在python binance(以及其他软件包)上有几个关于相同错误代码的查询(因此我不认为这是python binance的问题,我理解这是一个问题),不幸的是,似乎没有一个成功的解决方案
https://github.com/sammchardy/python-binance/issues/57
https://github.com/sammchardy/python-binance/issues/184
错误代码表示精度超过该符号允许的最大值。就我所知(或至少对于我感兴趣的仪器而言),baseAssetPrecision始终为8。然而,每种仪器也有不同的尺寸
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(代码=-1111):精度超过为此资源定义的最大值
我也尝试过包括十进制,但没有用
在过去的两天里,这一直是我生命中的祸根,任何帮助都将不胜感激。如果我没有提供一些细节,请告诉我
编辑:我有一个不满意的解决方案,就是通过二进制手动检查允许的位置大小。在这样做的过程中,我发现所需的精度与通过API请求符号信息时返回的精度大不相同
例如,请求信息时:
sym = 'BTCUSDT'
info = client.get_symbol_info(sym)
print(info)
它返回(在编写本文时):
{'symbol':'BTCUSDT','status':'TRADING','baseAssetPrecision':'BTC','baseAssetPrecision':8,'quoteAssetPrecision':8,'baseCommissionPrecision':8,'quoteCommissionPrecision':8,'orderTypes':['LIMIT','LIMIT'MAKER','MARKET','STOP'LOSS'LIMIT','TAKE'PROFIT'],'icebergAllowed':True,'ocoAllowed':True,'quoteOrderQtyMarketAllowed':True,'isSpotTradingAllowed':True,'IsMargingTradingAllowed':True,'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名义值','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_ALGO_ORDERS','MaxNumGoorders':5},'permissions':['SPOT','MARGIN']
然而,通过手动检查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
谢谢大家的帮助
你将设定期货头寸。但是请求spot的配对信息。 对于期货对,您可以通过调用.futures\u exchange\u info()获得精度
您可以调用api来检索步长,而不是使用硬代码精度:
Reference
为你们简化了,给你们:
相关问题 更多 >
编程相关推荐