| | |
| | | from utils.tool import CodeDataCacheUtil |
| | | |
| | | |
| | | def set_real_place_position(code, index): |
| | | def set_real_place_position(code, index, buy_single_index=None): |
| | | DCancelBigNumComputer().set_real_order_index(code, index) |
| | | SecondCancelBigNumComputer().set_real_place_order_index(code, index) |
| | | LCancelBigNumComputer().set_real_place_order_index(code, index) |
| | | LCancelBigNumComputer().set_real_place_order_index(code, index, buy_single_index=buy_single_index) |
| | | |
| | | |
| | | class SecondCancelBigNumComputer: |
| | |
| | | def clear(self, code=None): |
| | | if code: |
| | | self.del_watch_index(code) |
| | | if code in self.__last_trade_progress_dict: |
| | | self.__last_trade_progress_dict.pop(code) |
| | | if code in self.__real_place_order_index_dict: |
| | | self.__real_place_order_index_dict.pop(code) |
| | | else: |
| | | keys = RedisUtils.keys(self.__get_redis(), f"l_cancel_watch_index-*") |
| | | for k in keys: |
| | | code = k.replace("l_cancel_watch_index-", "") |
| | | if code in self.__last_trade_progress_dict: |
| | | self.__last_trade_progress_dict.pop(code) |
| | | if code in self.__real_place_order_index_dict: |
| | | self.__real_place_order_index_dict.pop(code) |
| | | self.del_watch_index(code) |
| | | |
| | | # 计算观察索引,倒序计算 |
| | |
| | | break |
| | | |
| | | # 设置真实下单位置 |
| | | def set_real_place_order_index(self, code, index): |
| | | def set_real_place_order_index(self, code, index, buy_single_index=None): |
| | | self.__real_place_order_index_dict[code] = index |
| | | if self.__last_trade_progress_dict.get(code): |
| | | self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), index) |
| | | else: |
| | | if buy_single_index: |
| | | self.compute_watch_index(code, buy_single_index, index) |
| | | |
| | | # 设置成交位置,成交位置变化之后相应的监听数据也会发生变化 |
| | | def set_trade_progress(self, code, index, total_data): |
| | | # 已经有计算的无法触发计算 |
| | | old_watch_indexes = self.__get_watch_indexes_cache(code) |
| | | if old_watch_indexes: |
| | | return |
| | | if self.__last_trade_progress_dict.get(code) == index: |
| | | return |
| | | self.__last_trade_progress_dict[code] = index |
| | | |
| | | try: |
| | | # 已经有计算的无法触发计算 |
| | | old_watch_indexes = self.__get_watch_indexes_cache(code) |
| | | if old_watch_indexes and self.__last_trade_progress_dict.get(code): |
| | | return |
| | | finally: |
| | | self.__last_trade_progress_dict[code] = index |
| | | |
| | | if self.__real_place_order_index_dict.get(code): |
| | | # 触发计算 |
| | | self.compute_watch_index(code, self.__last_trade_progress_dict.get(code), |
| | |
| | | cls.unreal_buy_dict.pop(code) |
| | | |
| | | @classmethod |
| | | def set_real_place_order_index(cls, code, index): |
| | | cancel_buy_strategy.set_real_place_position(code, index) |
| | | def set_real_place_order_index(cls, code, index,buy_single_index): |
| | | cancel_buy_strategy.set_real_place_position(code, index,buy_single_index) |
| | | |
| | | # 处理华鑫L2数据 |
| | | @classmethod |
| | |
| | | # 获取下单位置 |
| | | place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, datas) |
| | | if place_order_index: |
| | | cls.set_real_place_order_index(code, place_order_index) |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos( |
| | | code) |
| | | cls.set_real_place_order_index(code, place_order_index, buy_single_index) |
| | | async_log_util.info(logger_l2_process, "code:{} 获取到下单真实位置:{}", code, place_order_index) |
| | | __start_time = round(t.time() * 1000) |
| | | if len(datas) > 0: |
| | |
| | | |
| | | dask.compute(f1, f2, f3, f4) |
| | | else: |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | # 涨停价成交 |
| | | if limit_up_price and abs(float(limit_up_price) - float(datas[-1][1])) < 0.01: |
| | | # 买入订单号 |
| | | # 获取开盘啦的涨停时间 |
| | | kpl_total_datas = kpl_data_manager.KPLLimitUpDataRecordManager.total_datas |
| | | if total_datas and kpl_total_datas: |
| | | limit_up_time = None |
| | | for d in kpl_total_datas: |
| | | if d[3] == code: |
| | | limit_up_time = int(d[5]) |
| | | if limit_up_time: |
| | | if int(tool.to_time_str(limit_up_time).replace(":", "")) < int( |
| | | total_datas[0]["val"]["time"].replace(":", "")): |
| | | # 涨停时间比第一条数据时间还早 |
| | | l2_trade_util.forbidden_trade(code) |
| | | logger_trade.warning(f"{code}添加到禁止买入,原因:涨停时间比第一条数据时间还早") |
| | | pass |
| | | except Exception as e: |
| | | hx_logger_l2_transaction.exception(e) |
| | | |
New file |
| | |
| | | """ |
| | | 卖数据处理器 |
| | | """ |
| | | from utils import tool |
| | | |
| | | |
| | | class TickDataProcess: |
| | | # 初始化原始价格,取9点25的价格 |
| | | __last_price_infos = {} |
| | | |
| | | __last_15s_price_infos = {} |
| | | |
| | | __reference_price_info = {} |
| | | |
| | | @classmethod |
| | | def init_origin_price(cls, code, price, rate_percent): |
| | | cls.__last_price_infos[code] = [("09:25:00", price, rate_percent)] |
| | | cls.__last_15s_price_infos[code] = [("09:25:00", price, rate_percent)] |
| | | cls.__reference_price_info[code] = ("09:25:00", price, rate_percent) |
| | | |
| | | # 获取15s最终的价格 |
| | | @classmethod |
| | | def get_15_seconds_price_info(cls, price_infos, max_amplitude_rate_percent): |
| | | final_price_info = price_infos[-1] |
| | | max_rate_info = None |
| | | for price_info in price_infos: |
| | | if price_info - price_infos[0][2] > max_amplitude_rate_percent: |
| | | if not max_rate_info: |
| | | max_rate_info = price_info |
| | | if max_rate_info[2] < price_info[2]: |
| | | max_rate_info = price_info |
| | | if max_rate_info: |
| | | final_price_info = max_rate_info |
| | | return final_price_info |
| | | |
| | | # 价格信息(时间,现价,涨幅) |
| | | @classmethod |
| | | def process_tick_data(cls, code, time_str, price, rate_percent, max_amplitude_rate_percent=0.6): |
| | | now_price_info = (time_str, price, rate_percent) |
| | | latest_price_info = cls.__last_price_infos.get(code)[-1] |
| | | # 填充中间缺失的数据 |
| | | latest_time = latest_price_info[0] |
| | | if tool.trade_time_sub(latest_time, "09:29:57") < 0: |
| | | latest_time = "09:29:57" |
| | | |
| | | sub_time = tool.trade_time_sub(time_str, latest_time) |
| | | fill_middle_count = sub_time // 3 - 1 |
| | | if fill_middle_count > 0: |
| | | for i in range(0, fill_middle_count): |
| | | cls.__last_price_infos.get(code).append( |
| | | (tool.trade_time_add_second(latest_price_info[0], 3), latest_price_info[1], latest_price_info[2])) |
| | | cls.__last_price_infos.get(code).append(now_price_info) |
| | | latest_15s_price_info = cls.__last_15s_price_infos[code][-1] |
| | | if now_price_info[2] - latest_15s_price_info[2] > max_amplitude_rate_percent: |
| | | # 涨幅超过振幅且比参考点的振幅大 |
| | | if now_price_info[2] > cls.__reference_price_info[code][2]: |
| | | cls.__reference_price_info[code] = now_price_info |
| | | elif latest_15s_price_info[2] - now_price_info[2] > max_amplitude_rate_percent: |
| | | # 跌幅超过振幅 |
| | | cls.__reference_price_info[code] = now_price_info |
| | | # 当前点是否比参考点下降振幅就触发卖 |
| | | if cls.__reference_price_info[code][2] - now_price_info[2] > max_amplitude_rate_percent: |
| | | # 触发卖 |
| | | cls.__reference_price_info[code] = now_price_info |
| | | return True |
| | | else: |
| | | # 尚未触发卖 |
| | | if len(cls.__last_price_infos.get(code)) >= 5: |
| | | # 满足15s数据 |
| | | reference_price_info = cls.get_15_seconds_price_info(cls.__last_price_infos.get(code), max_amplitude_rate_percent) |
| | | cls.__last_price_infos.get(code).clear() |
| | | cls.__reference_price_info[code] = reference_price_info |
| | | |
| | | |
| | | |
| | | |