Administrator
2023-10-13 77aca8775ba39db7dcfeb806de7f0d6337fed8fb
测试影子订单
5个文件已修改
113 ■■■■■ 已修改文件
huaxin_client/constant.py 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client.py 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/trade_client.py 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/l2_huaxin_util.py 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/constant.py
@@ -6,4 +6,6 @@
TEST = True
L1_MIN_RATE = 4.0
L2_CODES_INFO_PATH = "/home/userzjj/logs/l2_codes.txt"
# 影子订单的量
SHADOW_ORDER_VOLUME = 100
huaxin_client/l2_client.py
@@ -357,13 +357,14 @@
    def OnRtnOrderDetail(self, pOrderDetail):
        can_listen = False
        code = str(pOrderDetail['SecurityID'])
        if code in self.special_code_volume_for_order_dict and self.special_code_volume_for_order_dict[code][0] == \
                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 code in self.special_code_volume_for_order_dict:
            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:
            # 暂时注释掉G撤相关数据产生
            # if pOrderDetail['OrderStatus'] == b'D':
huaxin_client/trade_client.py
@@ -92,7 +92,7 @@
        cls.__front_id = front_id
    # sinfo char(32)
    def buy(self, code, count, price, sinfo, order_ref):
    def buy(self, code, count, price, sinfo, order_ref, need_shadedow_order = True):
        if not ENABLE_ORDER:
            return
        if sinfo in self.__buy_sinfo_set:
@@ -154,28 +154,37 @@
        '''
        # 给L2发送消息
        ret = api.ReqOrderInsert(req_field, self.req_id)
        if ret != 0:
            raise Exception('ReqOrderInsert fail, ret[%d]' % ret)
        if queue_trade_w_l2_r is not None:
            queue_trade_w_l2_r.put_nowait(
                json.dumps({"type": "listen_volume", "data": {"code": code,
                                                              "volume": count}}).encode(
                    'utf-8'))
        async_log_util.info(logger_trade, f"{code}华鑫本地真实下单结束")
        # --------------------------------影子订单--------------------------------
        if order_ref:
            # 下一个影子订单
            shadow_order_ref = order_ref + 1
            shadow_sinfo = f"s_b_{order_ref}"
            shadow_price = price - 0.05
            req_field.LimitPrice = shadow_price
            req_field.SInfo = shadow_sinfo
            req_field.OrderRef = shadow_order_ref
            ret = api.ReqOrderInsert(req_field, self.req_id)
            if ret != 0:
                raise Exception('ReqOrderInsert fail, ret[%d]' % ret)
            # 影子订单撤单
            # 撤掉影子单
            shadow_cancel_order_ref = shadow_order_ref + 1
            self.cancel_buy(code, f"s_c_{shadow_order_ref}", order_sys_id=None,
                            order_ref=shadow_order_ref,
                            order_action_ref=shadow_cancel_order_ref, delay_s=0.05)
        if need_shadedow_order:
            if order_ref:
                # 下一个影子订单
                shadow_order_ref = order_ref + 1
                shadow_sinfo = f"s_b_{order_ref}"
                shadow_price = price - 0.05
                req_field.LimitPrice = shadow_price
                req_field.SInfo = shadow_sinfo
                req_field.OrderRef = shadow_order_ref
                req_field.VolumeTotalOriginal = constant.SHADOW_ORDER_VOLUME
                self.req_id += 1
                ret = api.ReqOrderInsert(req_field, self.req_id)
                if ret != 0:
                    raise Exception('ReqOrderInsert fail, ret[%d]' % ret)
                # 影子订单撤单
                # 撤掉影子单
                shadow_cancel_order_ref = shadow_order_ref + 1
                self.cancel_buy(code, f"s_c_{shadow_order_ref}", order_sys_id=None,
                                order_ref=shadow_order_ref,
                                order_action_ref=shadow_cancel_order_ref, delay_s=0.05)
        return ret
@@ -643,11 +652,12 @@
                                   pOrderField.LimitPrice, pOrderField.VolumeTotalOriginal, pOrderField.OrderSysID,
                                   pOrderField.OrderStatus, pOrderField.InsertTime))
            if pOrderField.OrderStatus == traderapi.TORA_TSTP_OST_Unknown:
                if queue_trade_w_l2_r is not None:
                    queue_trade_w_l2_r.put_nowait(
                        json.dumps({"type": "listen_volume", "data": {"code": pOrderField.SecurityID,
                                                                      "volume": pOrderField.VolumeTotalOriginal}}).encode(
                            'utf-8'))
                pass
            #     if queue_trade_w_l2_r is not None:
            #         queue_trade_w_l2_r.put_nowait(
            #             json.dumps({"type": "listen_volume", "data": {"code": pOrderField.SecurityID,
            #                                                           "volume": pOrderField.VolumeTotalOriginal}}).encode(
            #                 'utf-8'))
            else:
                order_data = {"sinfo": pOrderField.SInfo, "securityID": pOrderField.SecurityID,
                              "orderLocalID": pOrderField.OrderLocalID,
l2/cancel_buy_strategy.py
@@ -515,6 +515,10 @@
        # 守护30s以外的数据
        if time_space <= constant.H_CANCEL_START_TIME:
            return False, None
        if int(tool.get_now_time_str().replace(":", "")) > int("145000"):
            return False, None
        l2_log.cancel_debug(code, "H级是否需要撤单,数据范围:{}-{} ", start_index, end_index)
        # 监听的数据
        watch_index_set = self.__get_watch_index_set_cache(code)
@@ -837,11 +841,33 @@
    def compute_watch_index(self, code, start_index, end_index):
        total_datas = local_today_datas.get(code)
        if total_datas:
            # 计算的上截至位距离下截至位纯买额要小于2.5倍m值
            thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
            thresh_hold_money = int(thresh_hold_money * 2.5)
            threshold_num = thresh_hold_money // (float(gpcode_manager.get_limit_up_price(code)) * 100)
            # 统计净涨停买的数量
            total_num = 0
            re_start_index = start_index
            for j in range(end_index, start_index, -1):
                data = total_datas[j]
                val = data['val']
                if not L2DataUtil.is_limit_up_price_buy(val):
                    continue
                left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code,
                                                                                                         j,
                                                                                                         total_datas,
                                                                                                         local_today_canceled_buyno_map.get(
                                                                                                             code))
                if left_count > 0:
                    total_num += val['num']
                    if total_num >= threshold_num:
                        re_start_index = j - 1
            MIN_MONEYS = [300, 200, 100, 50]
            watch_indexes = set()
            MAX_COUNT = 5
            for min_money in MIN_MONEYS:
                for i in range(end_index, start_index, -1):
                for i in range(end_index, re_start_index, -1):
                    # if i > len(total_datas):
                    #     continue
                    try:
@@ -868,7 +894,7 @@
                    break
            if watch_indexes:
                self.__set_watch_indexes(code, watch_indexes)
                l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{start_index}-{end_index} 监听范围-{watch_indexes}")
                l2_log.l_cancel_debug(code, f"设置监听范围, 数据范围:{re_start_index}-{end_index} 监听范围-{watch_indexes}")
    # 设置真实下单位置
    def set_real_place_order_index(self, code, index, buy_single_index=None):
l2/huaxin/l2_huaxin_util.py
@@ -67,7 +67,7 @@
            item["limitPrice"] = "{}".format(limitPrice)
        operateType = item["operateType"]
        # 不需要非涨停买与买撤
        if int(item["limitPrice"]) != 1 and (int(operateType) == 0 or int(operateType) == 1):
        if int(item["limitPrice"]) != 1 and (int(operateType) == 0 or int(operateType) == 1) and num != 1:
            continue
        key = "{}-{}-{}".format(code, item["mainSeq"], item["subSeq"])
        if key in dataIndexs:
@@ -90,10 +90,10 @@
if __name__ == "__main__":
    ds =["('605167', 10.08, 68500, '1', '0', 9303108, 2, 439438, 436472, 'D', 1695864632451)",
         "('603439', 17.97, 27800, '1', '0', 9304966, 6, 435127, 407524, 'D', 1695864649883)",
         "('002369', 0.0, 100800, '1', '2', 93051880, 2011, 1431910, 1160638, 'D', 1695864651875)"
         ]
    ds = ["('605167', 10.08, 68500, '1', '0', 9303108, 2, 439438, 436472, 'D', 1695864632451)",
          "('603439', 17.97, 27800, '1', '0', 9304966, 6, 435127, 407524, 'D', 1695864649883)",
          "('002369', 0.0, 100800, '1', '2', 93051880, 2011, 1431910, 1160638, 'D', 1695864651875)"
          ]
    for d in ds:
        d = eval(d)
        print(__convert_order(d, 15.55))