|
1 | 1 | from datetime import timedelta |
2 | | -from sqlite3 import OperationalError |
3 | | -from unittest.mock import MagicMock |
| 2 | +from unittest.mock import MagicMock, PropertyMock |
4 | 3 |
|
5 | 4 | import pytest |
6 | 5 |
|
@@ -159,3 +158,38 @@ def test_dry_run_liquidation_price_cross_bitget(default_conf, mocker): |
159 | 158 | 100, |
160 | 159 | [], |
161 | 160 | ) |
| 161 | + |
| 162 | + |
| 163 | +def test__lev_prep_bitget(default_conf, mocker): |
| 164 | + api_mock = MagicMock() |
| 165 | + api_mock.set_margin_mode = MagicMock() |
| 166 | + api_mock.set_leverage = MagicMock() |
| 167 | + type(api_mock).has = PropertyMock(return_value={"setMarginMode": True, "setLeverage": True}) |
| 168 | + exchange = get_patched_exchange(mocker, default_conf, api_mock, exchange="bitget") |
| 169 | + exchange._lev_prep("BTC/USDC:USDC", 3.2, "buy") |
| 170 | + |
| 171 | + assert api_mock.set_margin_mode.call_count == 0 |
| 172 | + assert api_mock.set_leverage.call_count == 0 |
| 173 | + |
| 174 | + # test in futures mode |
| 175 | + api_mock.set_margin_mode.reset_mock() |
| 176 | + api_mock.set_leverage.reset_mock() |
| 177 | + default_conf["dry_run"] = False |
| 178 | + |
| 179 | + default_conf["trading_mode"] = "futures" |
| 180 | + default_conf["margin_mode"] = "isolated" |
| 181 | + |
| 182 | + exchange = get_patched_exchange(mocker, default_conf, api_mock, exchange="bitget") |
| 183 | + exchange._lev_prep("BTC/USDC:USDC", 3.2, "buy") |
| 184 | + |
| 185 | + assert api_mock.set_margin_mode.call_count == 0 |
| 186 | + assert api_mock.set_leverage.call_count == 1 |
| 187 | + api_mock.set_leverage.assert_called_with(symbol="BTC/USDC:USDC", leverage=3.2) |
| 188 | + |
| 189 | + api_mock.reset_mock() |
| 190 | + |
| 191 | + exchange._lev_prep("BTC/USDC:USDC", 19.99, "sell") |
| 192 | + |
| 193 | + assert api_mock.set_margin_mode.call_count == 0 |
| 194 | + assert api_mock.set_leverage.call_count == 1 |
| 195 | + api_mock.set_leverage.assert_called_with(symbol="BTC/USDC:USDC", leverage=19.99) |
0 commit comments