Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)