| | |
| | | import queue |
| | | import time |
| | | import lev2mdapi |
| | | from l2.huaxin import l2_huaxin_util |
| | | from log_module import log |
| | | from log_module.log import logger_local_huaxin_l2_subscript, logger_system |
| | | from utils import tool |
| | |
| | | def get_big_sell_orders(self): |
| | | return self.__big_sell_orders |
| | | |
| | | def add_transaction_data_for_accurate(self, data): |
| | | def add_transaction_data_for_accurate(self, item): |
| | | """ |
| | | 获取精确的买单信息 |
| | | @param data: |
| | |
| | | def format_timestamp(timestamp): |
| | | time_str = str(timestamp) |
| | | return int(time_str[:5] if time_str[0] == '9' else time_str[:6]) |
| | | |
| | | item = (data["BuyNo"], data["SellNo"], data["TradePrice"], data["TradeVolume"]) |
| | | # item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'], |
| | | # "TradeVolume": pTransaction['TradeVolume'], |
| | | # "OrderTime": pTransaction['TradeTime'], "MainSeq": pTransaction['MainSeq'], |
| | | # "SubSeq": pTransaction['SubSeq'], "BuyNo": pTransaction['BuyNo'], |
| | | # "SellNo": pTransaction['SellNo'], |
| | | # "ExecType": pTransaction['ExecType'].decode()} |
| | | money = round(item[2] * item[3]) |
| | | volume = item[3] |
| | | price = item[2] |
| | | order_time = data["OrderTime"] |
| | | order_time = item[4] |
| | | if item[0] not in self.__big_accurate_buy_order_dict: |
| | | # (买单号, 量, 金额, 时间, 最新成交价格) |
| | | self.__big_accurate_buy_order_dict[item[0]] = [item[0], 0, 0, order_time, price] |
| | |
| | | if self.__latest_buy_order and self.__latest_buy_order[0] != item[0]: |
| | | # 有可能是大单成交完成, 判断上个订单是否是大单 |
| | | last_buy_order = self.__big_accurate_buy_order_dict.get(self.__latest_buy_order[0]) |
| | | try: |
| | | if last_buy_order[2] > 299e4: |
| | | self.big_accurate_buy_order_queue.put_nowait(last_buy_order) |
| | | except Exception as e: |
| | | print("数据:", last_buy_order, self.__latest_buy_order, item) |
| | | raise e |
| | | |
| | | if last_buy_order[2] > 299e4: |
| | | self.big_accurate_buy_order_queue.put_nowait(last_buy_order) |
| | | |
| | | # 如果数据过多需要移除过长时间的小金额数据 |
| | | accurate_buy_count = len(self.__big_accurate_buy_order_dict.keys()) |
| | | if accurate_buy_count > 10000 and accurate_buy_count - self.__last_accurate_buy_count > 2000: |
| | | # 超过1w条数据且新增2000条数据 |
| | | # 超过1w条数据就要移除30分钟之前的数据 |
| | | now_time_int = int(tool.trade_time_add_second(tool.get_now_time_str(), -3600).replace(":", "")) |
| | | now_time_int = int( |
| | | tool.trade_time_add_second(l2_huaxin_util.convert_time(order_time), -3600).replace(":", "")) |
| | | try: |
| | | remove_order_nos = [x for x in self.__big_accurate_buy_order_dict if |
| | | now_time_int - format_timestamp( |
| | | self.__big_accurate_buy_order_dict[x][3]) > 0] |
| | | format_timestamp(self.__big_accurate_buy_order_dict[x][3]) < now_time_int] |
| | | if remove_order_nos: |
| | | for order_no in remove_order_nos: |
| | | self.__big_accurate_buy_order_dict.pop(order_no) |
| | |
| | | if accurate_sell_count > 10000 and accurate_sell_count - self.__last_accurate_sell_count > 2000: |
| | | # 超过1w条数据且新增2000条数据 |
| | | # 超过1w条数据就要移除30分钟之前的数据 |
| | | now_time_int = int(tool.trade_time_add_second(tool.get_now_time_str(), -3600).replace(":", "")) |
| | | now_time_int = int(tool.trade_time_add_second(l2_huaxin_util.convert_time(order_time), -3600).replace(":", "")) |
| | | try: |
| | | remove_order_nos = [x for x in self.__big_accurate_sell_order_dict if |
| | | now_time_int - format_timestamp( |
| | | self.__big_accurate_sell_order_dict[x][3]) > 0] |
| | | now_time_int > format_timestamp( |
| | | self.__big_accurate_sell_order_dict[x][3])] |
| | | if remove_order_nos: |
| | | for order_no in remove_order_nos: |
| | | self.__big_accurate_sell_order_dict.pop(order_no) |
| | |
| | | self.__last_accurate_sell_count = len(self.__big_accurate_sell_order_dict.keys()) |
| | | |
| | | def add_transaction_data(self, data): |
| | | item = (data["BuyNo"], data["SellNo"], data["TradePrice"], data["TradeVolume"]) |
| | | item = (data["BuyNo"], data["SellNo"], data["TradePrice"], data["TradeVolume"], data["OrderTime"]) |
| | | # item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'], |
| | | # "TradeVolume": pTransaction['TradeVolume'], |
| | | # "OrderTime": pTransaction['TradeTime'], "MainSeq": pTransaction['MainSeq'], |
| | |
| | | money = round(item[2] * item[3]) |
| | | volume = item[3] |
| | | price = item[2] |
| | | order_time = data["OrderTime"] |
| | | order_time = item[4] |
| | | |
| | | if self.accurate_buy: |
| | | self.add_transaction_data_for_accurate(data) |
| | | self.add_transaction_data_for_accurate(item) |
| | | |
| | | if not self.__latest_buy_order: |
| | | # (买单号, 量, 金额, 时间, 最新成交价格) |