Resolve Js output object Object
Question
When using update_from_tick I ran into this js error with [object Object]. I tried to update the last bar when a the new tick is within the bar timeframe.
js: Uncaught Error: Cannot update oldest data, last time=[object Object], new time=[object Object]
Is it possible to resolve the object data so I can see what I did wrong?
Code example
from datetime import datetime as dt, timedelta
def _on_tick(self, tickEvent):
backtester = Functions.backtester()
if not backtester:
return
lastCandle = self.chart.candle_data.iloc[-1] if not self.chart.candle_data.empty else None
# lastCandle = self.chart._last_bar
tickData = backtester.getTickData(tickEvent)
if lastCandle is None:
self.chart.set(tickData)
else:
for i, series in tickData.iterrows():
lastTime = dt.utcfromtimestamp(lastCandle['time']).replace(second=0, microsecond=0)
seriesTime = dt.strptime(str(series.name), '%Y-%m-%d %H:%M:%S')
nextCandleTime = lastTime + timedelta(seconds=self.chartTimeFrame.interval)
if seriesTime < nextCandleTime:
# update last bar with tick data
series['time'] = lastCandle['time']
series['price'] = series['close']
self.chart.update_from_tick(series, cumulative_volume=True)
else:
# create a new bar
self.chart.update(series)
The error your experiencing typically occurs when trying to set/update with data that occurs chronologically before the data you have already set.
Louis
I already tried to set the time to the last candle time before using update_from_tick
series['time'] = lastCandle['time']
series['price'] = series['close']
self.chart.update_from_tick(series, cumulative_volume=True)
I am not sure what went wrong.
I already tried to set the time to the last candle time before using
update_from_tickseries['time'] = lastCandle['time'] series['price'] = series['close'] self.chart.update_from_tick(series, cumulative_volume=True)I am not sure what went wrong.
Have you tried times that occur after the last bar?
After doing some tests its likely your times are in the wrong format; in the libraries current version they should either be datetime objects or nanosecond timestamps; this will change in the next update to millisecond timestamps, and i'll add a check to see if the tick time is less than the last bar time.
Louis
Nice, thanks for your effort. Hope we can get the update soon ;)
Fixed in the latest version.
Louis