Ejemplo n.º 1
0
def parse_kraken_kline_json_to_influx_data(text, base, quote):

    json_arr = []

    try:
        import json
        result_dict = json.loads(text)['result']
        for key in result_dict.keys():
            if key != 'last':
                ohlc_array = result_dict[key]
                for ohlc_data in ohlc_array:

                    time = timestamp_to_milliseconds(int(ohlc_data[0]))

                    open = float(ohlc_data[1])
                    high = float(ohlc_data[2])
                    low = float(ohlc_data[3])
                    close = float(ohlc_data[4])
                    # vwap = float(ohlc_data[5])
                    # volume = float(ohlc_data[6])
                    # count = int(ohlc_data[7])

                    json_body = 'kline_tb,market=kraken,base=%s,quote=%s open=%f,high=%f,low=%f,close=%f %d' \
                                % (base, quote, open, high, low, close, time)
                    json_arr.append(json_body)
    except Exception as ex:
        logger.error('parse_kraken_kline_json_to_influx_data error, ex:' % ex)

    return json_arr
Ejemplo n.º 2
0
def parse_binance_kline_json_to_influx_data(text, base, quote):
    import json

    json_arr = []

    try:
        response_arr = json.loads(text)
        for response in response_arr:
            time = timestamp_to_milliseconds(int(response[0]))
            open = float(response[1])
            high = float(response[2])
            low = float(response[3])
            close = float(response[4])
            # volume = float(response[5])
            # close_time = int(response[6])
            # quote_asset_vol = float(response[7])
            # count = int(response[8])
            # taker_buy_base_asset_vol = float(response[9])
            # taker_buy_quote_asset_vol = float(response[10])

            json_body = 'kline_tb,market=binance,base=%s,quote=%s' \
                        ' open=%f,high=%f,low=%f,close=%f %d' \
                        % (base, quote, open, high, low, close, time)
            json_arr.append(json_body)
    except Exception as ex:
        logger.error('parse_binance_kline_json_to_influx_data error, ex:' % ex)

    return json_arr
Ejemplo n.º 3
0
def parse_okex_kline_json_to_influx_data(text, base, quote):

    json_arr = []

    try:
        import json
        data_array = json.loads(text)
        for data in data_array:
            time = timestamp_to_milliseconds(int(data[0]))
            open = float(data[1])
            high = float(data[2])
            low = float(data[3])
            close = float(data[4])
            # volume = float(data[5])

            json_body = "kline_tb,market=okex,base=%s,quote=%s open=%f,high=%f,low=%f,close=%f %d" \
                        % (base, quote, open, high, low, close, time)
            json_arr.append(json_body)
    except Exception as ex:
        logger.error('parse_okex_kline_json_to_influx_data error, ex:' % ex)
    return json_arr
Ejemplo n.º 4
0
def parse_huobi_kline_json_to_influx_data(text, base, quote):
    import json

    json_arr = []
    try:
        response_arr = json.loads(text)['data']

        for response in response_arr:
            time = timestamp_to_milliseconds(int(response.get('id')))
            open = float(response.get('open'))
            close = float(response.get('close'))
            low = float(response.get('low'))
            high = float(response.get('high'))
            # amount = response.get('amount')
            # count = response.get('count')
            # vol = response.get('vol')

            json_body = 'kline_tb,market=huobi,base=%s,quote=%s open=%f,high=%f,low=%f,close=%f %d' \
                        % (base, quote, open, high, low, close, time)
            json_arr.append(json_body)
    except Exception as ex:
        logger.error('parse_huobi_kline_json_to_influx_data error, ex:' % ex)

    return json_arr