"""期权历史/复盘币本位金额."""

from __future__ import annotations

import unittest

from lib.exchange.okx_options_lib import format_option_history_row
from lib.options.options_review_lib import convert_option_amounts_to_usdt


class TestOptionsHistoryCoin(unittest.TestCase):
    def test_format_option_history_row_coin_premium_fmt(self) -> None:
        raw = {
            "instId": "ETH-USD-260822-2250-C",
            "openAvgPx": "0.02",
            "closeAvgPx": "0.03",
            "closeTotalPos": "2",
            "realizedPnl": "0.002",
            "pnlRatio": "0.5",
            "type": "2",
            "uTime": "1724146497000",
            "cTime": "1724126855000",
            "posId": "123",
            "uly": "ETH-USD",
        }
        row = format_option_history_row(raw, tick_sz="0.0001", ct_mult=0.1)
        self.assertEqual(row["margin_mode"], "coin")
        self.assertEqual(row["premium_ccy"], "ETH")
        self.assertAlmostEqual(float(row["premium_paid"]), 0.004, places=6)
        self.assertNotEqual(row["premium_paid_fmt"], "0.00")
        self.assertIn("0.004", str(row["premium_paid_fmt"]))

    def test_convert_option_amounts_to_usdt(self) -> None:
        out = convert_option_amounts_to_usdt(
            {
                "inst_id": "ETH-USD-260822-2250-C",
                "premium_ccy": "ETH",
                "margin_mode": "coin",
                "premium_paid": 0.004,
                "realized_pnl": 0.002,
            },
            index_px=2000.0,
        )
        self.assertEqual(out["pnl_quote_ccy"], "USDT")
        self.assertEqual(out["premium_paid"], 8.0)
        self.assertEqual(out["realized_pnl"], 4.0)


if __name__ == "__main__":
    unittest.main()
