dev progress
This commit is contained in:
+19
-33
@@ -1,23 +1,21 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from functools import partial
|
||||
from typing import Callable, Coroutine, Dict, List
|
||||
from typing import Callable, Coroutine, List
|
||||
|
||||
from cvttpy_tools.settings.cvtt_types import JsonDictT
|
||||
from cvttpy_tools.app import App
|
||||
from cvttpy_tools.config import Config
|
||||
from cvttpy_tools.base import NamedObject
|
||||
from cvttpy_tools.config import CvttAppConfig
|
||||
from cvttpy_tools.logger import Log
|
||||
from cvttpy_tools.settings.cvtt_types import BookIdT
|
||||
# ---
|
||||
from cvttpy_trading.trading.instrument import ExchangeInstrument
|
||||
from cvttpy_trading.trading.active_instruments import Instruments
|
||||
from cvttpy_trading.trading.mkt_data.md_summary import MdTradesAggregate
|
||||
from cvttpy_trading.trading.exchange_config import ExchangeAccounts
|
||||
# ---
|
||||
from pairs_trading.lib.pt_strategy.live.live_strategy import PtLiveStrategy
|
||||
from pairs_trading.lib.live.mkt_data_client import CvttRestMktDataClient, MdSummary
|
||||
from pairs_trading.lib.pt_strategy.live.ti_sender import TradingInstructionsSender
|
||||
from pairs_trading.lib.live.mkt_data_client import CvttRestMktDataClient
|
||||
from pairs_trading.lib.live.ti_sender import TradingInstructionsSender
|
||||
|
||||
# import sys
|
||||
# print("PYTHONPATH directories:")
|
||||
@@ -25,17 +23,7 @@ from pairs_trading.lib.pt_strategy.live.ti_sender import TradingInstructionsSend
|
||||
# print(path)
|
||||
|
||||
'''
|
||||
Config
|
||||
=======
|
||||
{
|
||||
"cvtt_base_url": "http://cvtt-tester-01.cvtt.vpn:23456",
|
||||
"ti_config": {
|
||||
TODO
|
||||
},
|
||||
"strategy_config": {
|
||||
TODO
|
||||
}
|
||||
}
|
||||
config http://cloud16.cvtt.vpn/apps/pairs_trading
|
||||
'''
|
||||
|
||||
HistMdCbT = Callable[[List[MdTradesAggregate]], Coroutine]
|
||||
@@ -44,6 +32,7 @@ UpdateMdCbT = Callable[[MdTradesAggregate], Coroutine]
|
||||
class PairsTrader(NamedObject):
|
||||
config_: CvttAppConfig
|
||||
instruments_: List[ExchangeInstrument]
|
||||
book_id_: BookIdT
|
||||
|
||||
live_strategy_: PtLiveStrategy
|
||||
pricer_client_: CvttRestMktDataClient
|
||||
@@ -62,11 +51,18 @@ class PairsTrader(NamedObject):
|
||||
),
|
||||
)
|
||||
|
||||
App.instance().add_cmdline_arg(
|
||||
"--book_id",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Book ID"
|
||||
)
|
||||
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:
|
||||
self.config_ = CvttAppConfig.instance()
|
||||
self.book_id_ = App.instance().get_argument(name="book_id")
|
||||
|
||||
# ------- PARSE INSTRUMENTS -------
|
||||
instr_str = App.instance().get_argument("pair", "")
|
||||
@@ -90,13 +86,6 @@ class PairsTrader(NamedObject):
|
||||
|
||||
Log.info(f"{self.fname()} Instruments: {self.instruments_[0].details_short()} <==> {self.instruments_[1].details_short()}")
|
||||
|
||||
|
||||
# ------- CREATE CVTT CLIENT -------
|
||||
ti_config = self.config_.get_subconfig("ti_config", Config(json_src={}))
|
||||
self.ti_sender_ = TradingInstructionsSender(config=ti_config)
|
||||
Log.info(f"{self.fname()} TI client created: {self.ti_sender_}")
|
||||
|
||||
|
||||
# ------- CREATE STRATEGY -------
|
||||
strategy_config = self.config_.get_subconfig("strategy_config", Config({}))
|
||||
self.live_strategy_ = PtLiveStrategy(
|
||||
@@ -108,13 +97,11 @@ class PairsTrader(NamedObject):
|
||||
|
||||
# # ------- CREATE PRICER CLIENT -------
|
||||
self.pricer_client_ = CvttRestMktDataClient(config=self.config_)
|
||||
Log.info(f"{self.fname()} MD client created: {self.pricer_client_}")
|
||||
|
||||
# ------- CREATE TRADER CLIENT -------
|
||||
# URGENT CREATE TRADER CLIENT
|
||||
# (send TradingInstructions)
|
||||
# ti_config = self.config_.get_subconfig("ti_config", {})
|
||||
# self.ti_sender_ = TradingInstructionsSender(config=ti_config)
|
||||
# Log.info(f"{self.fname()} TI client created: {self.ti_sender_}")
|
||||
self.ti_sender_ = TradingInstructionsSender(config=self.config_, pairs_trader=self)
|
||||
Log.info(f"{self.fname()} TI client created: {self.ti_sender_}")
|
||||
|
||||
|
||||
# # ------- CREATE REST SERVER -------
|
||||
@@ -133,10 +120,9 @@ class PairsTrader(NamedObject):
|
||||
callback=self._on_md_summary
|
||||
)
|
||||
|
||||
async def _on_md_summary(self, history: List[MdSummary]) -> None:
|
||||
# depth = len(history)
|
||||
# if depth < 2:
|
||||
pass # URGENT
|
||||
async def _on_md_summary(self, history: List[MdTradesAggregate]) -> None:
|
||||
# Snapshot or update?
|
||||
await self.live_strategy_.on_mkt_data_hist_snapshot(hist_aggr=history)
|
||||
|
||||
async def run(self) -> None:
|
||||
Log.info(f"{self.fname()} ...")
|
||||
|
||||
Reference in New Issue
Block a user