progress 0.0.5
This commit is contained in:
+57
-61
@@ -1,86 +1,82 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Callable, Coroutine, Dict, Any, List, Optional, Set
|
||||
from typing import Dict, Any, List, Optional, Set
|
||||
|
||||
import requests
|
||||
|
||||
from cvttpy_tools.base import NamedObject
|
||||
from cvttpy_tools.app import App
|
||||
from cvttpy_tools.logger import Log
|
||||
from cvttpy_tools.config import Config
|
||||
from cvttpy_tools.timer import Timer
|
||||
from cvttpy_tools.timeutils import NanosT, current_seconds, NanoPerSec
|
||||
from cvttpy_tools.timeutils import NanosT, current_seconds
|
||||
from cvttpy_tools.settings.cvtt_types import InstrumentIdT, IntervalSecT
|
||||
|
||||
from cvttpy_tools.web.rest_client import RESTSender
|
||||
# ---
|
||||
from cvttpy_trading.trading.mkt_data.historical_md import HistMdBar
|
||||
from cvttpy_trading.trading.instrument import ExchangeInstrument
|
||||
from cvttpy_trading.trading.accounting.exch_account import ExchangeAccountNameT
|
||||
from cvttpy_trading.trading.mkt_data.md_summary import MdTradesAggregate
|
||||
from cvttpy_trading.trading.mkt_data.md_summary import MdTradesAggregate, MdSummary, MdSummaryCallbackT
|
||||
from cvttpy_trading.trading.exchange_config import ExchangeAccounts
|
||||
|
||||
# ---
|
||||
from pairs_trading.lib.live.rest_client import RESTSender
|
||||
|
||||
|
||||
class MdSummary(HistMdBar):
|
||||
def __init__(
|
||||
self,
|
||||
ts_ns: int,
|
||||
open: float,
|
||||
high: float,
|
||||
low: float,
|
||||
close: float,
|
||||
volume: float,
|
||||
vwap: float,
|
||||
num_trades: int,
|
||||
):
|
||||
super().__init__(ts=ts_ns)
|
||||
self.open_ = open
|
||||
self.high_ = high
|
||||
self.low_ = low
|
||||
self.close_ = close
|
||||
self.volume_ = volume
|
||||
self.vwap_ = vwap
|
||||
self.num_trades_ = num_trades
|
||||
# class MdSummary(HistMdBar):
|
||||
# def __init__(
|
||||
# self,
|
||||
# ts_ns: int,
|
||||
# open: float,
|
||||
# high: float,
|
||||
# low: float,
|
||||
# close: float,
|
||||
# volume: float,
|
||||
# vwap: float,
|
||||
# num_trades: int,
|
||||
# ):
|
||||
# super().__init__(ts=ts_ns)
|
||||
# self.open_ = open
|
||||
# self.high_ = high
|
||||
# self.low_ = low
|
||||
# self.close_ = close
|
||||
# self.volume_ = volume
|
||||
# self.vwap_ = vwap
|
||||
# self.num_trades_ = num_trades
|
||||
|
||||
@classmethod
|
||||
def from_REST_response(cls, response: requests.Response) -> List[MdSummary]:
|
||||
res: List[MdSummary] = []
|
||||
jresp = response.json()
|
||||
hist_data = jresp.get("historical_data", [])
|
||||
for hd in hist_data:
|
||||
res.append(
|
||||
MdSummary(
|
||||
ts_ns=hd["time_ns"],
|
||||
open=hd["open"],
|
||||
high=hd["high"],
|
||||
low=hd["low"],
|
||||
close=hd["close"],
|
||||
volume=hd["volume"],
|
||||
vwap=hd["vwap"],
|
||||
num_trades=hd["num_trades"],
|
||||
)
|
||||
)
|
||||
return res
|
||||
# @classmethod
|
||||
# def from_REST_response(cls, response: requests.Response) -> List[MdSummary]:
|
||||
# res: List[MdSummary] = []
|
||||
# jresp = response.json()
|
||||
# hist_data = jresp.get("historical_data", [])
|
||||
# for hd in hist_data:
|
||||
# res.append(
|
||||
# MdSummary(
|
||||
# ts_ns=hd["time_ns"],
|
||||
# open=hd["open"],
|
||||
# high=hd["high"],
|
||||
# low=hd["low"],
|
||||
# close=hd["close"],
|
||||
# volume=hd["volume"],
|
||||
# vwap=hd["vwap"],
|
||||
# num_trades=hd["num_trades"],
|
||||
# )
|
||||
# )
|
||||
# return res
|
||||
|
||||
def create_md_trades_aggregate(
|
||||
self,
|
||||
exch_acct: ExchangeAccountNameT,
|
||||
exch_inst: ExchangeInstrument,
|
||||
interval_sec: IntervalSecT,
|
||||
) -> MdTradesAggregate:
|
||||
res = MdTradesAggregate(
|
||||
exch_acct=exch_acct,
|
||||
exch_inst=exch_inst,
|
||||
interval_ns=interval_sec * NanoPerSec,
|
||||
)
|
||||
res.set(mdbar=self)
|
||||
return res
|
||||
# def create_md_trades_aggregate(
|
||||
# self,
|
||||
# exch_acct: ExchangeAccountNameT,
|
||||
# exch_inst: ExchangeInstrument,
|
||||
# interval_sec: IntervalSecT,
|
||||
# ) -> MdTradesAggregate:
|
||||
# res = MdTradesAggregate(
|
||||
# exch_acct=exch_acct,
|
||||
# exch_inst=exch_inst,
|
||||
# interval_ns=interval_sec * NanoPerSec,
|
||||
# )
|
||||
# res.set(mdbar=self)
|
||||
# return res
|
||||
|
||||
|
||||
MdSummaryCallbackT = Callable[[List[MdTradesAggregate]], Coroutine]
|
||||
# MdSummaryCallbackT = Callable[[List[MdTradesAggregate]], Coroutine]
|
||||
|
||||
|
||||
class MdSummaryCollector(NamedObject):
|
||||
|
||||
Reference in New Issue
Block a user