56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
from abc import ABC, abstractmethod
|
|
|
|
from Account_Information import AccountInformation
|
|
from Orders import GenericLimitOrder, BuyOrder, SellOrder, OrderFilledResponse
|
|
|
|
from Historical_Data_Accessor import HistoricalDataAccessor
|
|
|
|
from typing import TYPE_CHECKING
|
|
if TYPE_CHECKING:
|
|
from datetime import datetime
|
|
|
|
from Common import TickData
|
|
from Brokerage_Simulation import BrokerageSimulation
|
|
|
|
|
|
|
|
class StrategyTemplate(ABC):
|
|
def __init__(self, symbol: str):
|
|
self._symbol = symbol
|
|
|
|
self._brokerage_simulation: 'BrokerageSimulation' = None
|
|
|
|
self._status = 0
|
|
self._historical_data_accessor: HistoricalDataAccessor = HistoricalDataAccessor()
|
|
if self._historical_data_accessor.status != 0: # Something went wrong
|
|
self._status = 1
|
|
|
|
self._current_datetime: datetime = None
|
|
|
|
self._account_information: AccountInformation = None
|
|
|
|
def attach_account_information(self, account_information: 'AccountInformation') -> None:
|
|
'''Link an AccountInformation() object to the Strategy.
|
|
The Brokerage Simulation holds the true account information and makes the changes.'''
|
|
self._account_information = account_information
|
|
|
|
def attach_brokerage_simulation(self, brokerage_simulation: 'BrokerageSimulation') -> None:
|
|
self._brokerage_simulation = brokerage_simulation
|
|
|
|
def set_current_datetime(self, new_datetime: 'datetime') -> None:
|
|
self._current_datetime = new_datetime
|
|
|
|
@abstractmethod
|
|
def react_to_market(self) -> list['GenericLimitOrder']:
|
|
'''Main function that performs the analysis and creates orders based on market conditions.
|
|
Using the _current_datetime, perform whatever past data analysis needed.
|
|
Generate buy or sell orders based on the analysis as the strategy sees fit.
|
|
Must be overridden'''
|
|
|
|
# Make buy or sell orders
|
|
|
|
# Submit orders with self._brokerage_simulation.submit_order()
|
|
|
|
# Return the list of orders
|
|
|
|
pass |