32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from abc import ABC, abstractmethod
|
|
import logging
|
|
|
|
class BasePositionLogic(ABC):
|
|
"""
|
|
Abstract base class for all strategy-specific position logic.
|
|
Defines the interface for how the PositionManager interacts with logic modules.
|
|
"""
|
|
def __init__(self, strategy_name: str, send_order_callback, log_trade_callback):
|
|
self.strategy_name = strategy_name
|
|
self.send_order = send_order_callback
|
|
self.log_trade = log_trade_callback
|
|
logging.info(f"Initialized position logic for '{strategy_name}'")
|
|
|
|
@abstractmethod
|
|
def handle_signal(self, signal_data: dict, current_strategy_positions: dict) -> dict:
|
|
"""
|
|
The core logic method. This is called by the PositionManager when a
|
|
new signal arrives for this strategy.
|
|
|
|
Args:
|
|
signal_data: The full signal dictionary from the strategy.
|
|
current_strategy_positions: A dict of this strategy's current positions,
|
|
keyed by coin (e.g., {"BTC": {"side": "long", ...}}).
|
|
|
|
Returns:
|
|
A dictionary representing the new state for the *specific coin* in the
|
|
signal (e.g., {"side": "long", "size": 0.1}).
|
|
Return None to indicate the position for this coin should be closed/removed.
|
|
"""
|
|
pass
|