def _aggregate_bars(self, apibars, timeframe_minutes, start_offset_minutes) -> List[Bar]:
     subbars = []
     for b in apibars:
         if b['open'] is None:
             continue
         subbars.append(self.barDictToBar(b))
     return process_low_tf_bars(subbars, timeframe_minutes, start_offset_minutes)
Beispiel #2
0
 def _aggregate_bars(self, bars, timeframe_minutes,
                     start_offset_minutes) -> List[Bar]:
     subbars = []
     for b in bars:
         subbars.append(self.convertBar(b))
     return process_low_tf_bars(subbars, timeframe_minutes,
                                start_offset_minutes)
Beispiel #3
0
 def recent_bars(self, timeframe_minutes,
                 start_offset_minutes) -> List[Bar]:
     subbars = []
     for b in self.candles:
         subbars.append(self.convertBarevent(b))
     return process_low_tf_bars(subbars, timeframe_minutes,
                                start_offset_minutes)
Beispiel #4
0
def load_bars(days_in_history,
              wanted_tf,
              start_offset_minutes=0,
              exchange='bybit',
              symbol='BTCUSD'):
    #empty symbol is legacy and means btcusd
    end = known_history_files[exchange + "_" + symbol]
    start = max(0, end - int(days_in_history * 1440 / 50000))
    m1_bars_temp = []
    logger.info("loading " + str(end - start + 1) + " history files from " +
                exchange)
    for i in range(start, end + 1):
        with open(history_file_name(i, exchange, symbol)) as f:
            m1_bars_temp += json.load(f)
    logger.info("done loading files, now preparing them")
    start = max(0, len(m1_bars_temp) - (days_in_history * 1440))
    m1_bars = m1_bars_temp[start:]

    subbars: List[Bar] = []
    for b in m1_bars:
        if exchange == 'bybit':
            if b['open'] is None:
                continue
            subbars.append(ByBitInterface.barDictToBar(b))
        elif exchange == 'bitmex':
            if b['open'] is None:
                continue
            subbars.append(BitmexInterface.barDictToBar(b, wanted_tf))
        elif exchange in ['binance_future', 'binanceSpot']:
            subbars.append(BinanceFuturesInterface.barArrayToBar(b))
        elif exchange == 'phemex':
            subbars.append(PhemexInterface.barArrayToBar(b, 10000))
    subbars.reverse()
    return process_low_tf_bars(subbars, wanted_tf, start_offset_minutes)
Beispiel #5
0
def load_bars(days_in_history,
              wanted_tf,
              start_offset_minutes=0,
              exchange='bitmex'):
    knownfiles = {"bitmex": 45, "bybit": 14, "binance": 6, "binanceSpot": 28}
    end = knownfiles[exchange]
    start = max(0, end - int(days_in_history * 1440 / 50000))
    m1_bars = []
    logger.info("loading " + str(end - start) + " history files from " +
                exchange)
    for i in range(start, end + 1):
        with open('history/' + exchange + '/M1_' + str(i) + '.json') as f:
            m1_bars += json.load(f)
    logger.info("done loading files, now preparing them")

    subbars: List[Bar] = []
    for b in m1_bars:
        if exchange == 'bybit':
            if b['open'] is None:
                continue
            subbars.append(ByBitInterface.barDictToBar(b))
        elif exchange == 'bitmex':
            if b['open'] is None:
                continue
            subbars.append(BitmexInterface.barDictToBar(b, wanted_tf))
        elif exchange in ['binance', 'binanceSpot']:
            subbars.append(BinanceInterface.barArrayToBar(b))
    subbars.reverse()
    return process_low_tf_bars(subbars, wanted_tf, start_offset_minutes)
Beispiel #6
0
    def get_bars(self, timeframe_minutes, start_offset_minutes) -> List[Bar]:
        tf = CandlestickInterval.MIN1 if timeframe_minutes <= 60 else CandlestickInterval.HOUR1

        bars = self.client.get_candlestick_data(symbol=self.symbol, interval=tf, limit=1000)

        subbars = []
        for b in reversed(bars):
            subbars.append(self.convertBar(b))
        return process_low_tf_bars(subbars, timeframe_minutes, start_offset_minutes)
Beispiel #7
0
def load_bars(days_in_history, wanted_tf, start_offset_minutes=0,exchange='bitmex'):
    end = 45 if exchange == 'bitmex' else 14
    start = max(0,end - int(days_in_history * 1440 / 50000))
    m1_bars = []
    logger.info("loading " + str(end - start) + " history files from "+exchange)
    for i in range(start, end + 1):
        with open('history/'+exchange+'/M1_' + str(i) + '.json') as f:
            m1_bars += json.load(f)
    logger.info("done loading files, now preparing them")

    subbars: List[Bar] = []
    if exchange == 'bybit':
        for b in m1_bars:
            if b['open'] is None:
                continue
            subbars.append(ByBitInterface.barDictToBar(b))
    else:
        for b in m1_bars:
            if b['open'] is None:
                continue
            subbars.append(BitmexInterface.barDictToBar(b,wanted_tf))
    subbars.reverse()
    return process_low_tf_bars(subbars, wanted_tf, start_offset_minutes)
Beispiel #8
0
 def _aggregate_bars(self, bars: List[Bar], timeframe_minutes,
                     start_offset_minutes) -> List[Bar]:
     """ bars need to be ordered newest bar = index 0 """
     return process_low_tf_bars(bars, timeframe_minutes,
                                start_offset_minutes)
Beispiel #9
0
 def recent_bars(self, timeframe_minutes,
                 start_offset_minutes) -> List[Bar]:
     return process_low_tf_bars(self.h1Bars,
                                timeframe_minutes,
                                start_offset_minutes=start_offset_minutes)