diff --git a/testy/tradebarresolution.py b/testy/tradebarresolution.py new file mode 100644 index 0000000..cefc5d7 --- /dev/null +++ b/testy/tradebarresolution.py @@ -0,0 +1,19 @@ +from datetime import datetime, timedelta + +def find_bar_start_time(trade_time, resolution_seconds): + # Calculate the number of seconds to subtract to align with resolution + remainder = trade_time.second % resolution_seconds + seconds_to_subtract = remainder if remainder < resolution_seconds / 2 else resolution_seconds - remainder + + # Subtract the calculated seconds and microseconds from the trade_time + bar_start_time = trade_time - timedelta(seconds=seconds_to_subtract, microseconds=trade_time.microsecond) + + return bar_start_time + +# Example usage: +trade_time = datetime(2023, 9, 13, 10, 30, 30) # Replace with the actual trade time +resolution_seconds = 54 # Replace with your desired resolution in seconds + +bar_start_time = find_bar_start_time(trade_time, resolution_seconds) +print("Trade Time:", trade_time) +print("Bar Start Time:", bar_start_time) \ No newline at end of file diff --git a/v2realbot/ENTRY_ClassicSL_v01.py b/v2realbot/ENTRY_ClassicSL_v01.py index ec92942..cfaa40d 100644 --- a/v2realbot/ENTRY_ClassicSL_v01.py +++ b/v2realbot/ENTRY_ClassicSL_v01.py @@ -375,6 +375,28 @@ def next(data, state: StrategyState): return 0, val #random.randint(10, 20) + #TODO error handling obecne v indicatorech + # def average(params): + # funcName = "average" + # lookback = int(safe_get(params, "lookback",1)) + # source = safe_get(params, "source", None) + # if source is None: + # state.ilog(lvl=1,e=f"INSIDE {funcName} source required 0", **params) + # return 0,0 + + # if source in ["open","high","low","close","vwap","hlcc4"]: + # source_series = state.bars[source] + # else: + # source_series = state.indicators[source] + + # state.ilog(lvl=0,e=f"INSIDE {funcName}", source_series=source_series, **params) + + # delka_pole = len(source_series) + # if delka_pole < lookback: + # lookback = delka_pole + + # return 0, Average(source_series[-lookback:]) + #abs/rel divergence of two indicators def divergence(params): funcName = "indicatorDivergence" @@ -418,6 +440,8 @@ def next(data, state: StrategyState): lookback_priceline = safe_get(params, "lookback_priceline", None) if lookback_priceline is None: lookback_series = source_series + elif lookback_priceline in ["open","high","low","close","vwap","hlcc4"]: + lookback_series = state.bars[lookback_priceline] else: lookback_series = state.indicators[lookback_priceline] @@ -842,7 +866,7 @@ def next(data, state: StrategyState): state.vars.last_50_deltas.append(last_update_delta) avg_delta = Average(state.vars.last_50_deltas) - state.ilog(lvl=1,e=f"-----{data['index']}-{conf_bar}--delta:{last_update_delta}---AVGdelta:{avg_delta}") + state.ilog(lvl=1,e=f"-----{data['index']}-{conf_bar}--delta:{last_update_delta}---AVGdelta:{avg_delta}", data=data) conf_bar = data['confirmed'] process_delta() diff --git a/v2realbot/__pycache__/config.cpython-310.pyc b/v2realbot/__pycache__/config.cpython-310.pyc index 56c196a..f7b5293 100644 Binary files a/v2realbot/__pycache__/config.cpython-310.pyc and b/v2realbot/__pycache__/config.cpython-310.pyc differ diff --git a/v2realbot/loader/__pycache__/aggregator.cpython-310.pyc b/v2realbot/loader/__pycache__/aggregator.cpython-310.pyc index 74bdcc9..793730f 100644 Binary files a/v2realbot/loader/__pycache__/aggregator.cpython-310.pyc and b/v2realbot/loader/__pycache__/aggregator.cpython-310.pyc differ diff --git a/v2realbot/loader/__pycache__/trade_offline_streamer.cpython-310.pyc b/v2realbot/loader/__pycache__/trade_offline_streamer.cpython-310.pyc index 2373eba..13eafa6 100644 Binary files a/v2realbot/loader/__pycache__/trade_offline_streamer.cpython-310.pyc and b/v2realbot/loader/__pycache__/trade_offline_streamer.cpython-310.pyc differ diff --git a/v2realbot/loader/aggregator.py b/v2realbot/loader/aggregator.py index ba52dc8..19e91aa 100644 --- a/v2realbot/loader/aggregator.py +++ b/v2realbot/loader/aggregator.py @@ -271,8 +271,10 @@ class TradeAggregator: self.newBar['open'] = data['p'] + #UPRAVENO - pouze pro prvni bar a ROUND, jinak bereme cas baru podle noveho tradu + #TODO: do budoucna vymyslet, kdyz bude mene tradu, tak to radit vzdy do spravneho intervalu #zarovname time prvniho baru podle timeframu kam patří (např. 5, 10, 15 ...) (ROUND) - if self.align: + if self.align == StartBarAlign.ROUND and self.bar_start == 0: t = datetime.fromtimestamp(data['t']) t = t - timedelta(seconds=t.second % self.timeframe,microseconds=t.microsecond) self.bar_start = datetime.timestamp(t) @@ -282,9 +284,7 @@ class TradeAggregator: t = datetime.fromtimestamp(int(data['t'])) #timestamp self.bar_start = int(data['t']) - - self.newBar['time'] = t self.newBar['resolution'] = self.timeframe diff --git a/v2realbot/loader/trade_offline_streamer.py b/v2realbot/loader/trade_offline_streamer.py index 149411e..9bf8508 100644 --- a/v2realbot/loader/trade_offline_streamer.py +++ b/v2realbot/loader/trade_offline_streamer.py @@ -196,7 +196,7 @@ class Trade_Offline_Streamer(Thread): #homogenizace timestampu s online streamem t['t'] = Timestamp.from_unix(to_datetime(t['t']).timestamp()) - print("PROGRESS ",cnt,"/",celkem) + #print("PROGRESS ",cnt,"/",celkem) #print(t) #na rozdil od wwebsocketu zde nemame v zaznamu symbol ['S'] #vsem streamum na tomto symbolu posilame data - tbd mozna udelat i per stream vlakno diff --git a/v2realbot/static/js/archivechart.js b/v2realbot/static/js/archivechart.js index f9ec99e..a86566e 100644 --- a/v2realbot/static/js/archivechart.js +++ b/v2realbot/static/js/archivechart.js @@ -637,9 +637,11 @@ function chart_archived_run(archRecord, data, oneMinuteBars) { //displays (redraws) buy markers function display_buy_markers() { - if (profitLine) { - chart.removeSeries(profitLine) - } + // if (profitLine) { + // console.log(profitLine) + // chart.removeSeries(profitLine) + // console.log("nd") + // } if (avgBuyLine) { chart.removeSeries(avgBuyLine) diff --git a/v2realbot/strategy/__pycache__/base.cpython-310.pyc b/v2realbot/strategy/__pycache__/base.cpython-310.pyc index a4a9c25..74636b5 100644 Binary files a/v2realbot/strategy/__pycache__/base.cpython-310.pyc and b/v2realbot/strategy/__pycache__/base.cpython-310.pyc differ diff --git a/v2realbot/strategy/base.py b/v2realbot/strategy/base.py index cf98ed8..6381b72 100644 --- a/v2realbot/strategy/base.py +++ b/v2realbot/strategy/base.py @@ -177,6 +177,13 @@ class Strategy: #bary updatujeme, pridavame jen prvni self.replace_prev_bar(self.state.bars,item) + #UPD + #tady mozna u standardnich(barovych) identifikatoru updatnout cas na "updated" - aby nebyl + #stale zarovnan s casem baru + for key in self.state.indicators: + if key == 'time': + self.state.indicators['time'][-1] = item['updated'] + #u cbar indikatoru, pridavame kazdou zmenu ceny, krome potvrzeneho baru if item['confirmed'] == 0: @@ -365,8 +372,8 @@ class Strategy: print(current_thread().name, "Paused.") continue #self.state.iter_log(event="INGEST",msg="New data ingested", item=item) - print("New data ingested") - + print("New data ingested", item) + print("bars list - previous", self.state.bars) #TODO sem pridat ochranu kulometu #pokud je updatetime aktualniho baru mensi nez LIMIT a nejde o potvrzovaci bar #tak jej vyhodit