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 update_all():
     for tn in table_names.complete_tables:
         last_date_updated = CandleTable.get_last_date(tn)
         target_curr = CandleTable.get_target_currency(tn)
         period = CandleTable.get_period(tn)
         CandleFetcher.fetch_candles_after_date(target_curr,
                                                last_date_updated, period)
Beispiel #3
0
    def update_tables_imperative(tns):

        ##CandleFetcher.update_tables(tns) ##perform normal update of any legit candles(replacing fake ones)

        for i, tn in enumerate(tns):
            sec_now = time.time()
            last_candle_date = CandleTable.get_last_date(tn)
            target_curr = CandleTable.get_target_currency(tn)
            period = int(CandleTable.get_period(tn))
            curr_pair = "USDT_" + target_curr

            last_candle_date += period
            while (last_candle_date < sec_now):
                ##(top_bid, bottom_ask) = OrderMaker.get_spread(curr_pair)
                ##if curr_avail[target_curr]: ##means it is true, means it is available to be sold
                ##close = bottom_ask
                ##else:
                ##close = top_bid
                close = OrderMaker.get_last_trade_rate(curr_pair,
                                                       last_candle_date)
                c = Candle(tn, last_candle_date, 0, 0, 0, close, 0, 0, 0)
                c.save()
                last_candle_date += period
            dbm = DBManager.get_instance()
            dbm.save_and_close()
Beispiel #4
0
 def update_tables(tns):
     for tn in tns:
         last_date_updated = CandleTable.get_last_date(tn)
         target_curr = CandleTable.get_target_currency(tn)
         period = CandleTable.get_period(tn)
         CandleFetcher.fetch_candles_after_date(
             target_curr, (last_date_updated - 10 * int(period)), period)
Beispiel #5
0
    def preprocess(self):

        ##initilize all bits to 0, get symbols
        for tn in self.table_name_array:
            self.bits_array.append(0)
            self.bits_end_array.append(0)
            self.symbol_array.append(CandleTable.get_target_currency(tn))
            self.total_bits_bought_array.append(0)

        ##get candle arrays
        self.candles_array = []
        for tn in self.table_name_array:
            candles = CandleTable.get_candle_array(tn)
            self.candles_array.append(candles)

        for s in self.strategy_array:
            if hasattr(s, "adapter") and self.balance_limit is not None:
                s.adapter.set_limit(self.balance_limit)

        ##create trade tables
        if self.to_log:
            for i, tn in enumerate(self.table_name_array):
                trade_table_name = TradeTable.calc_name(
                    tn, self.strategy_array[i].get_name())
                trade_table = TradeTable(trade_table_name)
                if DBManager.exists_table(trade_table_name):
                    DBManager.drop_table(trade_table_name)
                trade_table.save()
                self.trade_table_name_array.append(trade_table_name)

                self.strategy_array[i].trade_table_name = trade_table_name
                self.trades_array.append([])
    def __init__(self,
                 table_name,
                 is_simul=True,
                 to_print=False,
                 calc_stats=False):
        self.table_name = table_name
        self.candles = CandleTable.get_candle_array(table_name)
        self.to_print = to_print
        self.calc_stats = calc_stats
        self.interval_array = None
        self.is_simul = is_simul
        self.area_array = []

        self.adapter = ShortStratAdapter(is_simul)

        if is_simul:
            self.amount = TradeSimulator.get_currency_amount(table_name)
        else:
            self.amount = 1

        init_candles = self.candles[:self.DATA_PAST]
        self.ranges = self.create_ranges(init_candles)
        self.interval_array = self.create_interval_array(self.ranges)

        ##self.interval_array.pprint()
        ##print self.interval_array.local_maxes
        ##print self.interval_array.get_limits(773)
        ##self.update_levels(self.ranges, self.DATA_PAST)
        sym = CandleTable.get_target_currency(table_name)

        if is_simul:
            self.calc_vol_tables()
Beispiel #7
0
 def calc_name(candle_table_name, strategy_name):
     return "TRADE_" + strategy_name + "_" + CandleTable.get_target_currency(
         candle_table_name) + "_" + CandleTable.get_period(
             candle_table_name)