def save_cex_history_add(folder_path, new_date=0): cex_files = glob.glob(folder_path+"\*.txt") new_cex_files = [x for x in cex_files if int(os.path.basename(x)[4:12])>=int(new_date)] conn = dbconn.getConnect() cur = conn.cursor() for f in new_cex_files: jsfile = open(f) data = json.loads(jsfile.read()) cur.execute("DELETE FROM stg_cex_history_tik") res = [(x['tid'],x['type'],x['date'],unix_to_date(x['date']),x['amount'],x['price']) for x in data] cur.executemany("INSERT INTO stg_cex_history_tik (tid,type,unixdate,date,amount,price) VALUES (?,?,?,?,?,?)",res) cur.execute("INSERT OR IGNORE INTO "+cex_history_tbl+" SELECT DISTINCT * FROM stg_cex_history_tik") conn.commit() dbconn.closeConnect(conn)
def save_cex_history_seq(folder_path, new_date=0): cex_files = glob.glob(folder_path+"\*.txt") new_cex_files = [x for x in cex_files if int(os.path.basename(x)[4:12])>=int(new_date)] conn = dbconn.getConnect() cur = conn.cursor() for f in new_cex_files: jsfile = open(f) data = json.loads(jsfile.read()) #Текст в файле воспринимается как текст. Его надо распарсить как JSON, чтобы получить массив res = cur.execute("SELECT MAX(tid) FROM im_cex_history_tik"); max_tid = res.fetchone()[0]; if(max_tid == None): max_tid = 0 res = [(x['tid'],x['type'],x['date'],unix_to_date(x['date']),x['amount'],x['price']) for x in data if int(x['tid']) > max_tid] cur.executemany("INSERT INTO "+cex_history_tbl+" (tid,type,unixdate,date,amount,price) VALUES (?,?,?,?,?,?)",res) conn.commit() dbconn.closeConnect(conn)
log.log_action(conn, removed, 'cancel', market) f_orderIsSet = 0 prev_tik = curr_tik continue if (r_act == 'cancelALL'): # res_api = ... # list_orders = reas_api['data'] f_orderIsSet = 0 # За время рассчетов мог сработать ордер # Проверять, если был установлен флаг check_order_time_start = startCalcPeriodTime # т.к. на прошлом промежутке ничего не произошло, то его не надо повторно проверять tcalc2 = time.time() dCalctime = tcalc2 - tcalc1 # Время работы !!! ПРОВЕРИТЬ МОЖНО ЛИ ТАК ВЫЧИТАТЬ ВРЕМЯ # if dCalctime > DELTA_T: # расчет был слишком долгий # print('Too long calc at tik=' + curr_tik + ' startCalcPeriodTime=' + startCalcPeriodTime) # continue prev_tik = curr_tik dbconn.closeConnect(conn) print('==========', time.time())
#connection.row_factory = lambda cursor, row: row[0] r = curs.execute(sql) res = r.fetchone() return res if __name__ == '__main__': import db.connection as cn print('Hello') conn = cn.getConnect() #rs = alfa_curr(conn,'USD','RUB') curs = conn.cursor() sql = "SELECT ID, D1, D2, D3,D4 FROM tst " # connection.row_factory = lambda cursor, row: row[0] r = curs.execute(sql) res = r.fetchone() print(res) print(res[2]+1) cn.closeConnect(conn)