detecting local extremes and training on them
This commit is contained in:
59
core/trading_action.py
Normal file
59
core/trading_action.py
Normal file
@ -0,0 +1,59 @@
|
||||
"""
|
||||
Trading Action Module
|
||||
|
||||
Defines the TradingAction class used throughout the trading system.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List
|
||||
|
||||
@dataclass
|
||||
class TradingAction:
|
||||
"""Represents a trading action with full context"""
|
||||
symbol: str
|
||||
action: str # 'BUY', 'SELL', 'HOLD'
|
||||
quantity: float
|
||||
confidence: float
|
||||
price: float
|
||||
timestamp: datetime
|
||||
reasoning: Dict[str, Any]
|
||||
|
||||
def __post_init__(self):
|
||||
"""Validate the trading action after initialization"""
|
||||
if self.action not in ['BUY', 'SELL', 'HOLD']:
|
||||
raise ValueError(f"Invalid action: {self.action}. Must be 'BUY', 'SELL', or 'HOLD'")
|
||||
|
||||
if self.confidence < 0.0 or self.confidence > 1.0:
|
||||
raise ValueError(f"Invalid confidence: {self.confidence}. Must be between 0.0 and 1.0")
|
||||
|
||||
if self.quantity < 0:
|
||||
raise ValueError(f"Invalid quantity: {self.quantity}. Must be non-negative")
|
||||
|
||||
if self.price <= 0:
|
||||
raise ValueError(f"Invalid price: {self.price}. Must be positive")
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Convert trading action to dictionary"""
|
||||
return {
|
||||
'symbol': self.symbol,
|
||||
'action': self.action,
|
||||
'quantity': self.quantity,
|
||||
'confidence': self.confidence,
|
||||
'price': self.price,
|
||||
'timestamp': self.timestamp.isoformat(),
|
||||
'reasoning': self.reasoning
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict[str, Any]) -> 'TradingAction':
|
||||
"""Create trading action from dictionary"""
|
||||
return cls(
|
||||
symbol=data['symbol'],
|
||||
action=data['action'],
|
||||
quantity=data['quantity'],
|
||||
confidence=data['confidence'],
|
||||
price=data['price'],
|
||||
timestamp=datetime.fromisoformat(data['timestamp']),
|
||||
reasoning=data['reasoning']
|
||||
)
|
Reference in New Issue
Block a user