Пример #1
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)
Пример #2
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()
Пример #3
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
Пример #4
0
	def get_new_signals(self, tn_index):

		tn = self.trader_tables[tn_index]
		signal_tn = self.signal_table_names[tn_index]

		cur_date = int(time())
		last_date = SignalTable.get_last_date(signal_tn)
		period = float(CandleTable.get_period(tn))
		
		##cut the candle table to get one of a more manageable size
		cut_table_name = CandleFetcher.cut_table(tn, int(cur_date - 5*ShortTermStrategy.DATA_PAST*period))
		candles = CandleTable.get_candle_array(cut_table_name)

		##new_candle_index = self.find_new_candle_index(candles, last_date)
		
		new_signals = []

		##run a strategy on the candles and store the resulting operations returned
		strat = self.strat_array[tn_index]
		sym = SignalTable.get_sym(self.signal_table_names[tn_index])
		strat.update_state(candles)
	
		##i = new_candle_index
		##while i < len(candles):
		i = len(candles) - 1
		o = strat.decide(i, self.sym_infos[sym].total_balance, self.sym_infos["USDT"].total_balance)	
		sig = Sig(signal_tn, candles[i].date, SignalTable.get_sym(signal_tn), o.amount, candles[i].close, o.op)
		new_signals.append(sig)	
		##i += 1

		##delete created table when done
		DBManager.drop_table(cut_table_name)
		return new_signals
			
Пример #5
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)
Пример #6
0
    def run(self):

        ## first iterate over candle index
        most_candles = self.candles_array[self.most_candles_index()]
        num_most_candles = len(most_candles)
        for i in range(num_most_candles):
            ##then iterate over candle table
            for j in range(self.num_currencies):
                period = CandleTable.get_period(self.table_name_array[j])
                self.bit_sec += self.bits_array[j] * int(period)
                ##offset adjusts for different tables having different num of candles
                offset = num_most_candles - len(self.candles_array[j])
                if offset <= i:
                    operation = self.strategy_array[j].decide(
                        i - offset, self.bits_array[j], self.balance)
                    self.process_operation(j, operation,
                                           self.candles_array[j][i - offset])
                else:  ##too early to trade these candles
                    pass

        self.finalize_balance()

        if self.to_log:
            self.save_all_trades()

        if self.to_print:
            self.print_results()
Пример #7
0
 def set_defaults(self):
     if CandleTable.get_period(self.table_name) == "14400":
         self.bb_factor = 2.5
         self.stddev_adjust = False
         self.avg_period = 40
         self.num_past_buy = 0
         self.num_past_sell = 3
         self.one_op = False
         self.to_carry = True
         self.wait_better = True
     if CandleTable.get_period(self.table_name) == "7200":
         self.bb_factor = 2
         self.stddev_adjust = False
         self.avg_period = 80
         self.num_past_buy = 0
         self.num_past_sell = 6
         self.one_op = False
         self.to_carry = False
         self.wait_better = False
Пример #8
0
    def __init__(self, table_name, bits, bitsec):
        self.table_name = table_name
        self.bits = bits
        self.bitsec = bitsec

        self.candles = CandleTable.get_candle_array(table_name)
        self.period = float(CandleTable.get_period(table_name))
        self.buy_amt = self.calc_buy_amt()

        self.runs = [0]
Пример #9
0
	def grab_new_signals(self):
		period =  float(CandleTable.get_period(table_names.short_term_tables[0]))
		last_time = CandleTable.get_last_date(table_names.short_term_tables[0])
		cur_time = time.time()
		if(cur_time-last_time) > (period+1):
			print("***********************************SIGNALS*********************************************")
			self.signaler.update(self.order_updater.sym_infos)
			new_signals_array = self.signaler.new_signals_array
			self.handle_new_currency_signals(new_signals_array)
			
			sym_infos = self.order_updater.sym_infos
			for key, value in sym_infos.items():
				print("last operation was: " , value.is_owned)

		return Task.CONTINUE
Пример #10
0
    def __init__(self, predicter_table_name, mode):
        self.cur_traded_candles = None
        self.predicter_table_name = predicter_table_name
        self.predicter_candles = CandleTable.get_candle_array(
            predicter_table_name)
        self.table_period = CandleTable.get_period(predicter_table_name)

        self.candles_to_skip = 0
        ## if want to trade more often than data available, don't skip anything else skip however many table periods fit into TIME_PERIOD
        if self.table_period >= self.TIME_PERIOD:
            self.candles_to_skip = 1
        else:
            self.candles_to_skip = self.TIME_PERIOD / self.table_period

        ##an array where avg at each time can be looked up
        self.point_avgs = self.create_table(predicter_table_name, mode)
Пример #11
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)
Пример #12
0
 def __init__(self, table_name, to_spend):
     self.candles = CandleTable.get_candle_array(table_name)
     num_candles = len(self.candles)
     period = float(CandleTable.get_period(table_name))
     self.amount = to_spend / (self.candles[0].close *
                               (1 + TradeSimulator.BUY_FEE))