zarovnani baru u not div60 resolutions, +ind na FE

This commit is contained in:
David Brazda
2023-09-13 18:03:53 +02:00
parent e8f5805faf
commit cd51cfbccd
10 changed files with 62 additions and 10 deletions

View File

@ -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)

View File

@ -375,6 +375,28 @@ def next(data, state: StrategyState):
return 0, val return 0, val
#random.randint(10, 20) #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 #abs/rel divergence of two indicators
def divergence(params): def divergence(params):
funcName = "indicatorDivergence" funcName = "indicatorDivergence"
@ -418,6 +440,8 @@ def next(data, state: StrategyState):
lookback_priceline = safe_get(params, "lookback_priceline", None) lookback_priceline = safe_get(params, "lookback_priceline", None)
if lookback_priceline is None: if lookback_priceline is None:
lookback_series = source_series lookback_series = source_series
elif lookback_priceline in ["open","high","low","close","vwap","hlcc4"]:
lookback_series = state.bars[lookback_priceline]
else: else:
lookback_series = state.indicators[lookback_priceline] lookback_series = state.indicators[lookback_priceline]
@ -842,7 +866,7 @@ def next(data, state: StrategyState):
state.vars.last_50_deltas.append(last_update_delta) state.vars.last_50_deltas.append(last_update_delta)
avg_delta = Average(state.vars.last_50_deltas) 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'] conf_bar = data['confirmed']
process_delta() process_delta()

View File

@ -271,8 +271,10 @@ class TradeAggregator:
self.newBar['open'] = data['p'] 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) #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 = datetime.fromtimestamp(data['t'])
t = t - timedelta(seconds=t.second % self.timeframe,microseconds=t.microsecond) t = t - timedelta(seconds=t.second % self.timeframe,microseconds=t.microsecond)
self.bar_start = datetime.timestamp(t) self.bar_start = datetime.timestamp(t)
@ -284,8 +286,6 @@ class TradeAggregator:
self.bar_start = int(data['t']) self.bar_start = int(data['t'])
self.newBar['time'] = t self.newBar['time'] = t
self.newBar['resolution'] = self.timeframe self.newBar['resolution'] = self.timeframe
self.newBar['confirmed'] = 0 self.newBar['confirmed'] = 0

View File

@ -196,7 +196,7 @@ class Trade_Offline_Streamer(Thread):
#homogenizace timestampu s online streamem #homogenizace timestampu s online streamem
t['t'] = Timestamp.from_unix(to_datetime(t['t']).timestamp()) t['t'] = Timestamp.from_unix(to_datetime(t['t']).timestamp())
print("PROGRESS ",cnt,"/",celkem) #print("PROGRESS ",cnt,"/",celkem)
#print(t) #print(t)
#na rozdil od wwebsocketu zde nemame v zaznamu symbol ['S'] #na rozdil od wwebsocketu zde nemame v zaznamu symbol ['S']
#vsem streamum na tomto symbolu posilame data - tbd mozna udelat i per stream vlakno #vsem streamum na tomto symbolu posilame data - tbd mozna udelat i per stream vlakno

View File

@ -637,9 +637,11 @@ function chart_archived_run(archRecord, data, oneMinuteBars) {
//displays (redraws) buy markers //displays (redraws) buy markers
function display_buy_markers() { function display_buy_markers() {
if (profitLine) { // if (profitLine) {
chart.removeSeries(profitLine) // console.log(profitLine)
} // chart.removeSeries(profitLine)
// console.log("nd")
// }
if (avgBuyLine) { if (avgBuyLine) {
chart.removeSeries(avgBuyLine) chart.removeSeries(avgBuyLine)

View File

@ -177,6 +177,13 @@ class Strategy:
#bary updatujeme, pridavame jen prvni #bary updatujeme, pridavame jen prvni
self.replace_prev_bar(self.state.bars,item) 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 #u cbar indikatoru, pridavame kazdou zmenu ceny, krome potvrzeneho baru
if item['confirmed'] == 0: if item['confirmed'] == 0:
@ -365,8 +372,8 @@ class Strategy:
print(current_thread().name, "Paused.") print(current_thread().name, "Paused.")
continue continue
#self.state.iter_log(event="INGEST",msg="New data ingested", item=item) #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 #TODO sem pridat ochranu kulometu
#pokud je updatetime aktualniho baru mensi nez LIMIT a nejde o potvrzovaci bar #pokud je updatetime aktualniho baru mensi nez LIMIT a nejde o potvrzovaci bar
#tak jej vyhodit #tak jej vyhodit