def nct_delete(del_list): conn = default_db() cur = conn.cursor() for i in del_list: order = 'delete from ' + PARAMETER_TABLE + ' where id=%d' % i cur.execute(order) conn.commit() cur.close() conn.close()
def settings_search(): today_date = today() conn = default_db() cur = conn.cursor() order = 'select id, middle_on, strict_flag, static_closing, stocks, date from ' + SETTINGS_TABLE cur.execute(order) data = cur.fetchall() print data cur.close() conn.close()
def get_sell_signal_info(): conn = default_db() cur = conn.cursor() order = 'select id, stock_id, buy_share, low_sell, ref_sell_date from ' + SIGNAL_TABLE + \ ' where stock_status=1' cur.execute(order) data = cur.fetchall() print len(data) cur.close() conn.close()
def trade_search(query_body, fields): conn = default_db() cur = conn.cursor() order = 'select %s' % ','.join(fields) + ' from ' + STOCK_TABLE if 'stock_id' in query_body: order += ' where stock_id="%s"' % query_body['stock_id'] cur.execute(order) data = cur.fetchall() print len(data) cur.close() conn.close()
def nct_search(query_dict): conn = default_db() cur = conn.cursor() order = 'select * from ' + PARAMETER_TABLE if 'market_type' in query_dict: order += ' where market_type="%s"' % query_dict['market_type'] cur.execute(order) data = cur.fetchall() print data cur.close() conn.close()
def get_buy_signal_info(): yesterday_date = yesterday() print yesterday_date conn = default_db() cur = conn.cursor() order = 'select id, stock_id, ref_invest, high_buy from ' + SIGNAL_TABLE + \ ' where stock_status=0 and signal_date="%s"' % yesterday_date cur.execute(order) data = cur.fetchall() print len(data) cur.close() conn.close()
def nct_update(true_list, false_list): today_date = today() conn = default_db() cur = conn.cursor() for i in true_list: order = 'update ' + PARAMETER_TABLE + ' set status=1, modify_date="%s" where id=%d' % (today_date, i) cur.execute(order) for j in false_list: order = 'update ' + PARAMETER_TABLE + ' set status=1, modify_date="%s" where id=%d' % (today_date, i) cur.execute(order) conn.commit() cur.close() conn.close()
def nct_update(true_list, false_list): today_date = today() conn = default_db() cur = conn.cursor() for i in true_list: order = 'update ' + PARAMETER_TABLE + ' set status=1, modify_date="%s" where id=%d' % ( today_date, i) cur.execute(order) for j in false_list: order = 'update ' + PARAMETER_TABLE + ' set status=1, modify_date="%s" where id=%d' % ( today_date, i) cur.execute(order) conn.commit() cur.close() conn.close()
def nct_create(market_type, status, window_length, conf_width, trade_gap): today_date = today() conn = default_db() cur = conn.cursor() order = 'select * from ' + PARAMETER_TABLE + ' where market_type="%s" and window_length=%d and conf_width=%f and trade_gap=%d' \ % (market_type, window_length, conf_width, trade_gap) cur.execute(order) if cur.fetchone() == None: order = 'insert into ' + PARAMETER_TABLE + '(market_type, status, window_length, conf_width, trade_gap, modify_date) ' \ + 'values("%s", %d, %d, %f, %d, "%s")' % (market_type, status, window_length, conf_width, trade_gap, today_date) cur.execute(order) conn.commit() else: print 'exist' cur.close() conn.close()
def trade_sell(signal_id, stock_id, price, share, net_value): today_date = today() direction = 'sell' conn = default_db() order = 'select account from ' + ACCOUNT_TABLE + ' order by id desc' cur.execute(order) account = cur.fetchone()[0] value = price * share order = 'select * from ' + SIGNAL_TABLE + 'where id=%d' % signal_id cur.execute(order) if cur.fetchone() != None: order = 'update ' + SIGNAL_TABLE + ' set stock_status=2, sell_share=%d, sell_price=%f, sell_date="%s" where id=%d' % (share, price, today_date, signal_id) cur.execute(order) order = 'insert into ' + STOCK_TABLE + ' (stock_id, direction, share, value, date) values ("%s", "%s", %d, %f, "%s")' % (stock_id, direction, share, value, today_date) cur.execute(order) order = 'insert into ' + ACCOUNT_TABLE + ' (account, date) values (%f, "%s")' % (account + net_value, today_date) cur.execute(order) conn.commit() cur.close() conn.close()
def settings_modify(modify_dict): today_date = today() conn = default_db() cur = conn.cursor() order = 'select middle_on, strict_flag, static_closing, stocks from ' + SETTINGS_TABLE + ' order by id desc' cur.execute(order) middle_on, strict_flag, static_closing, stocks = cur.fetchone() if 'middle_on' in modify_dict: middle_on = modify_dict['middle_on'] if 'strict_flag' in modify_dict: strict_flag = modify_dict['strict_flag'] if 'static_closing' in modify_dict: static_closing = modify_dict['static_closing'] if 'stocks' in modify_dict: stocks = modify_dict['stocks'] order = 'insert into ' + SETTINGS_TABLE + '(middle_on, strict_flag, static_closing, stocks, date) ' \ + 'values(%d, %d, %d, "%s", "%s")' % (middle_on, strict_flag, static_closing, stocks, today_date) cur.execute(order) conn.commit() cur.close() conn.close()
def trade_sell(signal_id, stock_id, price, share, net_value): today_date = today() direction = 'sell' conn = default_db() order = 'select account from ' + ACCOUNT_TABLE + ' order by id desc' cur.execute(order) account = cur.fetchone()[0] value = price * share order = 'select * from ' + SIGNAL_TABLE + 'where id=%d' % signal_id cur.execute(order) if cur.fetchone() != None: order = 'update ' + SIGNAL_TABLE + ' set stock_status=2, sell_share=%d, sell_price=%f, sell_date="%s" where id=%d' % ( share, price, today_date, signal_id) cur.execute(order) order = 'insert into ' + STOCK_TABLE + ' (stock_id, direction, share, value, date) values ("%s", "%s", %d, %f, "%s")' % ( stock_id, direction, share, value, today_date) cur.execute(order) order = 'insert into ' + ACCOUNT_TABLE + ' (account, date) values (%f, "%s")' % ( account + net_value, today_date) cur.execute(order) conn.commit() cur.close() conn.close()