balik zmen uff

This commit is contained in:
David Brazda
2023-11-03 20:49:24 +01:00
parent de5382d04a
commit 0db88b194c
53 changed files with 1693 additions and 514 deletions
+10
View File
@@ -369,6 +369,11 @@ class TradeAggregator2Queue(TradeAggregator):
self.queue = queue
self.symbol = symbol
#accepts loaded queue and sents it to given output
async def ingest_cached(self, cached_queue):
for element in cached_queue:
self.queue.put(element)
async def ingest_trade(self, data):
#print("ingest ve threadu:",current_thread().name)
res = await super().ingest_trade(data, self.symbol)
@@ -400,6 +405,11 @@ class TradeAggregator2List(TradeAggregator):
# if os.path.exists(self.debugfile):
# os.remove(self.debugfile)
#accepts loaded queue and sents it to given output
async def ingest_cached(self, cached_queue):
for element in cached_queue:
self.btdata.append((element['t'],element['p']))
async def ingest_trade(self, data):
#print("ted vstoupil do tradeagg2list ingestu")
res1 = await super().ingest_trade(data, self.symbol)
+63
View File
@@ -0,0 +1,63 @@
from v2realbot.loader.aggregator import TradeAggregator, TradeAggregator2List, TradeAggregator2Queue
from alpaca.trading.requests import GetCalendarRequest
from alpaca.trading.client import TradingClient
from alpaca.data.live import StockDataStream
from v2realbot.config import ACCOUNT1_PAPER_API_KEY, ACCOUNT1_PAPER_SECRET_KEY, DATA_DIR, OFFLINE_MODE
from alpaca.data.enums import DataFeed
from alpaca.data.historical import StockHistoricalDataClient
from alpaca.data.requests import StockLatestQuoteRequest, StockBarsRequest, StockTradesRequest
from threading import Thread, current_thread
from v2realbot.utils.utils import parse_alpaca_timestamp, ltp, zoneNY, print
from v2realbot.utils.tlog import tlog
from datetime import datetime, timedelta, date
from threading import Thread
import asyncio
from msgpack.ext import Timestamp
from msgpack import packb
from pandas import to_datetime
import pickle
import os
from rich import print
import queue
from alpaca.trading.models import Calendar
from v2realbot.enums.enums import RecordType, StartBarAlign
from datetime import datetime, timedelta
from v2realbot.utils.utils import parse_alpaca_timestamp, ltp, Queue,is_open_hours,zoneNY
from queue import Queue
from rich import print
from v2realbot.enums.enums import Mode
import threading
class Cacher:
def __init__(self,
rectype: RecordType = RecordType.BAR,
timeframe: int = 5,
minsize: int = 100,
update_ltp: bool = False,
align: StartBarAlign = StartBarAlign.ROUND,
mintick: int = 0,
exthours: bool = False):
#vstupuje seznam aggregatoru - obvykle 1 pro queue, 1 pro backtest engine
def get_cached_agg_data(agg_list, open, close):
file_path = DATA_DIR + "/cache/"+populate_file_name(agg_list[0], open, close)
if os.path.exists(file_path):
##denní file existuje
#loadujeme ze souboru
#pokud je start_time < trade < end_time
#odesíláme do queue
#jinak pass
with open (file_path, 'rb') as fp:
agg_data = pickle.load(fp)
print("Loading AGGREGATED DATA from CACHE", file_path)
return agg_data
def store_cache_agg_data(aggregator, open, close):
pass
#ulozi data do fajlu
def populate_file_name(aggregator, open, close):
aggregated_file = aggregator.symbol + '-' + str(aggregator.rectype) + "-" + aggregator.timeframe + "-" + aggregator.minsize + "-" + aggregator.align + aggregator.mintick + str(aggregator.exthours) + '-' + str(int(open.timestamp())) + '-' + str(int(close.timestamp())) + '.cache'
return aggregated_file
@@ -1,4 +1,5 @@
from v2realbot.loader.aggregator import TradeAggregator, TradeAggregator2List, TradeAggregator2Queue
#from v2realbot.loader.cacher import get_cached_agg_data
from alpaca.trading.requests import GetCalendarRequest
from alpaca.trading.client import TradingClient
from alpaca.data.live import StockDataStream
@@ -132,6 +133,21 @@ class Trade_Offline_Streamer(Thread):
print("time_to je pred zacatkem marketu. Vynechavame tento den.")
continue
#check if we have aggregated data in cache
#agg dat found, load it from file
#and call cacher
#trade daily file
#vstupuje pole agregatoru, open, close daneho dne
#cached_aggregated_data = get_cached_agg_data(self.to_run[symbpole[0]], day.open, day.close)
# if cached_aggregated_data is not None:
# #poslu agregovana data do ingest cache aggregatorů pro přeposlání do jednotlivých kanálů
#trade daily file
daily_file = str(symbpole[0]) + '-' + str(int(day.open.timestamp())) + '-' + str(int(day.close.timestamp())) + '.cache'
print(daily_file)
file_path = DATA_DIR + "/"+daily_file