|
|
@@ -296,12 +296,11 @@ def test_okx_error_payload_raises_value_error():
|
|
|
client.get_candles(symbol="BTC-USDT-SWAP", bar="1H", limit=20)
|
|
|
|
|
|
|
|
|
-def test_empty_okx_data_raises_stable_value_error():
|
|
|
+def test_empty_positions_data_returns_empty_list():
|
|
|
session = DummySession([DummyResponse({"code": "0", "msg": "", "data": []})])
|
|
|
client = OkxClient(config=sample_config(), session=session)
|
|
|
|
|
|
- with pytest.raises(ValueError, match="okx response payload is invalid"):
|
|
|
- client.get_positions(symbol="BTC-USDT-SWAP")
|
|
|
+ assert client.get_positions(symbol="BTC-USDT-SWAP") == []
|
|
|
|
|
|
|
|
|
def test_malformed_numeric_field_raises_stable_value_error():
|
|
|
@@ -329,7 +328,15 @@ def test_malformed_numeric_field_raises_stable_value_error():
|
|
|
client.get_positions(symbol="BTC-USDT-SWAP")
|
|
|
|
|
|
|
|
|
-def test_place_demo_order_returns_none_when_order_id_is_missing():
|
|
|
+def test_non_list_okx_data_raises_stable_value_error():
|
|
|
+ session = DummySession([DummyResponse({"code": "0", "msg": "", "data": {}})])
|
|
|
+ client = OkxClient(config=sample_config(), session=session)
|
|
|
+
|
|
|
+ with pytest.raises(ValueError, match="okx response payload is invalid"):
|
|
|
+ client.get_positions(symbol="BTC-USDT-SWAP")
|
|
|
+
|
|
|
+
|
|
|
+def test_place_demo_order_raises_when_order_id_is_missing():
|
|
|
session = DummySession(
|
|
|
[
|
|
|
instrument_response(),
|
|
|
@@ -341,9 +348,26 @@ def test_place_demo_order_returns_none_when_order_id_is_missing():
|
|
|
)
|
|
|
client = OkxClient(config=sample_config(), session=session)
|
|
|
|
|
|
- result = client.place_demo_order(symbol="BTC-USDT-SWAP", signal=market_long_signal(), margin_usdt=100)
|
|
|
+ with pytest.raises(ValueError, match="okx response payload is invalid"):
|
|
|
+ client.place_demo_order(symbol="BTC-USDT-SWAP", signal=market_long_signal(), margin_usdt=100)
|
|
|
+
|
|
|
|
|
|
- assert result.order_id is None
|
|
|
+def test_place_demo_order_rejects_invalid_leverage_before_okx():
|
|
|
+ session = DummySession([])
|
|
|
+ signal = TradeSignal(
|
|
|
+ action="long",
|
|
|
+ confidence=0.9,
|
|
|
+ leverage=4,
|
|
|
+ entry_price=None,
|
|
|
+ take_profit_price=None,
|
|
|
+ stop_loss_price=None,
|
|
|
+ reason="x",
|
|
|
+ )
|
|
|
+ client = OkxClient(config=sample_config(), session=session)
|
|
|
+
|
|
|
+ with pytest.raises(ValueError, match="leverage is invalid"):
|
|
|
+ client.place_demo_order(symbol="BTC-USDT-SWAP", signal=signal, margin_usdt=100)
|
|
|
+ assert session.request_paths == []
|
|
|
|
|
|
|
|
|
def test_get_positions_returns_normalized_positions():
|