diff options
Diffstat (limited to 'shared')
| -rw-r--r-- | shared/src/shared/models.py | 3 | ||||
| -rw-r--r-- | shared/tests/test_models.py | 29 |
2 files changed, 32 insertions, 0 deletions
diff --git a/shared/src/shared/models.py b/shared/src/shared/models.py index 0e8ca44..70820b5 100644 --- a/shared/src/shared/models.py +++ b/shared/src/shared/models.py @@ -45,6 +45,9 @@ class Signal(BaseModel): price: Decimal quantity: Decimal reason: str + conviction: float = 1.0 # 0.0 to 1.0, signal strength/confidence + stop_loss: Optional[Decimal] = None # Price to exit at loss + take_profit: Optional[Decimal] = None # Price to exit at profit created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) diff --git a/shared/tests/test_models.py b/shared/tests/test_models.py index 25ab4c9..b23d71d 100644 --- a/shared/tests/test_models.py +++ b/shared/tests/test_models.py @@ -94,6 +94,35 @@ def test_order_creation(): assert order.created_at is not None +def test_signal_conviction_default(): + """Test Signal defaults for conviction, stop_loss, take_profit.""" + from shared.models import Signal, OrderSide + + signal = Signal( + strategy="rsi", symbol="BTCUSDT", side=OrderSide.BUY, + price=Decimal("50000"), quantity=Decimal("0.01"), reason="test", + ) + assert signal.conviction == 1.0 + assert signal.stop_loss is None + assert signal.take_profit is None + + +def test_signal_with_stops(): + """Test Signal with explicit conviction, stop_loss, take_profit.""" + from shared.models import Signal, OrderSide + + signal = Signal( + strategy="rsi", symbol="BTCUSDT", side=OrderSide.BUY, + price=Decimal("50000"), quantity=Decimal("0.01"), reason="test", + conviction=0.8, + stop_loss=Decimal("48000"), + take_profit=Decimal("55000"), + ) + assert signal.conviction == 0.8 + assert signal.stop_loss == Decimal("48000") + assert signal.take_profit == Decimal("55000") + + def test_position_unrealized_pnl(): """Test Position unrealized_pnl computed property.""" from shared.models import Position |
