This commit is contained in:
David Chen
2026-03-14 20:14:33 +08:00
committed by GitHub
parent ab91804be1
commit 05c17f6b5d
16 changed files with 3177 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
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'