from lib.exchange.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
