test_strategy.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import pytest
  2. from okx_codex_trader.strategy import validate_signal
  3. def test_validate_signal_rejects_leverage_out_of_range():
  4. with pytest.raises(ValueError):
  5. validate_signal(
  6. {
  7. "action": "long",
  8. "confidence": 0.9,
  9. "leverage": 4,
  10. "entry_price": None,
  11. "take_profit_price": None,
  12. "stop_loss_price": None,
  13. "reason": "x",
  14. }
  15. )
  16. def test_validate_signal_rejects_unknown_action():
  17. with pytest.raises(ValueError):
  18. validate_signal(
  19. {
  20. "action": "hold",
  21. "confidence": 0.9,
  22. "leverage": 2,
  23. "entry_price": None,
  24. "take_profit_price": None,
  25. "stop_loss_price": None,
  26. "reason": "x",
  27. }
  28. )
  29. def test_validate_signal_rejects_confidence_out_of_range():
  30. with pytest.raises(ValueError):
  31. validate_signal(
  32. {
  33. "action": "long",
  34. "confidence": 1.2,
  35. "leverage": 2,
  36. "entry_price": None,
  37. "take_profit_price": None,
  38. "stop_loss_price": None,
  39. "reason": "x",
  40. }
  41. )
  42. def test_validate_signal_requires_full_shape():
  43. with pytest.raises(ValueError):
  44. validate_signal({"action": "long", "confidence": 0.9, "leverage": 2})