from fxhnt.application.xsfunding_strategy import XsFundingForward


class _FakeLive:
    """snapshot(prev) -> {sym: (tf, today_funding, perp, spot, qvol)}."""

    def __init__(self, snap):
        self._snap = snap

    def snapshot(self, prev):
        return self._snap


def test_top_and_bottom_quantile_get_signed_weights():
    # 5 names spread across funding so top/bottom quantiles are distinct; all borrowable (high qvol)
    snap = {
        "AAA": (0.003, 0.003, 100.0, 100.0, 5e7),
        "BBB": (0.002, 0.002, 100.0, 100.0, 5e7),
        "CCC": (0.000, 0.000, 100.0, 100.0, 5e7),
        "DDD": (-0.002, -0.002, 100.0, 100.0, 5e7),
        "EEE": (-0.003, -0.003, 100.0, 100.0, 5e7),
    }
    fwd = XsFundingForward(_FakeLive(snap), quantile=0.2, borrowable_qvol=2e7)
    w = fwd.current_weights("2026-06-21")
    assert w["AAA"] > 0  # top funding -> long
    assert w["EEE"] < 0  # bottom funding -> short
    assert w.get("CCC", 0.0) == 0.0  # middle -> flat
