Fix ghost open positions: dedupe tickets and reconcile against MT5.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -49,7 +49,8 @@ TODAY_STATS_MS = 2500 # 今日战绩(含 history)节流
|
||||
ATR_CACHE_MS = 2000
|
||||
DAY_OHLC_CACHE_MS = 1500
|
||||
HUB_FLOAT_MS = 3000 # 浮盈上报间隔
|
||||
HUB_RECONCILE_MS = 45000 # 历史回填/对账间隔(重)
|
||||
HUB_RECONCILE_MS = 8000 # 对账间隔:清掉中控幽灵持仓
|
||||
HUB_HISTORY_MS = 60000 # 历史平仓回填(较重)
|
||||
|
||||
BALANCE_HIGH = 10000.0
|
||||
BALANCE_LOW = 1000.0
|
||||
@@ -1031,6 +1032,7 @@ class OrderApp(tk.Tk):
|
||||
self._day_ohlc_cache: Tuple[float, Any] = (0.0, None) # (ts, dict)
|
||||
self._last_float_sync = 0.0
|
||||
self._last_reconcile_sync = 0.0
|
||||
self._last_history_sync = 0.0
|
||||
self._hub_sync_busy = False
|
||||
self._cached_today_stats: Optional[dict] = None
|
||||
self._build_ui()
|
||||
@@ -1713,8 +1715,11 @@ class OrderApp(tk.Tk):
|
||||
return
|
||||
self._last_float_sync = now
|
||||
do_reconcile = (now - float(self._last_reconcile_sync or 0)) >= HUB_RECONCILE_MS / 1000.0
|
||||
do_history = (now - float(self._last_history_sync or 0)) >= HUB_HISTORY_MS / 1000.0
|
||||
if do_reconcile:
|
||||
self._last_reconcile_sync = now
|
||||
if do_history:
|
||||
self._last_history_sync = now
|
||||
# 持仓快照在 UI 线程取,避免与刷新抢 MT5
|
||||
try:
|
||||
poss = self.bridge.positions(symbol)
|
||||
@@ -1742,7 +1747,7 @@ class OrderApp(tk.Tk):
|
||||
def run() -> None:
|
||||
try:
|
||||
reports = list(float_reports)
|
||||
if do_reconcile:
|
||||
if do_history:
|
||||
try:
|
||||
reports[0:0] = self.bridge.recent_close_reports(symbol, hours=48)
|
||||
except Exception:
|
||||
@@ -1752,11 +1757,11 @@ class OrderApp(tk.Tk):
|
||||
hub_client.report_trade(item)
|
||||
except Exception:
|
||||
pass
|
||||
if do_reconcile:
|
||||
try:
|
||||
hub_client.reconcile_trades(open_tickets, symbol)
|
||||
except Exception:
|
||||
pass
|
||||
# 对账:清掉中控多出来的幽灵持仓(与 MT5 实际持仓对齐)
|
||||
try:
|
||||
hub_client.reconcile_trades(open_tickets, symbol)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user