def add_stock_pool(self, sid, day, info): cur_day = str(day) current_time = datetime.datetime(int(cur_day[0:4]), int(cur_day[4:6]), int(cur_day[6:8])) # 本周一 start_time = current_time + datetime.timedelta( days=-1 * (current_time.isoweekday() - 1)) start_day = '{0:%Y%m%d}'.format(start_time) sql = "select id from t_stock_pool where sid={sid} and status = 'Y' and day >= {start_day} and day < {end_day}"\ .format(sid=sid, start_day=start_day, end_day=day) print sql try: record_list = self.db_conn.query_sql(sql) except Exception as e: print e return False if len(record_list) >= 1: return True info['add_time'] = time.mktime(datetime.datetime.now().timetuple()) info['status'] = 'Y' sql = SqlUtil.create_insert_sql("t_stock_pool", info) print sql try: self.db_conn.query_sql(sql, True) except Exception as e: print e return False return True
def core(self, location, day, param_sid): stock_df = pd.read_sql_query( "select * from t_stock where location = " + str(location) + " and type = 1 and status = 'Y'", self.conn, index_col='id') #print stock_df.index, stock_df.columns sid_list = [param_sid] if param_sid > 0 else stock_df.index for sid in sid_list: dyn_info = self.update_dyn(day, sid) if dyn_info is None: print format_log("stock_paused", { 'sid': sid, 'location': location, 'day': day }) continue sql = SqlUtil.create_insert_sql("t_stock_dyn", dyn_info) try: db_conn = SqlUtil.get_db(self.db_config) db_conn.query_sql(sql, True) except Exception as e: print "err=insert_dyn sid=" + str(sid) + " day=" + str( day) + " ex=" + str(e) continue print format_log("add_stock_dyn", dyn_info) print format_log("finish_dyn", {'location': location, 'day': day})
def add_stock_pool(db_config, redis_config, sid, day, source, trend_info = dict()): sql = "select id, sid, day, source from t_stock_pool where sid = {sid} and day = {day} and status = 'Y'".format(sid=sid, day=day) try: db_conn = SqlUtil.get_db(db_config) record_list = db_conn.query_sql(sql) if len(record_list) > 0: record_id = record_list[0]['id'] new_source = int(record_list[0]['source']) | source oper_sql = "update t_stock_pool set source = {source} where id = {id}".format(source=new_source, id=record_id) else: fields = {'sid': sid, 'day': day, 'source': source, 'status': 'Y'} fields['create_time'] = time.mktime( datetime.datetime.now().timetuple() ) if trend_info: fields.update(trend_info) # 获取当日行情数据 hqdata = get_hqdata(db_config, redis_config, sid, day) if hqdata: fields['close_price'] = hqdata['daily']['close_price'] if 'policy' in hqdata and hqdata['policy']: fields['volume_ratio'] = round(float(hqdata['policy']['volume_ratio']), 2) fields['rise_factor'] = round(float(hqdata['policy']['rise_factor']), 2) #print fields oper_sql = SqlUtil.create_insert_sql("t_stock_pool", fields) db_conn.query_sql(oper_sql, True) except Exception as e: print e return False return True
def add_stock_pool(self, sid, day, info): cur_day = str(day) current_time = datetime.datetime(int(cur_day[0:4]), int(cur_day[4:6]), int(cur_day[6:8])) # 本周一 start_time = current_time + datetime.timedelta(days = -1 * (current_time.isoweekday() - 1)) start_day = '{0:%Y%m%d}'.format(start_time) sql = "select id from t_stock_pool where sid={sid} and status = 'Y' and day >= {start_day} and day < {end_day}"\ .format(sid=sid, start_day=start_day, end_day=day) print sql try: record_list = self.db_conn.query_sql(sql) except Exception as e: print e return False if len(record_list) >= 1: return True info['add_time'] = time.mktime( datetime.datetime.now().timetuple() ) info['status'] = 'Y' sql = SqlUtil.create_insert_sql("t_stock_pool", info) print sql try: self.db_conn.query_sql(sql, True) except Exception as e: print e return False return True
def add_stock_price_threshold(db_config, sid, day, price, high_type, low_type): info = {'sid': sid, 'day': day, 'price': price, 'status': 'Y'} info['create_time'] = time.mktime(datetime.datetime.now().timetuple()) info['high_type'] = high_type info['low_type'] = low_type sql = SqlUtil.create_insert_sql("t_stock_price_threshold", info) print sql try: db_conn = SqlUtil.get_db(db_config) db_conn.query_sql(sql, True) except Exception as e: print e return False return True
def add_stock_price_threshold(db_config, sid, day, price, high_type, low_type): info = {'sid': sid, 'day': day, 'price': price, 'status': 'Y'} info['create_time'] = time.mktime( datetime.datetime.now().timetuple() ) info['high_type'] = high_type info['low_type'] = low_type sql = SqlUtil.create_insert_sql("t_stock_price_threshold", info) print sql try: db_conn = SqlUtil.get_db(db_config) db_conn.query_sql(sql, True) except Exception as e: print e return False return True
def core(self, location, day, param_sid): stock_df = pd.read_sql_query("select * from t_stock where location = " + str(location) + " and type = 1 and status = 'Y'", self.conn, index_col='id') #print stock_df.index, stock_df.columns sid_list = [param_sid] if param_sid > 0 else stock_df.index for sid in sid_list: dyn_info = self.update_dyn(day, sid) if dyn_info is None: print format_log("stock_paused", {'sid': sid, 'location': location, 'day': day}) continue sql = SqlUtil.create_insert_sql("t_stock_dyn", dyn_info) try: db_conn = SqlUtil.get_db(self.db_config) db_conn.query_sql(sql, True) except Exception as e: print "err=insert_dyn sid=" + str(sid) + " day=" + str(day) + " ex=" + str(e) continue print format_log("add_stock_dyn", dyn_info) print format_log("finish_dyn", {'location': location, 'day': day})