| | |
| | | from db import redis_manager |
| | | import tool |
| | | import l2.l2_data_util |
| | | from log import logger_l2_trade_buy_queue |
| | | |
| | | |
| | | class TradeBuyQueue: |
| | |
| | | val = json.loads(val) |
| | | return val[0], [1] |
| | | |
| | | def __save_buy_progress_index(self, code, index): |
| | | def __save_buy_progress_index(self, code, index, is_default): |
| | | key = "trade_buy_progress_index-{}".format(code) |
| | | self.__getRedis().setex(key, tool.get_expire(), index) |
| | | self.__getRedis().setex(key, tool.get_expire(), json.dumps((index, is_default))) |
| | | # 返回数据与更新时间 |
| | | |
| | | def __get_buy_progress_index(self, code): |
| | | key = "trade_buy_progress_index-{}".format(code) |
| | | val = self.__getRedis().get(key) |
| | | if val is None: |
| | | return None |
| | | return int(val) |
| | | return None, True |
| | | val = json.loads(val) |
| | | return int(val[0]), bool(val[1]) |
| | | |
| | | # 最近的非涨停买1的时间 |
| | | def __save_latest_not_limit_up_time(self, code, time_str): |
| | |
| | | self.last_buy_queue_data[code] = queues |
| | | min_num = round(constant.L2_MIN_MONEY / (limit_up_price * 100)) |
| | | num_list = [] |
| | | for num in queues: |
| | | # 忽略第一条数据 |
| | | for i in range(1, len(queues)): |
| | | num = queues[i] |
| | | if num > min_num: |
| | | num_list.append(num) |
| | | # 保存列表 |
| | |
| | | def save_traded_index(self, code, buy1_price, buyQueueBig): |
| | | total_datas = l2.l2_data_util.local_today_datas.get(code) |
| | | today_num_operate_map = l2.l2_data_util.local_today_num_operate_map.get(code) |
| | | index = l2.l2_data_util.L2TradeQueueUtils.find_traded_progress_index(buy1_price, total_datas, |
| | | today_num_operate_map, buyQueueBig,self.__get_latest_not_limit_up_time(code)) |
| | | if index is not None: |
| | | # 保存成交进度 |
| | | self.__save_buy_progress_index(code, index) |
| | | return index |
| | | for i in range(0, len(buyQueueBig)): |
| | | buyQueueBigTemp = buyQueueBig[i:] |
| | | if i > 0 and len(buyQueueBigTemp) < 2: |
| | | # 已经执行过一次,且数据量小于2条就终止计算 |
| | | break |
| | | |
| | | last_index, is_default = self.get_traded_index(code) |
| | | |
| | | index = l2.l2_data_util.L2TradeQueueUtils.find_traded_progress_index(buy1_price, total_datas, |
| | | today_num_operate_map, buyQueueBigTemp, |
| | | ( |
| | | last_index if last_index is not is_default else 0), |
| | | self.__get_latest_not_limit_up_time( |
| | | code)) |
| | | if index is not None: |
| | | logger_l2_trade_buy_queue.info(f"确定交易进度:code-{code} index-{index}") |
| | | # 保存成交进度 |
| | | self.__save_buy_progress_index(code, index, False) |
| | | return index |
| | | return None |
| | | |
| | | # 获取成交进度索引 |
| | | def get_traded_index(self, code): |
| | | index = self.__get_buy_progress_index(code) |
| | | return index |
| | | index, is_default = self.__get_buy_progress_index(code) |
| | | return index, is_default |
| | | |
| | | def set_default_traded_index(self, code, index): |
| | | self.__save_buy_progress_index(code, index, True) |
| | | |
| | | |
| | | if __name__ == '__main': |
| | | |
| | | |
| | | pass |