我在使用 python-binance 执行限价购买订单时遇到问题。限价卖单功能执行得很好。我的账户里有余额 35.95302628 USDT。 0.06545172930180404 * 548.26772 USDT = 35.89 USDT
.
self.client = Client(KEY, Secret)
def round_decimals_down(self, number:float, decimals:int=2):
"""
Returns a value rounded down to a specific number of decimal places.
"""
self.number = number
self.decimals = decimals
if not isinstance(self.decimals, int):
raise TypeError("decimal places must be an integer")
elif self.decimals < 0:
raise ValueError("decimal places has to be 0 or more")
elif self.decimals == 0:
return math.floor(self.number)
factor = 10 ** self.decimals
return math.floor(self.number * factor) / factor
def sell(self, symbol, offerSellPrice):
self.symbol = symbol
self.sellSymbol = (self.symbol + str("USDT"))
self.quantity = self.cursor.execute("SELECT " + self.symbol + "Quantity FROM Table WHERE tID = (SELECT MAX(tID) FROM Table)").fetchval()
self.offerSellPrice = offerSellPrice
self.order = self.client.order_limit_sell(symbol=self.sellSymbol,
quantity=self.round_decimals_down(self.quantity, 6),
price=self.round_decimals_down(self.offerSellPrice, 2))
def buy(self, symbol, cryptoQuantity, offerBuyPrice):
self.buySymbol = (symbol + str("USDT"))
self.cryptoQuantity = cryptoQuantity
self.offerBuyPrice = offerBuyPrice
self.order = self.client.order_limit_buy(symbol=self.buySymbol,
quantity=self.round_decimals_down(self.cryptoQuantity, 6),
price=self.round_decimals_down(self.offerBuyPrice, 2))
buy('BCH', 0.06545172930180404, 548.26772)
追溯:
Traceback (most recent call last):
File "c:\Users\User\Documents\CryptoBot\A9.py", line 891, in <module>
loop.run_until_complete(main())
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "c:\Users\User\Documents\CryptoBot\A9.py", line 881, in main
s.operations()
File "c:\Users\User\Documents\CryptoBot\A9.py", line 604, in operations
self.buy(self.cryptoToBuy, self.rawCryptoQuantityBCH, self.offerBuyPriceBCH)
File "c:\Users\User\Documents\CryptoBot\A9.py", line 422, in buy
self.order = self.client.order_limit_buy(symbol=self.buySymbol,
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 1460, in order_limit_buy
return self.order_limit(timeInForce=timeInForce, **params)
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 1424, in order_limit
return self.create_order(**params)
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 1387, in create_order
return self._post('order', True, data=params)
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 374, in _post
return self._request_api('post', path, signed, version, **kwargs)
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 334, in _request_api
return self._request(method, uri, signed, **kwargs)
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 315, in _request
return self._handle_response(self.response)
File "C:\Users\User\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 324, in _handle_response
raise BinanceAPIException(response, response.status_code, response.text)
binance.exceptions.BinanceAPIException: APIError(code=-1013): Filter failure: LOT_SIZE
info = client.get_symbol_info('BCHUSDT')
print(info)
返回:
{'symbol': 'BCHUSDT', 'status': 'TRADING', 'baseAsset': 'BCH', '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': '100000.00000000', 'tickSize': '0.01000000'}, {'filterType': 'PERCENT_PRICE', 'multiplierUp': '5', 'multiplierDown': '0.2', 'avgPriceMins': 5}, {'filterType': 'LOT_SIZE', 'minQty': '0.00001000', 'maxQty': '90000.00000000', 'stepSize': '0.00001000'}, {'filterType': 'MIN_NOTIONAL', 'minNotional': '10.00000000', 'applyToMarket': True, 'avgPriceMins': 5}, {'filterType': 'ICEBERG_PARTS', 'limit': 10}, {'filterType': 'MARKET_LOT_SIZE', 'minQty': '0.00000000', 'maxQty': '3410.06217369', 'stepSize': '0.00000000'}, {'filterType': 'MAX_NUM_ORDERS', 'maxNumOrders': 200}, {'filterType': 'MAX_NUM_ALGO_ORDERS', 'maxNumAlgoOrders': 5}], 'permissions': ['SPOT', 'MARGIN']}
LOT_SIZE
:
{'filterType': 'LOT_SIZE', 'minQty': '0.00001000', 'maxQty': '90000.00000000', 'stepSize': '0.00001000'}
我的订单数量大于'minQt': '0.00001000'
我也以 8 的精度(数量)进行了尝试,并收到了相同的错误。
任何建议,将不胜感激。