【问题标题】:Close position Binance Futures with ccxt使用 ccxt 平仓 Binance Futures
【发布时间】:2021-04-07 09:26:33
【问题描述】:

我正在尝试使用 ccxt ccxt-1.39.93、Python 3 平仓 Binance Futures。

# fetch position
position = binance.fetch_balance()['info']['positions']
pos = [p for p in position if p['symbol'] == "ETHUSDT"][0]

ticker = get_binance_futures(fetch_only=True)

close_position = binance.create_order(symbol=symbol, type="TAKE_PROFIT_MARKET", side="buy", amount=pos['positionAmt'], price=ticker , params={"closePosition": True, "stopPrice": ticker})    

我想平仓。但是得到了这个错误:

ccxt.base.errors.ExchangeError: binance {"code":-2021,"msg":"Order would immediately trigger."}

对于给定的交易品种,是否有一种简单的方法可以以市场或现货价格平仓?

【问题讨论】:

  • google the error message了吗?这些链接是否有助于解决问题?
  • 是的,已经尝试过了。找不到工作示例。
  • 听起来您的订单格式不正确。我建议您更改type 或研究什么是“止盈”订单。

标签: python binance ccxt


【解决方案1】:

经过一番挣扎,我终于找到了解决办法。

close_position = binance.create_order(symbol=symbol, type="MARKET", side="buy", amount=pos['positionAmt'], params={"reduceOnly": True})    

使用 reduceOnly 参数可以解决问题。 无需设置价格,因为它是 MARKET。

【讨论】:

    猜你喜欢
    • 2022-10-25
    • 2022-07-10
    • 2021-09-21
    • 2019-12-08
    • 1970-01-01
    • 2022-09-25
    • 2022-12-11
    • 2021-10-02
    • 2022-11-18
    相关资源
    最近更新 更多