首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python-binance order_limit_buy() APIError(code=-1013):过滤失败: LOT_SIZE

python-binance order_limit_buy() APIError(code=-1013):过滤失败: LOT_SIZE
EN

Stack Overflow用户
提问于 2021-07-31 05:07:03
回答 1查看 425关注 0票数 1

我在使用python-binance执行限价买入订单时遇到了问题。卖出限制订单功能执行得很好。我的账户上有35.95302628美元的余额。0.06545172930180404 * 548.26772 USDT = 35.89 USDT

代码语言:javascript
复制
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)

回溯:

代码语言:javascript
复制
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
代码语言:javascript
复制
info = client.get_symbol_info('BCHUSDT')
print(info)

返回:

代码语言:javascript
复制
{'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

代码语言:javascript
复制
{'filterType': 'LOT_SIZE', 'minQty': '0.00001000', 'maxQty': '90000.00000000', 'stepSize': '0.00001000'}

我的订单量大于'minQt': '0.00001000'

我也尝试了精度(数量)为8,并收到了相同的错误。

如有任何建议,我们将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2021-09-15 19:04:00

LOT_SIZE是您正在使用的小数位数。您的订单必须符合您的案例中的'stepSize‘:0.00001000

代码语言:javascript
复制
0.06545172930180404
      ^
0.00001

0.06545 ->你的价值必须是这样的

我做了一个算法,并在github上提供了一个函数,根据'stepSize‘https://github.com/gustavoara/binance-lot_size对值进行四舍五入

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68599281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档