from functools import partial from typing import Dict from cvtt_client.mkt_data import (CvttPricerWebSockClient, CvttPricesSubscription, MessageTypeT, SubscriptionIdT) from cvttpy_base.tools.app import App from cvttpy_base.tools.base import NamedObject from pt_strategy.live_strategy import PtLiveStrategy class PairTradingRunner(NamedObject): def __init__(self) -> None: super().__init__() App.instance().add_call(App.Stage.Config, self._on_config()) App.instance().add_call(App.Stage.Run, self.run()) async def _on_config(self) -> None: pass async def run(self) -> None: pass # async def main() -> None: # live_strategy = PtLiveStrategy( # config={}, # instruments=[ # {"exchange_config_name": "COINBASE_AT", "instrument_id": "PAIR-BTC-USD"}, # {"exchange_config_name": "COINBASE_AT", "instrument_id": "PAIR-ETH-USD"}, # ] # ) # async def on_message(message_type: MessageTypeT, subscr_id: SubscriptionIdT, message: Dict, instrument_id: str) -> None: # print(f"{message_type=} {subscr_id=} {instrument_id}") # if message_type == "md_aggregate": # aggr = message.get("md_aggregate", []) # print(f"[{aggr['tstamp'][:19]}] *** RLTM *** {message}") # elif message_type == "historical_md_aggregate": # for aggr in message.get("historical_data", []): # print(f"[{aggr['tstamp'][:19]}] *** HIST *** {aggr}") # else: # print(f"Unknown message type: {message_type}") # pricer_client = CvttPricerWebSockClient( # "ws://localhost:12346/ws" # ) # await pricer_client.subscribe(CvttPricesSubscription( # exchange_config_name="COINBASE_AT", # instrument_id="PAIR-BTC-USD", # interval_sec=60, # history_depth_sec=60*60*24, # callback=partial(on_message, instrument_id="PAIR-BTC-USD") # )) # await pricer_client.subscribe(CvttPricesSubscription( # exchange_config_name="COINBASE_AT", # instrument_id="PAIR-ETH-USD", # interval_sec=60, # history_depth_sec=60*60*24, # callback=partial(on_message, instrument_id="PAIR-ETH-USD") # )) # await pricer_client.run() if __name__ == "__main__": App() App.instance().run()