如何在币安中通过ccxt下止买单

时间:2021-04-11 21:30:51

标签: binance ccxt

我尝试通过下面的代码来做到这一点,但出现错误

import ccxt  # noqa: E402
import apiConfig

exchange = ccxt.binance({
    'apiKey': apiConfig.API_KEY,
    'secret': apiConfig.API_SECRET,
    'enableRateLimit': True,
})

symbol = 'RVN/USDT'

type = 'limit'  # or 'market', other types aren't unified yet
side = 'buy'
amount = 69  # your amount
price = 0.21  # your price
# overrides
params = {
    'stopPrice': 0.20,  # your stop price
    'type': 'stopLimit',
}
order = exchange.create_order(symbol, type, side, amount, price, params)

我收到此错误: ccxt.base.errors.BadRequest:binance {"code":-1106,"msg":"不需要时发送参数'stopPrice'。"}

1 个答案:

答案 0 :(得分:1)

在这种情况下,ccxt 文档不正确(币安的止损限制,可能适用于其他交易所)。

您需要将 type 参数设置为 stop_loss_limittake_profit_limit(取决于 price 是否大于/小于 stopPrice)。此外,params.type 不会覆盖 type 值。

type = 'stop_loss_limit'

params = {
    'stopPrice': 0.20,
}

Binance API (docs) 仅在 stopPrice 为以下之一时接受 type 参数:

  • STOP_LOSS
  • STOP_LOSS_LIMIT
  • TAKE_PROFIT
  • TAKE_PROFIT_LIMIT

并且 ccxt (GitHub source) 仅从函数参数 uppercaseType 设置 type,并且不会覆盖来自 params 的值。