fix: Gate hub close sync and trade record open stop-loss snapshot

Sync order monitors from Gate position history after hub flat close. Store and display initial_stop_loss in trade records instead of post-amend exchange stops.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-09 18:01:59 +08:00
parent 02d2a6c70b
commit 59a45ed027
11 changed files with 449 additions and 40 deletions
+26
View File
@@ -0,0 +1,26 @@
from gate_position_history_lib import pick_gate_position_close, unified_symbol_for_match
def test_unified_symbol_strips_settle_suffix():
assert unified_symbol_for_match("BTC/USDT:USDT") == "BTC/USDT"
def test_pick_gate_position_close_matches_symbol_side_and_time():
hist = [
{
"symbol_u": "SOL/USDT",
"side": "short",
"close_ms": 1_700_000_000_000,
"open_ms": 1_699_999_000_000,
"pnl": -1.25,
"sync_key": "SOL_USDT|1|short",
}
]
hit = pick_gate_position_close(
hist,
"SOL/USDT:USDT",
"short",
opened_at_ms=1_699_999_500_000,
)
assert hit is not None
assert hit["pnl"] == -1.25
+6
View File
@@ -1,6 +1,7 @@
from order_monitor_display_lib import (
apply_order_price_display_fields,
is_sl_breakeven_secured,
monitor_open_stop_loss,
order_monitor_tpsl_needs_sync,
resolve_live_tpsl_prices,
sl_breakeven_from_exchange_tpsl,
@@ -26,6 +27,11 @@ def test_snapshot_stop_loss_prefers_initial():
assert snapshot_stop_loss(None, 2.6) == 2.6
def test_monitor_open_stop_loss_prefers_initial_snapshot():
row = {"initial_stop_loss": 64000, "stop_loss": 63200}
assert monitor_open_stop_loss(row) == 64000
def test_snapshot_rr_ignores_current_stop_after_manual_move():
rr = snapshot_rr(_calc_rr, "long", 2.726, 2.45, 2.65, 3.3)
assert rr is not None