def recalcBar(bar: Bar): if "trades" not in bar.bot_data or len(bar.bot_data['trades']) == 0: return lastTstamp = 0 firstTstamp = bar.last_tick_tstamp bar.volume = 0 bar.buyVolume = 0 bar.sellVolume = 0 bar.high = bar.low = list(bar.bot_data['trades'].values())[0][3] for data in bar.bot_data['trades'].values(): tstamp = int(data[1]) / 1000 price = data[3] volume = abs(data[2]) isBuy = data[2] > 0 if tstamp > lastTstamp: bar.close = price lastTstamp = tstamp if tstamp <= firstTstamp: bar.open = price firstTstamp = tstamp bar.low = min(bar.low, price) bar.high = max(bar.high, price) bar.volume += volume bar.last_tick_tstamp = tstamp if isBuy: bar.buyVolume += volume else: bar.sellVolume += volume
def read_data_file(self, filename): try: with open(filename, 'r') as file: data = json.load(file) for entry in data: d = VolubaData(entry['tstamp']) for exchange, bar in entry['barsByExchange'].items(): bar = dotdict(bar) b = Bar(tstamp=bar.tstamp, open=bar.open, high=bar.high, low=bar.low, close=bar.close, volume=bar.volume) b.buyVolume = bar.buyVolume b.sellVolume = bar.sellVolume d.barsByExchange[exchange] = b self.m1Data[entry['tstamp']] = d except Exception as e: self.logger.error("Error reading data " + str(e))