5

我正在尝试使用 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."}

是否有一种简单的方法可以以给定代码的市场或现货价格关闭当前头寸?

4

1 回答 1

8

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

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

使用 reduceOnly 参数就可以了。无需设置价格,因为它是市场。

于 2020-12-31T09:57:40.800 回答