| | |
| | | |
| | | # 买入的大单订单号 |
| | | |
| | | def __init__(self, api, l2_data_upload_manager): |
| | | def __init__(self, api, l2_data_upload_manager: L2DataUploadManager): |
| | | lev2mdapi.CTORATstpLev2MdSpi.__init__(self) |
| | | self.__api = api |
| | | self.is_login = False |
| | |
| | | code = d[0] |
| | | codes.add(code) |
| | | self.codes_volume_and_price_dict[code] = (d[1], d[2]) |
| | | self.l2_data_upload_manager.set_order_fileter_condition(code, d[1], d[2]) |
| | | add_codes = codes - self.subscripted_codes |
| | | del_codes = self.subscripted_codes - codes |
| | | print("add del codes", add_codes, del_codes) |
| | |
| | | |
| | | def set_code_special_watch_volume(self, code, volume): |
| | | # 有效期为3s |
| | | self.special_code_volume_for_order_dict[code] = (volume, time.time() + 3) |
| | | # self.special_code_volume_for_order_dict[code] = (volume, time.time() + 3) |
| | | min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code) |
| | | self.l2_data_upload_manager.set_order_fileter_condition(code, min_volume,limit_up_price, |
| | | {volume, constant.SHADOW_ORDER_VOLUME}, time.time() + 3) |
| | | |
| | | async_log_util.info(logger_local_huaxin_l2_subscript, f"设置下单量监听:{code}-{volume}") |
| | | |
| | | def OnFrontConnected(self): |
| | |
| | | |
| | | def OnRtnTransaction(self, pTransaction): |
| | | code = str(pTransaction['SecurityID']) |
| | | min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code) |
| | | # min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code) |
| | | # 输出逐笔成交数据 |
| | | if pTransaction['ExecType'] == b"2": |
| | | if min_volume is None: |
| | | # 默认筛选50w |
| | | if pTransaction['TradePrice'] * pTransaction['Volume'] < 500000: |
| | | return |
| | | elif pTransaction['TradeVolume'] < min_volume: |
| | | return |
| | | # if min_volume is None: |
| | | # # 默认筛选50w |
| | | # if pTransaction['TradePrice'] * pTransaction['Volume'] < 500000: |
| | | # return |
| | | # elif pTransaction['TradeVolume'] < min_volume: |
| | | # return |
| | | # 撤单 |
| | | item = {"SecurityID": pTransaction['SecurityID'], "Price": pTransaction['TradePrice'], |
| | | "Volume": pTransaction['TradeVolume'], |
| | |
| | | item["Side"] = "2" |
| | | self.l2_data_upload_manager.add_l2_order_detail(item, 0, True) |
| | | else: |
| | | if abs(pTransaction['TradePrice'] - limit_up_price) < 0.201: |
| | | # 涨停价 |
| | | # 成交 |
| | | 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()} |
| | | # 暂时注释掉同1单号至多上传1次 |
| | | # key = f"{item['SecurityID']}_{item['TradePrice']}_{item['BuyNo']}" |
| | | # if self.__last_transaction_keys_dict.get(code) == key: |
| | | # return |
| | | # self.__last_transaction_keys_dict[code] = key |
| | | # print("逐笔成交", item) |
| | | self.l2_data_upload_manager.add_transaction_detail(item) |
| | | # if abs(pTransaction['TradePrice'] - limit_up_price) < 0.201: |
| | | # 涨停价 |
| | | # 成交 |
| | | 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()} |
| | | # 暂时注释掉同1单号至多上传1次 |
| | | # key = f"{item['SecurityID']}_{item['TradePrice']}_{item['BuyNo']}" |
| | | # if self.__last_transaction_keys_dict.get(code) == key: |
| | | # return |
| | | # self.__last_transaction_keys_dict[code] = key |
| | | # print("逐笔成交", item) |
| | | self.l2_data_upload_manager.add_transaction_detail(item) |
| | | |
| | | def OnRtnOrderDetail(self, pOrderDetail): |
| | | can_listen = False |
| | | code = str(pOrderDetail['SecurityID']) |
| | | start_time = 0 |
| | | if code in self.special_code_volume_for_order_dict: |
| | | start_time = time.time() |
| | | if self.special_code_volume_for_order_dict[code][0] == pOrderDetail[ |
| | | 'Volume'] or constant.SHADOW_ORDER_VOLUME == pOrderDetail['Volume']: |
| | | # 监控目标订单与影子订单 |
| | | if self.special_code_volume_for_order_dict[code][1] > time.time(): |
| | | # 特殊量监听 |
| | | can_listen = True |
| | | else: |
| | | self.special_code_volume_for_order_dict.pop(code) |
| | | if not can_listen: |
| | | min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code) |
| | | if min_volume is None: |
| | | # 默认筛选50w |
| | | if pOrderDetail['Price'] * pOrderDetail['Volume'] < 500000: |
| | | return |
| | | elif pOrderDetail['Volume'] < min_volume: |
| | | return |
| | | # can_listen = False |
| | | # code = str(pOrderDetail['SecurityID']) |
| | | # start_time = 0 |
| | | # if code in self.special_code_volume_for_order_dict: |
| | | # start_time = time.time() |
| | | # if self.special_code_volume_for_order_dict[code][0] == pOrderDetail[ |
| | | # 'Volume'] or constant.SHADOW_ORDER_VOLUME == pOrderDetail['Volume']: |
| | | # # 监控目标订单与影子订单 |
| | | # if self.special_code_volume_for_order_dict[code][1] > time.time(): |
| | | # # 特殊量监听 |
| | | # can_listen = True |
| | | # else: |
| | | # self.special_code_volume_for_order_dict.pop(code) |
| | | # if not can_listen: |
| | | # min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code) |
| | | # if min_volume is None: |
| | | # # 默认筛选50w |
| | | # if pOrderDetail['Price'] * pOrderDetail['Volume'] < 500000: |
| | | # return |
| | | # elif pOrderDetail['Volume'] < min_volume: |
| | | # return |
| | | # 输出逐笔委托数据 |
| | | # 上证OrderStatus=b"D"表示撤单 |
| | | item = {"SecurityID": pOrderDetail['SecurityID'], "Price": pOrderDetail['Price'], |
| | |
| | | "OrderTime": pOrderDetail['OrderTime'], "MainSeq": pOrderDetail['MainSeq'], |
| | | "SubSeq": pOrderDetail['SubSeq'], "OrderNO": pOrderDetail['OrderNO'], |
| | | "OrderStatus": pOrderDetail['OrderStatus'].decode()} |
| | | self.l2_data_upload_manager.add_l2_order_detail(item, start_time) |
| | | self.l2_data_upload_manager.add_l2_order_detail(item, 0) |
| | | |
| | | def OnRtnBondMarketData(self, pDepthMarketData, FirstLevelBuyNum, FirstLevelBuyOrderVolumes, FirstLevelSellNum, |
| | | FirstLevelSellOrderVolumes): |