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
+6
View File
@@ -88,6 +88,8 @@ export type MarketSnapshot = {
connected: boolean;
updated_at_ms: number | null;
index_px: number | null;
exchange?: string;
perp_inst_id?: string;
pair: {
expiry_ymd: string;
strike: number;
@@ -180,5 +182,9 @@ export type StrategySettings = {
close_bid_mark_max_pct: number;
perp_qty_eth: number;
option_qty_eth: number;
exchange: "okx" | "binance";
perp_inst_id?: string;
option_inst_family?: string;
index_inst_id?: string;
ledger: { equity: number; available: number };
};
+3 -1
View File
@@ -124,7 +124,9 @@ export default function PlanPage() {
<div>
<h2 style={{ marginTop: 0 }}></h2>
<p style={{ color: "var(--muted)", marginTop: -8 }}>
SIM · ·
SIM · {" "}
{(snap?.exchange || "okx").toUpperCase()}
{snap?.perp_inst_id ? ` · ${snap.perp_inst_id}` : ""} ·
</p>
{err ? <div className="err">{err}</div> : null}
+28 -2
View File
@@ -35,6 +35,7 @@ export default function SettingsPage() {
const [perpQty, setPerpQty] = useState(1);
const [optQty, setOptQty] = useState(2);
const [initialEquity, setInitialEquity] = useState(10000);
const [exchange, setExchange] = useState<"okx" | "binance">("okx");
const [stratOk, setStratOk] = useState("");
useEffect(() => {
@@ -53,6 +54,7 @@ export default function SettingsPage() {
setPerpQty(s.perp_qty_eth ?? 1);
setOptQty(s.option_qty_eth ?? 2);
setInitialEquity(s.initial_equity ?? 10000);
setExchange(s.exchange === "binance" ? "binance" : "okx");
})
.catch(() => undefined);
}, []);
@@ -109,10 +111,11 @@ export default function SettingsPage() {
perp_qty_eth: perpQty,
option_qty_eth: optQty,
initial_equity: initialEquity,
exchange,
}),
});
setStratOk(
"策略参数已保存(模拟资金仅在数值变更且无持仓时重置账本",
"策略参数已保存(切换交易所/改模拟资金需无持仓;切换后会重连行情",
);
} catch (ex) {
setErr(ex instanceof Error ? ex.message : String(ex));
@@ -142,11 +145,34 @@ export default function SettingsPage() {
{tab === "strategy" ? (
<div className="card settings-card">
<p className="settings-lead">
OKX / SIM
</p>
{stratOk ? <div className="settings-ok">{stratOk}</div> : null}
{err && tab === "strategy" ? <div className="err">{err}</div> : null}
<form onSubmit={onSaveStrategy}>
<section className="settings-section">
<h3></h3>
<div className="settings-fields">
<div className="field">
<label htmlFor="exch">SIM </label>
<select
id="exch"
className="mono"
value={exchange}
onChange={(e) =>
setExchange(e.target.value === "binance" ? "binance" : "okx")
}
>
<option value="okx">OKXUSDC </option>
<option value="binance">USDT + </option>
</select>
<p className="settings-hint">
</p>
</div>
</div>
</section>
<section className="settings-section">
<h3></h3>
<div className="settings-fields">