Add Binance SIM market adapter and exchange switch in settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-25 12:02:36 +08:00
parent 5dcec0fde0
commit 78fd046fb6
25 changed files with 879 additions and 45 deletions
+1 -1
View File
@@ -154,7 +154,7 @@ class StrategyEngine:
ymd = upl.get("expiry_ymd")
if ymd:
try:
from ..exchange.okx.parse import expiry_ms_from_ymd
from ..exchange.expiry import expiry_ms_from_ymd
return int(expiry_ms_from_ymd(str(ymd)))
except Exception:
+2 -2
View File
@@ -25,7 +25,7 @@ def hours_until_expiry(
if expiry_ms is not None:
return hours_until_ms(expiry_ms, now)
# 兼容测试:无 ms 时按 OKX 惯例(UTC 08:00)推算
from ..exchange.okx.parse import expiry_ms_from_ymd
from ..exchange.expiry import expiry_ms_from_ymd
return hours_until_ms(expiry_ms_from_ymd(ymd), now)
@@ -76,7 +76,7 @@ def _complete_by_expiry(
if ymd in ms_map:
ems = ms_map[ymd]
else:
from ..exchange.okx.parse import expiry_ms_from_ymd
from ..exchange.expiry import expiry_ms_from_ymd
ems = expiry_ms_from_ymd(ymd)
out[ymd] = (ems, complete)
+7 -2
View File
@@ -286,7 +286,10 @@ class StrategySession:
return self.ex.snapshot(self.settings.perp_inst_id)
def snapshot_dict(self) -> dict[str, Any]:
return self.ex.snapshot_dict(self.settings.perp_inst_id)
d = self.ex.snapshot_dict(self.settings.perp_inst_id)
d["exchange"] = getattr(self.ex, "name", self.settings.exchange)
d["perp_inst_id"] = self.settings.perp_inst_id
return d
async def _refresh_loop(self) -> None:
while True:
@@ -328,7 +331,9 @@ set_gateway = set_session
def bootstrap_session(settings: Settings | None = None) -> StrategySession:
"""main 启动:创建交易所 + 策略会话。"""
s = settings or get_settings()
from ..exchange.runtime import load_runtime_settings
s = settings or load_runtime_settings()
ex = build_exchange(s)
set_exchange(ex)
sess = StrategySession(s, ex)