Add mutual-exclusion gate between hedge plans and standalone options.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -143,18 +143,35 @@ def _max_active() -> int:
|
||||
|
||||
def _gates_dict(cfg: dict[str, Any], plan_type: str) -> dict[str, Any]:
|
||||
active = 0
|
||||
has_standalone = False
|
||||
mutual = True
|
||||
try:
|
||||
from lib.hedge_plan.hedge_options_exclusive_lib import (
|
||||
has_standalone_option_position,
|
||||
mutual_exclusive_enabled,
|
||||
)
|
||||
from lib.hedge_plan.hedge_plan_db import count_active_plans, init_hedge_plan_tables
|
||||
|
||||
mutual = mutual_exclusive_enabled()
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_hedge_plan_tables(conn)
|
||||
active = count_active_plans(conn)
|
||||
if mutual:
|
||||
try:
|
||||
from lib.exchange.okx_options_lib import fetch_option_positions
|
||||
|
||||
ex = cfg.get("exchange_options") or cfg.get("exchange")
|
||||
raw = fetch_option_positions(ex) if ex is not None else []
|
||||
has_standalone = has_standalone_option_position(conn, raw or [])
|
||||
except Exception:
|
||||
has_standalone = False
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
except Exception:
|
||||
active = 0
|
||||
has_standalone = False
|
||||
return gate_status(
|
||||
hedge_enabled=_hedge_enabled(),
|
||||
sizing_mode=load_position_sizing_mode(),
|
||||
@@ -166,6 +183,8 @@ def _gates_dict(cfg: dict[str, Any], plan_type: str) -> dict[str, Any]:
|
||||
max_active=_max_active(),
|
||||
show_perp_options=_show_perp_options(),
|
||||
show_options_options=_show_options_options(),
|
||||
mutual_exclusive=mutual,
|
||||
has_standalone_option=has_standalone,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user