from enum import Enum from pydantic import BaseModel, Field, field_validator class Action(str, Enum): LONG = "long" SHORT = "short" class SignalPayload(BaseModel): ticker: str action: Action entry_price: str current_price: str stop_loss_price: str take_profit_1_price: str take_profit_2_price: str take_profit_3_price: str visual_timeframe: str signal_sequence: int = Field(ge=1) signal_time: int = Field(gt=0) # unix seconds of seq==1 bar open (UTC) @field_validator("action", mode="before") @classmethod def normalize_action(cls, value: object) -> object: if isinstance(value, str): return value.strip().lower() return value @field_validator( "ticker", "entry_price", "current_price", "stop_loss_price", "take_profit_1_price", "take_profit_2_price", "take_profit_3_price", "visual_timeframe", mode="before", ) @classmethod def strip_strings(cls, value: object) -> object: if isinstance(value, str): return value.strip() return value