dev progress

This commit is contained in:
Oleg Sheynin
2025-12-28 19:30:00 +00:00
parent ba2a6cd2eb
commit 2e32b26fad
11 changed files with 122 additions and 173 deletions
+17 -8
View File
@@ -11,6 +11,7 @@ from cvttpy_tools.logger import Log
from cvttpy_tools.config import Config
from cvttpy_tools.timer import Timer
from cvttpy_tools.timeutils import NanoPerSec, NanosT, current_nanoseconds, current_seconds
from cvttpy_trading.trading.mkt_data.historical_md import HistMdBar
@@ -177,24 +178,32 @@ class MdSummaryCollector(NamedObject):
return
self.history_ = self.get_history()
self.run_callbacks()
self.set_timer()
def set_timer(self):
if self.timer_:
self.timer_.cancel()
self.timer_ = Timer(
start_in_sec=self.interval_sec_,
is_periodic=True,
period_interval=self.interval_sec_,
start_in_sec=(self.next_load_time() - current_seconds()),
func=self._load_new,
)
def next_load_time(self) -> NanosT:
curr_sec = int(current_seconds())
return (curr_sec - curr_sec % self.interval_sec_) + self.interval_sec_ + 2
async def _load_new(self) -> None:
last: Optional[MdSummary] = self.get_last()
if not last:
Log.warning(f"{self.fname()}: did not get last update")
return
if not self.is_empty() and last.ts_ns_ <= self.history_[-1].ts_ns_:
elif not self.is_empty() and last.ts_ns_ <= self.history_[-1].ts_ns_:
Log.info(f"{self.fname()}: Received {last}. Already Have: {self.history_[-1]}")
return
self.history_.append(last)
self.run_callbacks()
else:
self.history_.append(last)
self.run_callbacks()
self.set_timer()
def run_callbacks(self) -> None:
[cb(self.history_) for cb in self.callbacks_]