Files
strat-playground/trading_gateway/trading_gateway.py
David Chen 05c17f6b5d -
2026-03-14 20:14:33 +08:00

43 lines
1.1 KiB
Python

from abc import ABC, abstractmethod
from typing import Generator, override
from historical_data.historical_data import historical_data_tradingview_csv
from internal_types.types import OHLC, BidAsk, Instrument
class TradingGateway(ABC):
@abstractmethod
def next_bid_ask(self) -> Generator[BidAsk, None, None]:
pass
@abstractmethod
def next_ohlc(self) -> Generator[OHLC, None, None]:
pass
@abstractmethod
def submit_order(self) -> None:
# todo: submit_order -> async submit_order with callback
pass
class BacktestGateway(TradingGateway):
def __init__(self, csv: str, instr: Instrument, t0: str, t1: str):
self.instr = instr
self.historical_data = historical_data_tradingview_csv(csv, instr, t0, t1)
@override
def next_bid_ask(self) -> Generator[BidAsk, None, None]:
assert False, 'not available for backtesting'
@override
def next_ohlc(self) -> Generator[OHLC, None, None]:
for ohlc in self.historical_data:
yield ohlc
@override
def submit_order(self) -> None:
# todo: submit_order -> async submit_order with callback
assert False, 'todo'