code_attribute/code_nature_analyse.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
code_attribute/first_target_code_data_processor.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
huaxin_client/l2_data_manager.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inited_data.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
l2/cancel_buy_strategy.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
l2/l2_data_manager_new.py | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
code_attribute/code_nature_analyse.py
@@ -18,58 +18,83 @@ class CodeNatureRecordManager: __redisManager = RedisManager(0) __k_format_cache = {} __nature_cache = {} __db = 0 __instance = None __redis_manager = redis_manager.RedisManager(0) def __new__(cls, *args, **kwargs): if not cls.__instance: cls.__instance = super(CodeNatureRecordManager, cls).__new__(cls, *args, **kwargs) cls.__load_datas() return cls.__instance @classmethod def __get_redis(cls): return cls.__redisManager.getRedis() return cls.__redis_manager.getRedis() @classmethod def __load_datas(cls): __redis = cls.__get_redis() try: keys = RedisUtils.keys(__redis, "k_format-*") for k in keys: code = k.split("-")[1] val = RedisUtils.get(__redis, k) val = json.loads(val) cls.__k_format_cache[code] = val keys = RedisUtils.keys(__redis, "code_nature-*") for k in keys: code = k.split("-")[1] val = RedisUtils.get(__redis, k) val = json.loads(val) cls.__nature_cache[code] = val except: pass finally: RedisUtils.realse(__redis) # 保存K线形态 @classmethod def save_k_format(cls, code, k_format): RedisUtils.setex(cls.__get_redis(), f"k_format-{code}", tool.get_expire(), json.dumps(k_format)) def save_k_format(self, code, k_format): self.__k_format_cache[code] = k_format RedisUtils.setex_async(self.__db, f"k_format-{code}", tool.get_expire(), json.dumps(k_format)) @classmethod def get_k_format(cls, code): val = RedisUtils.get(cls.__get_redis(), f"k_format-{code}") def get_k_format(self, code): val = RedisUtils.get(self.__get_redis(), f"k_format-{code}") if val: return json.loads(val) return None @classmethod def get_k_format_cache(cls, code): val = None if code in cls.__k_format_cache: val = cls.__k_format_cache[code] if not val: val = cls.get_k_format(code) if val: cls.__k_format_cache[code] = val def get_k_format_cache(self, code): val = self.__k_format_cache.get(code) # 复制 return copy.deepcopy(val) if val else None # 保存股性 @classmethod def save_nature(cls, code, natures): RedisUtils.setex(cls.__get_redis(), f"code_nature-{code}", tool.get_expire(), json.dumps(natures)) def clear(self): self.__k_format_cache.clear() self.__nature_cache.clear() keys = RedisUtils.keys(self.__get_redis(), "k_format-*") for k in keys: RedisUtils.delete(self.__get_redis(), k) keys = RedisUtils.keys(self.__get_redis(), "code_nature-*") for k in keys: RedisUtils.delete(self.__get_redis(), k) @classmethod def get_nature(cls, code): val = RedisUtils.get(cls.__get_redis(), f"code_nature-{code}") # 保存股性 def save_nature(self, code, natures): RedisUtils.setex_async(self.__db, f"code_nature-{code}", tool.get_expire(), json.dumps(natures)) def get_nature(self, code): val = RedisUtils.get(self.__get_redis(), f"code_nature-{code}") if val: return json.loads(val) return None @classmethod def get_nature_cache(cls, code): if code in cls.__nature_cache: return cls.__nature_cache[code] val = cls.get_nature(code) if val: cls.__nature_cache[code] = val return val def get_nature_cache(self, code): return self.__nature_cache.get(code) class LatestMaxVolumeManager: @@ -344,33 +369,17 @@ datas = copy.deepcopy(datas) datas.sort(key=lambda x: x["bob"]) datas = datas[-80:] max_volume = 0 max_volume_index = 0 max_price = 0 max_price_index = 0 for index in range(0, len(datas)): data = datas[index] if max_volume < data["volume"]: max_volume = data["volume"] max_volume_index = index price = 0 price_index = 0 for index in range(max_volume_index, len(datas)): data = datas[index] if data["high"] > price: price = data["high"] price_index = index index = price_index # 最大量当日最高价比当日之后的最高价涨幅在15%以内 if (price - datas[max_volume_index]["high"]) / datas[max_volume_index]["high"] < 0.15: price = datas[max_volume_index]["high"] index = max_volume_index print(max_volume) rate = (price - limit_up_price) / limit_up_price if 0 < rate < 0.03: return True, datas[index]['bob'].strftime("%Y-%m-%d") if data["high"] > max_price: max_price = data["high"] max_price_index = index rate = (max_price - float(limit_up_price)) / max_price if 0 < rate < 0.02: return True, datas[max_price_index]['bob'].strftime("%Y-%m-%d") return False, '' @@ -541,4 +550,3 @@ HighIncreaseCodeManager().add_code("000333") print(HighIncreaseCodeManager().is_in("000333")) print(HighIncreaseCodeManager().is_in("000222")) code_attribute/first_target_code_data_processor.py
@@ -119,6 +119,11 @@ volumes_data[:90])) logger_first_code_record.info("{} 获取到首板60天最大量:{}", code, volumes) code_volumn_manager.set_histry_volumn(code, volumes[0], volumes[1], volumes[2]) # 保存K线形态 k_format = code_nature_analyse.get_k_format(limit_up_price, volumes_data) code_nature_analyse.CodeNatureRecordManager().save_k_format(code, k_format) if code_nature_analyse.is_up_too_high_in_10d(volumes_data): # 判断是否太高 l2_trade_util.forbidden_trade(code, "股价长得太高") @@ -223,3 +228,12 @@ gpcode_first_screen_manager.process_ticks(prices) logger_l2_codes_subscript.info(f"({request_id})l2代码相关数据加载完成") return tick_datas if __name__ == "__main__": code = "002308" limit_up_price = gpcode_manager.get_limit_up_price(code) volumes_data = inited_data.get_volumns_by_code(code, 150) # 保存K线形态 k_format = code_nature_analyse.get_k_format(limit_up_price, volumes_data) code_nature_analyse.CodeNatureRecordManager().save_k_format(code, k_format) huaxin_client/l2_data_manager.py
@@ -158,23 +158,23 @@ upload_queue = queue_info[1] while True: try: if len(q) > 0: while len(q) > 0: data = q.popleft() # 前置数据处理,过滤掉无用的数据 data = self.__filter_order(data) if data: temp_list.append(data) if temp_list: # 上传数据 self.__upload_l2_data(code, upload_queue, temp_list) temp_list = [] else: if temp_list: # 上传数据 self.__upload_l2_data(code, upload_queue, temp_list) temp_list = [] else: if code not in self.temp_order_queue_dict: self.l2_order_codes.discard(code) break self.l2_order_codes.add(code) time.sleep(0.001) if code not in self.temp_order_queue_dict: self.l2_order_codes.discard(code) break self.l2_order_codes.add(code) time.sleep(0.001) except Exception as e: logging.exception(e) @@ -189,22 +189,21 @@ temp_list = [] while True: try: if len(q) > 0: while len(q) > 0: data = q.popleft() data = self.__filter_transaction(data) if data: temp_list.append(data) if temp_list: # 上传数据 self.__upload_l2_data(code, upload_queue, temp_list) temp_list = [] else: if temp_list: # 上传数据 self.__upload_l2_data(code, upload_queue, temp_list) temp_list = [] else: if code not in self.temp_transaction_queue_dict: self.l2_transaction_codes.discard(code) break self.l2_transaction_codes.add(code) time.sleep(0.002) if code not in self.temp_transaction_queue_dict: self.l2_transaction_codes.discard(code) break self.l2_transaction_codes.add(code) time.sleep(0.002) except: pass finally: inited_data.py
@@ -9,7 +9,7 @@ # import gm.api as gmapi from code_attribute import big_money_num_manager, global_data_loader, gpcode_manager, gpcode_first_screen_manager from code_attribute.code_nature_analyse import LatestMaxVolumeManager, HighIncreaseCodeManager from code_attribute.code_nature_analyse import LatestMaxVolumeManager, HighIncreaseCodeManager, CodeNatureRecordManager from db.redis_manager_delegate import RedisUtils from l2.l2_sell_manager import L2MarketSellManager from ths import client_manager @@ -105,6 +105,8 @@ L2MarketSellManager().clear() # 涨幅过高代码 HighIncreaseCodeManager().clear() # 股性清除 CodeNatureRecordManager().clear() # 每日初始化 l2/cancel_buy_strategy.py
@@ -576,6 +576,7 @@ # 设置成交进度 def set_transaction_index(self, code, buy_single_index, index): try: # 每3s或者成交进度变化就囊括一次 if index == self.__transaction_progress_index_dict.get(code): if code in self.__transaction_progress_index_updatetime_dict and time.time() - self.__transaction_progress_index_updatetime_dict.get( code) < 3: @@ -820,7 +821,7 @@ if temp_rate > 3: temp_rate = 3 deal_rate = round((temp_rate * 3.5 - 2.5) / 100, 4) if is_up else round( (temp_rate * 10.5 - 7.5) / 100, 4) (temp_rate * 5.25 - 3.75) / 100, 4) base_rate += block_rate base_rate += deal_rate l2/l2_data_manager_new.py
@@ -1119,16 +1119,21 @@ order_begin_pos.count = 0 order_begin_pos.buy_single_index = buy_single_index if order_begin_pos.sell_info: if float(total_datas[buy_single_index]["val"]["price"]) >= 3 and cls.volume_rate_info[code][0] > 0.3 and sell_info[1] > 2000 * 10000: # 暂时打8折 # order_begin_pos.threshold_money = int(sell_info[1] * 0.8) # 深证总卖大于1000万的票,m值打5折 if code.find('00') == 0: order_begin_pos.threshold_money = int(sell_info[1] * 0.6) else: order_begin_pos.threshold_money = int(sell_info[1] * 0.8) else: k_format = code_nature_analyse.CodeNatureRecordManager().get_k_format_cache(code) if k_format and (k_format[1][0] or k_format[3][0]): # 股价新高或者逼近前高 order_begin_pos.threshold_money = int(sell_info[1]) else: if float(total_datas[buy_single_index]["val"]["price"]) >= 3 and cls.volume_rate_info[code][0] > 0.3 and sell_info[1] > 2000 * 10000: # 暂时打8折 # order_begin_pos.threshold_money = int(sell_info[1] * 0.8) # 深证总卖大于1000万的票,m值打5折 if code.find('00') == 0: order_begin_pos.threshold_money = int(sell_info[1] * 0.6) else: order_begin_pos.threshold_money = int(sell_info[1] * 0.8) else: order_begin_pos.threshold_money = int(sell_info[1]) l2_log.debug(code, "获取到买入信号起始点:{} ,计算范围:{}-{} ,量比:{},是否板上买:{},数据:{} 模式:{}({})", buy_single_index, compute_start_index, compute_end_index, cls.volume_rate_info[code], order_begin_pos.at_limit_up,