Realign market pair when hedge mode switches.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -403,6 +403,9 @@ async def put_strategy_settings(
|
|||||||
data = body.model_dump(exclude_none=True)
|
data = body.model_dump(exclude_none=True)
|
||||||
equity_to_apply: float | None = None
|
equity_to_apply: float | None = None
|
||||||
switch_to: str | None = None
|
switch_to: str | None = None
|
||||||
|
old_hedge = str(
|
||||||
|
db.get_setting("hedge_mode", s.hedge_mode) or s.hedge_mode or "perp_option"
|
||||||
|
).strip().lower()
|
||||||
|
|
||||||
if "exchange" in data:
|
if "exchange" in data:
|
||||||
new_ex = normalize_exchange_name(str(data.pop("exchange")))
|
new_ex = normalize_exchange_name(str(data.pop("exchange")))
|
||||||
@@ -611,6 +614,18 @@ async def put_strategy_settings(
|
|||||||
detail=f"交易所已切换为 {switch_to},但行情重连失败: {e}",
|
detail=f"交易所已切换为 {switch_to},但行情重连失败: {e}",
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
|
new_hedge = str(
|
||||||
|
db.get_setting("hedge_mode", s.hedge_mode) or s.hedge_mode or "perp_option"
|
||||||
|
).strip().lower()
|
||||||
|
if new_hedge != old_hedge and switch_to is None:
|
||||||
|
# 对冲模式切换:强制按新模式重对齐监控合约(ATM ↔ 虚值)
|
||||||
|
try:
|
||||||
|
from ..strategy.session import get_session
|
||||||
|
|
||||||
|
await get_session().ensure_atm_async(force=True)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
return _read_settings()
|
return _read_settings()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user