Beispiel #1
0
    def cut_table(orig_table_name, date_start, date_end=9999999999):
        ##print "Cutting table: ", orig_table_name, " candle data between: ", timestamp_to_date(date_start), " ---- ", timestamp_to_date(date_end)

        ##create new table
        curr_ref = CandleTable.get_ref_currency(orig_table_name)
        curr_target = CandleTable.get_target_currency(orig_table_name)
        period = CandleTable.get_period(orig_table_name)
        new_table = CandleTable(curr_ref, curr_target, date_start, date_end,
                                period)
        new_table_name = new_table.table_name

        if DBManager.exists_table(new_table_name):
            DBManager.drop_table(new_table_name)

        new_table.save()

        ##populate new table with candles from orig_table that lie between the 2 dates
        candle_array = CandleTable.get_candle_array_by_date(
            orig_table_name, date_start, date_end)
        for c in candle_array:
            new_c = Candle(new_table_name, c.date, c.high, c.low, c.open,
                           c.close, c.volume, c.quoteVolume, c.weightedAverage)
            new_c.save()
        dbm = DBManager.get_instance()
        return new_table_name
Beispiel #2
0
 def get_candle_data(curr_target, date_start, date_end, period):
     polo = Poloniex.get_instance()
     ##print "Adding ", curr_target, " candle data between: ", timestamp_to_date(date_start), " ---- ", timestamp_to_date(date_end)
     ##configuration
     curr_ref = "USDT"
     ##curr_target = "BTC"
     ##start = 1451606400 ## Jan 01 2016
     ##end = 1459468800## Apr 1 2016
     ##start = 1459468800## Apr 1 2016
     ##end = 1467331200 ## july 01 2016
     ##start = 1467331200 ## july 01 2016
     ##end =  1475280000## oct 01 2016
     ##start = 1475280000 ## aug 8 2016
     ##end = 9999999999 ## present
     ##period = 14400 ## in seconds
     ##table_name = CandleTable.calc_table_name(curr_ref, curr_target, start, end, period)
     table_name = "CANDLE_" + curr_ref + "_" + curr_target + "_" + str(
         period)
     if not DBManager.exists_table(table_name):
         ct = CandleTable(curr_ref, curr_target, date_start, date_end,
                          period, table_name)
         ct.save()
     print("Populating table: " + table_name + " ...")
     curr_pair = curr_ref + "_" + curr_target
     data = polo.api_query(
         "returnChartData", {
             'currencyPair': curr_pair,
             'start': date_start,
             'end': date_end,
             'period': period
         })
     cp = CandleParser(table_name, data)