dev progress
This commit is contained in:
+21
-15
@@ -13,6 +13,7 @@ from cvttpy_tools.logger import Log
|
||||
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
|
||||
@@ -42,7 +43,7 @@ UpdateMdCbT = Callable[[MdTradesAggregate], Coroutine]
|
||||
|
||||
class PairsTrader(NamedObject):
|
||||
config_: CvttAppConfig
|
||||
instruments_: List[JsonDictT]
|
||||
instruments_: List[ExchangeInstrument]
|
||||
|
||||
live_strategy_: PtLiveStrategy
|
||||
pricer_client_: CvttRestMktDataClient
|
||||
@@ -72,20 +73,22 @@ class PairsTrader(NamedObject):
|
||||
if not instr_str:
|
||||
raise ValueError("Pair is required")
|
||||
instr_list = instr_str.split(",")
|
||||
|
||||
assert len(instr_list) == 2, "Only two instruments are supported"
|
||||
|
||||
for instr in instr_list:
|
||||
instr_parts = instr.split(":")
|
||||
if len(instr_parts) != 2:
|
||||
raise ValueError(f"Invalid pair format: {instr}")
|
||||
instrument_id = instr_parts[0]
|
||||
exch_acct = instr_parts[1]
|
||||
exch_inst = Instruments.instance()
|
||||
self.instruments_.append({
|
||||
"exch_acct": exch_acct,
|
||||
"instrument_id": instrument_id
|
||||
})
|
||||
exch_inst = ExchangeAccounts.instance().get_exchange_instrument(exch_acct=exch_acct, instrument_id=instrument_id)
|
||||
|
||||
assert len(self.instruments_) == 2, "Only two instruments are supported"
|
||||
Log.info(f"{self.fname()} Instruments: {self.instruments_}")
|
||||
assert exch_inst is not None, f"No ExchangeInstrument for {instr}"
|
||||
exch_inst.user_data_["exch_acct"] = exch_acct
|
||||
self.instruments_.append(exch_inst)
|
||||
|
||||
Log.info(f"{self.fname()} Instruments: {self.instruments_[0].details_short()} <==> {self.instruments_[1].details_short()}")
|
||||
|
||||
|
||||
# ------- CREATE CVTT CLIENT -------
|
||||
@@ -95,7 +98,7 @@ class PairsTrader(NamedObject):
|
||||
|
||||
|
||||
# ------- CREATE STRATEGY -------
|
||||
strategy_config = self.config_.get_value("strategy_config", {})
|
||||
strategy_config = self.config_.get_subconfig("strategy_config", Config({}))
|
||||
self.live_strategy_ = PtLiveStrategy(
|
||||
config=strategy_config,
|
||||
instruments=self.instruments_,
|
||||
@@ -104,7 +107,7 @@ class PairsTrader(NamedObject):
|
||||
Log.info(f"{self.fname()} Strategy created: {self.live_strategy_}")
|
||||
|
||||
# # ------- CREATE PRICER CLIENT -------
|
||||
self.pricer_client_ = CvttRestMktDataClient(self.config_)
|
||||
self.pricer_client_ = CvttRestMktDataClient(config=self.config_)
|
||||
|
||||
# ------- CREATE TRADER CLIENT -------
|
||||
# URGENT CREATE TRADER CLIENT
|
||||
@@ -118,9 +121,10 @@ class PairsTrader(NamedObject):
|
||||
# URGENT CREATE REST SERVER for dashboard communications
|
||||
|
||||
async def subscribe_md(self) -> None:
|
||||
for inst in self.instruments_:
|
||||
exch_acct = inst.get("exch_acct", "?exch_acct?")
|
||||
instrument_id = inst.get("instrument_id", "?instrument_id?")
|
||||
for exch_inst in self.instruments_:
|
||||
exch_acct = exch_inst.user_data_.get("exch_acct", "?exch_acct?")
|
||||
instrument_id = exch_inst.instrument_id()
|
||||
|
||||
await self.pricer_client_.add_subscription(
|
||||
exch_acct=exch_acct,
|
||||
instrument_id=instrument_id,
|
||||
@@ -129,8 +133,10 @@ class PairsTrader(NamedObject):
|
||||
callback=self._on_md_summary
|
||||
)
|
||||
|
||||
def _on_md_summary(self, history: List[MdSummary]) -> None:
|
||||
pass # URGENT
|
||||
async def _on_md_summary(self, history: List[MdSummary]) -> None:
|
||||
# depth = len(history)
|
||||
# if depth < 2:
|
||||
pass # URGENT
|
||||
|
||||
async def run(self) -> None:
|
||||
Log.info(f"{self.fname()} ...")
|
||||
|
||||
Reference in New Issue
Block a user