def process_tick(self, tick): timestamp, value = tick.timestamp, tick.value self.current = self.current or [tick_boundaries(timestamp, self.period), value, value, value, value] if timestamp <= self.current[0]: self.current_ticks.append((timestamp, value)) self.current[4] = value # reset close if value > self.current[2]: # compare with high self.current[2] = value # update high elif value < self.current[3]: # compare with low self.current[3] = value # update low else: self.append(tuple(self.current)) self.current_ticks = [] # reset the current_ticks list # TODO: think about this roll-over if (datetime.utcfromtimestamp(timestamp).date() > datetime.utcfromtimestamp(self.current[0]).date()): # next UTC day, do not fill gap self.current = [tick_boundaries(timestamp, self.period), value, value, value, value] else: # same day, fill gaps if needed candle_time = self.current[0] + (self.period * 60) while timestamp > candle_time: # fill gaps close = self.current[4] self.append((candle_time, close, close, close, close)) candle_time += self.period * 60 self.current = [candle_time, value, value, value, value]
def process_tick(self, tick): timestamp, value = tick.timestamp, tick.value a = self.array ci = self.current_index c_row = a[ci] if ci is None: first_values = [tick_boundaries(timestamp, self.period), value, value, value, value] self.__init_array(first_values) if timestamp <= c_row[0]: self.current_ticks.append((timestamp, value)) c_row[4] = value # close if value > c_row[2]: c_row[2] = value # update high elif value < c_row[3]: c_row[3] = value # update low else: last_close = c_row[4] self.current_index += 1 self.current_ticks = [] while timestamp > a[self.current_index][0]: a[self.current_index][1:] = [last_close] * 4 self.current_index += 1 a[self.current_index][1:] = [value] * 4