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()
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
def insert(self): for c in self.data['candleStick']: try: ct = Candle(self.table_name, c['date'], c['high'], c['low'], c['open'], c['close'], c['volume'], c['quoteVolume'], c['weightedAverage']) try: ct.save() except: "Duplicate candle, cannot insert" except: print("Candle cannot be parsed") dbm = DBManager.get_instance() dbm.save_and_close()