Python二进制检测是否处于活动状态

2024-09-26 18:03:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用图书馆python-binance

当我连接binance客户端时,如果我尝试进行短期订购,如果Hedge模式未处于活动状态(more about Hedge mode activation),我会出现以下错误:

binance.exceptions.BinanceAPIException: APIError(code=-4061): Order's position side does not match user's setting.

守则:

from binance.client import Client

client = Client(
    api_key,
    api_secret,
    )

# Here : I want to get if client accoutn has hedge mode enable or not like : 

# hedge_mode = client.get_hedge_mode_active() <--- This method does not exists on library



order = client.futures_create_order(
    symbol = "XRPUSDT",
    side = SIDE_BUY,
    positionSide = "SHORT",
    type = ORDER_TYPE_MARKET,
    quantity = 500,
    )

Tags: clientapi客户端get图书馆modebinance模式
1条回答
网友
1楼 · 发布于 2024-09-26 18:03:30

positionSide是对冲模式,特别是。激活它允许您同时持有同一符号的多头和空头头寸

因此,如果您想要单向模式(而不是对冲模式),那么您只需要:

response = client.futures_create_order(
    timeInForce="GTC",
    symbol="BTCUSDT",
    side="BUY",
    type="LIMIT",
    quantity=1,
    price=1.00
)

要检查对冲模式是否激活,只需使用:

client.futures_get_position_mode() #This in python-binance

答复:

{
    "dualSidePosition": true // "true": Hedge Mode mode; "false": One-way Mode
}

来自binance API的文档:

https://binance-docs.github.io/apidocs/futures/en/#get-current-position-mode-user_data

相关问题 更多 >

    热门问题