def _get_all_share_ids(self): date_info = time.strftime('%Y_%m_%d') trade_table_name = "trade_info_%s" % (date_info) share_ids = fetch_data.get_data(fetch_data.select_db("daily_temp", trade_table_name, ["share_id"],{"share_id":[["000001","000010","000301","000601","000901","002101","002401","002701","300001","300301","600301","600601","601801","603001","603601","603901"],"in"]}, pre = "distinct")) #share_ids = fetch_data.get_data(fetch_data.select_db("daily_temp", trade_table_name, ["share_id"],{}, pre = "distinct")) #share_ids = fetch_data.get_data(fetch_data.select_db("daily_temp", trade_table_name, ["share_id"],{"share_id":["000001","="]}, pre = "distinct")) return share_ids
def _get_all_share_ids(self): date_info = time.strftime('%Y_%m_%d') trade_table_name = "trade_info_%s" % (date_info) share_ids = fetch_data.get_data( fetch_data.select_db(self._daily_temp_conn_name, trade_table_name, ["share_id"], {}, pre="distinct")) return share_ids
def _get_all_share_ids(self): date_info = time.strftime('%Y_%m_%d') trade_table_name = "trade_info_%s" % (date_info) #share_ids = fetch_data.get_data(fetch_data.select_db("daily_temp", trade_table_name, ["share_id"],{"share_id":["000001","="]}, pre = "distinct")) share_ids = fetch_data.get_data( fetch_data.select_db("daily_temp", trade_table_name, ["share_id"], {}, pre="distinct")) return share_ids
def _get_all_share_ids_market_type(self): share_ids = self._get_all_share_ids() ids = [] for share_id in share_ids: ids.append(share_id[0]) share_ids = fetch_data.get_data( fetch_data.select_db("stock_db", "share_base_info", ["share_id", "market_type"], {"share_id": [ids, "in"]})) return share_ids
def _get_daily_info(self, share_id, table_name, start_time, compare): stock_conn_manager_obj = stock_conn_manager() conn_name = stock_conn_manager_obj.get_conn_name(share_id) data = fetch_data.get_data( fetch_data.select_db(conn_name, table_name, self._table_keys, {"time": [start_time, compare]}, extend="order by time desc")) return data
def _get_start_time(self, share_id, table_name, ma_empty_start_time): stock_conn_manager_obj = stock_conn_manager() conn_name = stock_conn_manager_obj.get_conn_name(share_id) last_time = fetch_data.get_data(fetch_data.select_db(conn_name, table_name, ["time"], {"time":[ma_empty_start_time, "<="]}, extend="order by time desc limit 180")) if len(last_time) > 0: last_day = last_time[-1][0] tz = pytz.timezone('Asia/Shanghai') last_day_obj = datetime.datetime.fromtimestamp(last_day, tz) time_str = last_day_obj.strftime("%Y%m%d") return time.mktime(time.strptime(time_str, '%Y%m%d')) else: return ma_empty_start_time
def _get_ex_dividend_last_time(self, share_id, table_name): stock_conn_manager_obj = stock_conn_manager() conn_name = stock_conn_manager_obj.get_conn_name(share_id) data = fetch_data.get_data( fetch_data.select_db(conn_name, table_name, ["time"], {}, extend="order by time desc limit 1")) if len(data) > 0: last_day = data[0][0] return int(last_day) else: return 0
def _get_close_volume(self, share_id, table_name, start_time): stock_conn_manager_obj = stock_conn_manager() conn_name = stock_conn_manager_obj.get_conn_name(share_id) data = fetch_data.get_data(fetch_data.select_db(conn_name, table_name, ["time", "today_close", "volume"], {"time":[start_time, ">="]})) time_list = [] close_list = [] volume_list = [] for item in data: time_int = item[0] close = item[1] volume = item[2] time_list.append(time_int) close_list.append(close) volume_list.append(volume) return {"time":time_list, "close":close_list, "volume":volume_list}
def _bak_market_maker_info(self, share_id): date_info = time.strftime('%Y_%m_%d') table_name = "market_maker_%s" % (date_info) fields_array = [ "time_str", "price", "up_percent", "market_maker_net_inflow", "market_maker_net_inflow_per", "huge_inflow", "huge_inflow_per", "large_inflow", "large_inflow_per", "medium_inflow", "medium_inflow_per", "small_inflow", "small_inflow_per" ] daily_data = fetch_data.get_data( fetch_data.select_db(self._daily_temp_conn_name, table_name, fields_array, {"share_id": [share_id, "="]})) self._bak_single_market_maker_info(share_id, daily_data)
def _get_start_time(self, share_id, table_name): stock_conn_manager_obj = stock_conn_manager() conn_name = stock_conn_manager_obj.get_conn_name(share_id) last_time = fetch_data.get_data( fetch_data.select_db(conn_name, table_name, ["time"], {}, extend="order by time desc limit 1")) if len(last_time) > 0: last_day = last_time[0][0] tz = pytz.timezone('Asia/Shanghai') last_day_obj = datetime.datetime.fromtimestamp(last_day, tz) while True: next_day_obj = last_day_obj + datetime.timedelta(days=1) if next_day_obj.weekday() < 5: break last_day_obj = next_day_obj time_str = next_day_obj.strftime("%Y%m%d") else: time_str = "19900101" return time.mktime(time.strptime(time_str, '%Y%m%d'))
def _get_average_info(self, share_id, table_name, period = 0): stock_conn_manager_obj = stock_conn_manager() conn_name = stock_conn_manager_obj.get_conn_name(share_id) periods = [5, 10, 20, 30, 60, 120] types = ["close_ma", "volume_ma"] columns = ["time", "today_close", "today_high", "today_low", "today_open", "yesterday_close", "pchg", "turnover_rate", "volume", "turnover"] for type_item in types: for period_item in periods: column_name = "%s%d" % (type_item, period_item) columns.append(column_name) extend_str = "order by time desc" if period > 0: extend_str = "%s limit %d" % (extend_str, period) data= fetch_data.get_data(fetch_data.select_db(conn_name, table_name, columns, {}, extend=extend_str)) infos = [] for data_item in data: info = {} for index in range(len(columns)): info[columns[index]] = data_item[index] infos.insert(0, info) return infos