39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
|
|
from decimal import Decimal
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from grid_trading.domain.grid_alerts import evaluate_grid_alert
|
||
|
|
from grid_trading.domain.models import GridAlertState, TradeSide
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize(
|
||
|
|
("side", "current", "target", "expected"),
|
||
|
|
[
|
||
|
|
(TradeSide.BUY, "9.99", "10.00", GridAlertState.REACHED),
|
||
|
|
(TradeSide.BUY, "10.04", "10.00", GridAlertState.NEAR),
|
||
|
|
(TradeSide.BUY, "10.10", "10.00", GridAlertState.WAITING),
|
||
|
|
(TradeSide.SELL, "10.01", "10.00", GridAlertState.REACHED),
|
||
|
|
(TradeSide.SELL, "9.96", "10.00", GridAlertState.NEAR),
|
||
|
|
(TradeSide.SELL, "9.90", "10.00", GridAlertState.WAITING),
|
||
|
|
],
|
||
|
|
)
|
||
|
|
def test_evaluate_grid_alert_handles_buy_and_sell_directions(side, current, target, expected):
|
||
|
|
result = evaluate_grid_alert(
|
||
|
|
side=side,
|
||
|
|
current_price=Decimal(current),
|
||
|
|
target_price=Decimal(target),
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result.state is expected
|
||
|
|
|
||
|
|
|
||
|
|
def test_evaluate_grid_alert_marks_missing_quote_unavailable():
|
||
|
|
result = evaluate_grid_alert(
|
||
|
|
side=TradeSide.BUY,
|
||
|
|
current_price=None,
|
||
|
|
target_price=Decimal("10"),
|
||
|
|
)
|
||
|
|
|
||
|
|
assert result.state is GridAlertState.UNAVAILABLE
|
||
|
|
assert result.distance_pct is None
|