Sync exchange PnL when hub loads trade records API.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2440,6 +2440,11 @@ def insert_trade_record(
|
||||
opened_at_ms=open_ts_ms,
|
||||
closed_at_ms=close_ts_ms,
|
||||
)
|
||||
# 中控只拉 /api/trade_records,平仓当下也尝试回填交易所盈亏(内部 25s 节流)
|
||||
try:
|
||||
sync_trade_records_from_exchange(conn, force=False)
|
||||
except Exception:
|
||||
pass
|
||||
return tid
|
||||
|
||||
|
||||
@@ -6942,7 +6947,11 @@ def sync_trade_records_from_exchange(conn, force=False):
|
||||
matched += 1
|
||||
stats["matched"] = matched
|
||||
stats["ok"] = True
|
||||
_LAST_EXCHANGE_PNL_SYNC_AT = now
|
||||
# 仍有未匹配且历史非空:缩短节流,避免平仓后历史稍晚入库时卡在「估」
|
||||
if matched < stats["pending"] and hist:
|
||||
_LAST_EXCHANGE_PNL_SYNC_AT = now - 15.0
|
||||
else:
|
||||
_LAST_EXCHANGE_PNL_SYNC_AT = now
|
||||
try:
|
||||
conn.commit()
|
||||
except Exception:
|
||||
@@ -9378,6 +9387,7 @@ register_trade_records_api(
|
||||
filter_trade_records_excluding_miss=filter_trade_records_excluding_miss,
|
||||
app_tz=APP_TZ,
|
||||
format_price_fn=format_price_for_symbol,
|
||||
sync_exchange_pnl_fn=lambda conn: sync_trade_records_from_exchange(conn, force=False),
|
||||
)
|
||||
|
||||
def _dashboard_enrich_orders(items):
|
||||
|
||||
Reference in New Issue
Block a user