HTTP 400 Error: size is too accurate. Smallest unit is 0.00000001

HTTP 400 Error: size is too accurate. Smallest unit is 0.00000001

我正在打电话给


authedClient.placeOrder(sellParams)

带参数:


sellParams:any = {
    'side': 'sell',
    'product_id': 'BTC-USD',
    'type': ‘market’,
    ’size’: 0.012613515
}

这会引发错误:

Error: HTTP 400 Error: size is too accurate. Smallest unit is 0.00000001
    at Request._callback (/srv/node_modules/coinbase-pro/lib/clients/public.js:68:15)
    at Request.self.callback (/srv/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)

我不确定为什么会失败。请指教

它说你应该只放置增量为 0.00000001 的大小(下面的 base_increment)。当您的 size 精度为 9: 0.012613515 时,它被拒绝了。

目前,我无法在 /products 端点中找到 base_increment,但在 status 频道中:

// Status Message
{
    "type": "status",
    "products": [
        {
            "id": "BTC-USD",
            "base_currency": "BTC",
            "quote_currency": "USD",
            "base_min_size": "0.001",
            "base_max_size": "70",
            "base_increment": "0.00000001", // Here you go
            "quote_increment": "0.01",
            "display_name": "BTC/USD",
            "status": "online",
            "status_message": null,
            "min_market_funds": "10",
            "max_market_funds": "1000000",
            "post_only": false,
            "limit_only": false,
            "cancel_only": false
        }
    ],
    ...
}

我可以添加一个更新,订单浮点数确实有点不稳定,并且因交易所而异。对于 CB/CB Pro,您需要获取关于 base_increment 卖单和 quote_increment 买单的信息,以字符串格式,运行 函数如下:

def get_increments(ticker, auth_client):
    products = auth_client.get_products()
    for i in range(len(products)):
        if products[i]['id'] == ticker:
            base_incr = products[i]['base_increment']
            quote_incr = products[i]['quote_increment']
    return base_incr, quote_incr

我。接下来,您需要利用这些增量进行舍入。我除以适当的增量,使用 floor 除以 1,然后乘以相同的增量。

二。为了安全起见,我使用字符串操作函数再次获得了一个小数计数,并且 运行 类似于 round(qty, decimals)。这会清除偶尔出现的滞后字符串 9999999 或 00000001。

三。如果您希望以 100% 的权益进行交易,请在买入(报价资产价值)中使用 funds 参数,在卖出(基础资产价值)中使用 size 参数。 购买代码类似于:

decimals = int(str(quote_incr).find('1'))-int(str(quote_incr).find('.'))
quote_incr = float(quote_incr)
qty = (qty/quote_incr//1)*quote_incr            
qty = str(round(qty,decimals))
auth_client.place_market_order(product_id=ticker, side='buy', funds=qty)

虽然销售代码看起来像:

decimals = int(str(base_incr).find('1'))-int(str(base_incr).find('.'))
base_incr = float(base_incr_
qty = (qty/base_incr//1)*base_incr            
qty = str(round(qty,decimals))
auth_client.place_market_order(product_id=ticker, side='buy', size=qty)