Fix CTP exchange routing for non-SHFE contracts and duplicate trade closes.
Resolve CZCE/DCE symbols to the correct exchange for orders, dedupe stop-loss closes and trade logs, and rely on CTP sync for authoritative records. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+18
-16
@@ -1639,23 +1639,25 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
lots=lots, price=price, settings=_settings_dict(),
|
||||
order_type="market",
|
||||
)
|
||||
write_manual_close_trade_log(
|
||||
conn,
|
||||
mon,
|
||||
symbol=sym,
|
||||
direction=direction,
|
||||
lots=lots,
|
||||
close_price=price,
|
||||
entry_price=entry or price,
|
||||
trading_mode=mode,
|
||||
capital=capital,
|
||||
stop_loss=float(mon["stop_loss"]) if mon and mon.get("stop_loss") is not None else None,
|
||||
take_profit=float(mon["take_profit"]) if mon and mon.get("take_profit") is not None else None,
|
||||
open_time=(mon.get("open_time") or "") if mon else "",
|
||||
symbol_name=(mon.get("symbol_name") or "") if mon else "",
|
||||
market_code=(mon.get("market_code") or "") if mon else "",
|
||||
)
|
||||
if not ctp_status(mode).get("connected"):
|
||||
write_manual_close_trade_log(
|
||||
conn,
|
||||
mon,
|
||||
symbol=sym,
|
||||
direction=direction,
|
||||
lots=lots,
|
||||
close_price=price,
|
||||
entry_price=entry or price,
|
||||
trading_mode=mode,
|
||||
capital=capital,
|
||||
stop_loss=float(mon["stop_loss"]) if mon and mon.get("stop_loss") is not None else None,
|
||||
take_profit=float(mon["take_profit"]) if mon and mon.get("take_profit") is not None else None,
|
||||
open_time=(mon.get("open_time") or "") if mon else "",
|
||||
symbol_name=(mon.get("symbol_name") or "") if mon else "",
|
||||
market_code=(mon.get("market_code") or "") if mon else "",
|
||||
)
|
||||
if mid:
|
||||
_close_duplicate_monitors(conn, sym, direction, mid)
|
||||
conn.execute(
|
||||
"UPDATE trade_order_monitors SET status='closed' WHERE id=?",
|
||||
(mid,),
|
||||
|
||||
Reference in New Issue
Block a user