我正在用python和ccxt库编写代码。我在试着做一个未来的机器人。我的机器人应该在对冲模式下运行,在我将我的偏好从单向模式转变为对冲模式之前,一切看起来都很好。为了解决这个问题,我寻找并尝试了我所能做的一切。这是我遇到的-错误:
binance {"code":-4061,"msg":"Order's position side does not match user's setting."}
所有的密码都是贝娄。
import ccxt
exchange = ccxt.binance({
'base_url': 'https://testnet.binancefuture.com',
'account_info': '/api/v3/account',
'enableRateLimit': True,
'apiKey': '...',
'secret': '...',
'hedgeMode': True,
'options': {
'defaultType': 'future',
},
})
exchange.set_sandbox_mode(True)
balance = exchange.fetch_balance()
balance
上面的代码工作得很好,虽然我使用的是测试网络,但出于安全原因,我也稍微更改了API凭据,除此之外,一切都是一样的。
我的问题是下面的代码
symbol = 'ETH/USDT'
typee = 'market' # or 'market', other types aren't unified yet
side1 = 'buy'
side2 = 'sell'
amount = 0.1 # your amount
#price = 0.21 # your price
# overrides
params = {
'position_side': 'LONG' and 'SHORT'
#'stopPrice': ,# your stop price
}
buy_market_order = exchange.create_order(symbol, typee, side1, amount, params)
#INCLUDE 'price' IF NEEDED
sell_market_order = exchange.create_order(symbol, typee, side2, amount, params)
发布于 2022-06-21 18:21:26
我认为,在下订单打开对冲头寸之前,您必须将头寸模式更改为hedged
:
symbol = 'ETH/USDT'
try:
exchange.set_position_mode(hedged=True, symbol=symbol) # ADD THIS
except Exception as e:
pass # swallow the error if you're already in hedge mode
typee = 'market' # or 'market', other types aren't unified yet
side1 = 'buy'
side2 = 'sell'
amount = 0.1 # your amount
#price = 0.21 # your price
# overrides
params = {
'positionSide': 'LONG' # and 'SHORT'
#'stopPrice': ,# your stop price
}
buy_market_order = exchange.create_order(symbol, typee, side1, amount, params)
#INCLUDE 'price' IF NEEDED
sell_market_order = exchange.create_order(symbol, typee, side2, amount, params)
https://stackoverflow.com/questions/72684256
复制相似问题