Administrator
2023-10-20 1772431bd0578e706d91a4c92ecbab78bda55dfb
影子订单委托价格重新定义
8个文件已修改
55 ■■■■■ 已修改文件
huaxin_client/trade_client.py 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_api.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api_server.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_data_update.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/trade_huaxin.py 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/tool.py 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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, need_shadedow_order = True):
    def buy(self, code, count, price, sinfo, order_ref, shadow_price = None):
        if not ENABLE_ORDER:
            return
        if sinfo in self.__buy_sinfo_set:
@@ -158,6 +158,7 @@
        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,
@@ -165,12 +166,11 @@
                    'utf-8'))
        async_log_util.info(logger_trade, f"{code}华鑫本地真实下单结束")
        # --------------------------------影子订单--------------------------------
        if need_shadedow_order:
        if shadow_price:
            if order_ref:
                # 下一个影子订单
                shadow_order_ref = order_ref + 1
                shadow_sinfo = f"s_b_{order_ref}"
                shadow_price = tool.get_buy_min_price(price)
                req_field.LimitPrice = shadow_price
                req_field.SInfo = shadow_sinfo
                req_field.OrderRef = shadow_order_ref
@@ -873,6 +873,7 @@
            price = data["price"]
            sinfo = data["sinfo"]
            order_ref = data.get("order_ref")
            shadow_price = data.get("shadow_price")
            if direction == 1:
                async_log_util.info(logger_trade, f"{code}华鑫本地开始下单")
@@ -881,7 +882,7 @@
                    req_rid_dict[sinfo] = (client_id, request_id, sk, order_ref)
                    # threading.Thread(target=lambda: self.__tradeSimpleApi.buy(code, volume, price, sinfo, order_ref),
                    #                  daemon=True).start()
                    self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, price, sinfo, order_ref)
                    self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, price, sinfo, order_ref, shadow_price)
                    async_log_util.info(logger_trade, f"{code}华鑫本地下单线程结束")
                except Exception as e:
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -16,10 +16,10 @@
# 下单
def place_order(code, price, volume, data, order_ref):
def place_order(code, price, volume, data, order_ref, shadow_price):
    async_log_util.info(logger_real_place_order_position,
                        f"下单:code-{code} price-{price} volume-{volume} exec-index-{data['index']} order_ref-{order_ref}")
    _place_order_info_dict[code] = (price, volume, data, time.time(), order_ref)
                        f"下单:code-{code} price-{price} shadow_price-{shadow_price} volume-{volume} exec-index-{data['index']} order_ref-{order_ref}")
    _place_order_info_dict[code] = (price, volume, data, time.time(), order_ref, shadow_price)
# 获取下单信息
@@ -43,6 +43,7 @@
    volume = order_info[1]
    exec_data = order_info[2]
    order_ref = order_info[4]
    shadow_price = order_info[5]
    # 获取量
    is_sz = code.startswith("00")
    # 提交到交易所的时间预估
@@ -55,7 +56,7 @@
        # 判断影子订单位置
        if val["num"] != huaxin_client_constant.SHADOW_ORDER_VOLUME // 100:
            continue
        if abs(tool.get_buy_min_price(limit_up_price) - float(val["price"])) >= 0.01:
        if abs(shadow_price - float(val["price"])) >= 0.01:
            continue
        if d["index"] <= exec_data["index"]:
            continue
third_data/kpl_api.py
@@ -133,4 +133,4 @@
if __name__ == "__main__":
    getCodeJingXuanBlocks("002316")
    print(getLimitUpInfo())
trade/huaxin/huaxin_trade_api.py
@@ -74,8 +74,7 @@
                                # 获取涨停价
                                limit_up_price = gpcode_manager.get_limit_up_price(code)
                                if limit_up_price and volume == huaxin_client_constant.SHADOW_ORDER_VOLUME:
                                    shadow_price = tool.get_buy_min_price(float(limit_up_price))
                                    if abs(float(limitPrice) - float(shadow_price)) < 0.01:
                                    if abs(float(limitPrice) - float(limit_up_price)) >= 0.01:
                                        is_shadow_order = True
                                order = HuaxinOrderEntity(code, orderStatus, orderRef, accountID, orderSysID,
@@ -91,7 +90,7 @@
                                if not is_shadow_order:
                                    # 订单相关回调
                                    # 重新请求委托列表与资金
                                    huaxin_trade_data_update.add_delegate_list("来自交易管道")
                                    # huaxin_trade_data_update.add_delegate_list("来自交易管道")
                                    huaxin_trade_data_update.add_deal_list()
                                    huaxin_trade_data_update.add_money_list()
                            # print("响应结果:", data_json['data'])
@@ -349,7 +348,7 @@
# price:价格(如果是卖时不传价格就按照5挡价卖)
# blocking是否阻塞进程
def order(direction, code, volume, price, price_type=2, blocking=False, sinfo=None, request_id=None,
          order_ref=None):
          order_ref=None, shadow_price=None):
    timestamp = round(time.time() * 1000)
    if not sinfo:
        sinfo = f"b_{code}_{timestamp}"
@@ -362,7 +361,8 @@
                            "order_ref": order_ref,
                            "volume": volume,
                            "price_type": price_type,
                            "price": price, "sinfo": sinfo}, request_id=request_id, blocking=blocking,
                            "price": price, "shadow_price": shadow_price, "sinfo": sinfo}, request_id=request_id,
                           blocking=blocking,
                           is_pipe=is_pipe_channel_normal())
    try:
        if blocking:
trade/huaxin/huaxin_trade_api_server.py
@@ -449,6 +449,7 @@
                        try:
                            limit_up_data_str = kpl_api.getLimitUpInfo()
                            limit_up_datas = json.loads(limit_up_data_str)
                            limit_up_datas = limit_up_datas["list"]
                            for d in limit_up_datas:
                                code = d[0]
                                if code in codes:
trade/huaxin/huaxin_trade_data_update.py
@@ -56,8 +56,8 @@
                                    is_shadow_order = False
                                    limit_up_price = gpcode_manager.get_limit_up_price_cache(code)
                                    if limit_up_price and volume == huaxin_client_constant.SHADOW_ORDER_VOLUME:
                                        shadow_price = tool.get_buy_min_price(float(limit_up_price))
                                        if abs(float(limitPrice) - float(shadow_price)) < 0.01:
                                        if abs(float(limitPrice) - float(limit_up_price)) >= 0.01:
                                            is_shadow_order = True
                                    if is_shadow_order:
                                        continue
trade/trade_huaxin.py
@@ -40,14 +40,17 @@
        if code.find("00") != 0 and code.find("60") != 0:
            raise Exception("只支持00开头与60开头的代码下单")
        # 保存下单信息
        huaxin.huaxin_delegate_postion_manager.place_order(code, price, count, last_data, order_ref)
        shadow_price = tool.get_shadow_price(price)
        huaxin.huaxin_delegate_postion_manager.place_order(code, price, count, last_data, order_ref,
                                                           shadow_price=shadow_price)
        if not constant.TRADE_ENABLE:
            return
        result = None
        blocking = False
        try:
            async_log_util.info(logger_trade, f"{code}下单开始")
            result = huaxin_trade_api.order(1, code, count, price, blocking=blocking, order_ref=order_ref)
            result = huaxin_trade_api.order(1, code, count, price, blocking=blocking, order_ref=order_ref,
                                            shadow_price=shadow_price)
            async_log_util.info(logger_trade, f"{code}下单结束")
        except Exception as e:
            if str(e).find("超时") >= 0:
utils/tool.py
@@ -222,8 +222,18 @@
    return max(price1, price2)
# 获取买入价格笼子的最低价
def get_shadow_price(price):
    fprice = round((100 - random.randint(2, 10)) * price / 100, 2)
    if price - 0.1 < fprice:
        fprice = price - 0.1
    return round(fprice, 2)
if __name__ == "__main__":
    print(get_buy_min_price(20))
    print(get_shadow_price(20))
    print(get_shadow_price(20))
    print(get_shadow_price(20))
    # print(trade_time_sub("11:29:59", 5))
    # print(trade_time_sub("10:29:59", 10))
    # print(trade_time_add_second("13:29:59", 60))
@@ -264,3 +274,4 @@
    except:
        pass
    return None