"""趋势补仓下单:空 params 不得变成 None(ccxt 会报 not iterable)."""
from __future__ import annotations

import unittest
from unittest.mock import MagicMock

from lib.strategy.strategy_trend_exchange import trend_market_add


class TestTrendMarketAddParams(unittest.TestCase):
    def test_empty_gate_params_not_passed_as_none(self):
        ex = MagicMock()
        ex.create_order.return_value = {"id": "1", "average": 0.34}
        app = MagicMock()
        app.exchange = ex
        app.ensure_markets_loaded = MagicMock()
        app.build_gate_order_params = MagicMock(return_value={})
        cfg = {"app_module": app}

        trend_market_add(cfg, "ONDO/USDT:USDT", "long", 23, 10)

        args = ex.create_order.call_args
        self.assertEqual(args[0][5], {})
        self.assertIsNotNone(args[0][5])

    def test_binance_oneway_empty_params_not_passed_as_none(self):
        ex = MagicMock()
        ex.create_order.return_value = {"id": "1"}
        app = MagicMock(spec=["exchange", "ensure_markets_loaded", "build_binance_order_params"])
        app.exchange = ex
        app.ensure_markets_loaded = MagicMock()
        app.build_binance_order_params = MagicMock(return_value={})
        cfg = {"app_module": app}

        trend_market_add(cfg, "BTC/USDT:USDT", "long", 1, 10)

        self.assertEqual(ex.create_order.call_args[0][5], {})


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