Administrator
2024-03-11 6039ab8bc1cd3c016a6f870562c7101731070e7a
修改真实下单位计算/修改影子单价格
9个文件已修改
98 ■■■■■ 已修改文件
huaxin_client/l2_client.py 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_data_manager.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_util.py 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test.py 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api_server.py 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/tool.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
huaxin_client/l2_client.py
@@ -304,12 +304,6 @@
        # 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
            # 撤单
            item = {"SecurityID": pTransaction['SecurityID'], "Price": pTransaction['TradePrice'],
                    "Volume": pTransaction['TradeVolume'],
@@ -497,9 +491,9 @@
    g_SubMode = lev2mdapi.TORA_TSTP_MST_MCAST
    # case 1缓存模式
    # api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, True)
    api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, True)
    # case 2非缓存模式
    api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, False)
    # api = lev2mdapi.CTORATstpLev2MdApi_CreateTstpLev2MdApi(g_SubMode, False)
    global spi
    spi = Lev2MdSpi(api, l2_data_upload_manager)
    api.RegisterSpi(spi)
huaxin_client/l2_data_manager.py
@@ -92,10 +92,10 @@
        # queue_info[1].put_nowait(
        #     (data['SecurityID'], data['Price'], data['Volume'], data['Side'], data['OrderType'], data['OrderTime'],
        #      data['MainSeq'], data['SubSeq'], data['OrderNO'], data['OrderStatus'], time.time(), start_time))
        if data['Volume'] == 100:
            log_queue = self.temp_log_queue_dict.get(code)
            if log_queue:
                log_queue.put_nowait(data)
        # if data['Volume'] == 100:
        #     log_queue = self.temp_log_queue_dict.get(code)
        #     if log_queue:
        #         log_queue.put_nowait(data)
        q: collections.deque = self.temp_order_queue_dict.get(code)
        q.append((data['SecurityID'], data['Price'], data['Volume'], data['Side'], data['OrderType'], data['OrderTime'],
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -7,7 +7,7 @@
from l2 import l2_data_util
from l2.l2_data_util import L2DataUtil
from log_module import async_log_util
from log_module.log import hx_logger_trade_debug, logger_real_place_order_position
from log_module.log import hx_logger_trade_debug, logger_real_place_order_position, logger_debug
from trade.huaxin import huaxin_trade_record_manager
from utils import tool
@@ -28,7 +28,8 @@
    info = _place_order_info_dict.get(code)
    TIME_SPACE_THRESHHOD = 3 if code.find("00") == 0 else 20
    if info and time.time() - info[3] > TIME_SPACE_THRESHHOD:
        async_log_util.info(logger_real_place_order_position, "get_order_info 间隔{}s以上:code-{}",TIME_SPACE_THRESHHOD, code)
        async_log_util.info(logger_real_place_order_position, "get_order_info 间隔{}s以上:code-{}", TIME_SPACE_THRESHHOD,
                            code)
        # 间隔3s以上就无效了
        info = None
        _place_order_info_dict.pop(code)
@@ -41,8 +42,41 @@
# 计算预估下单位
def __compute_estimate_order_position(code, exec_buy_index):
def __compute_estimate_order_position(code, exec_buy_index, shadow_price):
    total_datas = l2_data_util.local_today_datas.get(code)
    try:
        if code.find("60") == 0:
            # 通过影子单买撤数据的订单号确认大致位置
            shadow_place_order_cancel_index = None
            for i in range(exec_buy_index, total_datas[-1]['index'] + 1):
                d = total_datas[i]
                val = d['val']
                # 判断影子订单位置
                if val["num"] != huaxin_client_constant.SHADOW_ORDER_VOLUME // 100:
                    continue
                if abs(shadow_price - float(val["price"])) >= 0.01:
                    continue
                if not L2DataUtil.is_buy_cancel(val):
                    continue
                shadow_place_order_cancel_index = d["index"]
            if shadow_place_order_cancel_index:
                async_log_util.info(logger_debug,
                                    f"{code} 执行位:{exec_buy_index} 获取到影子单的买撤:{shadow_place_order_cancel_index}")
                order_no = int(total_datas[shadow_place_order_cancel_index])
                for i in range(shadow_place_order_cancel_index, 0, -1):
                    d = total_datas[i]
                    val = d['val']
                    if not L2DataUtil.is_buy(val):
                        continue
                    if order_no > int(val['orderNo']) and abs(tool.trade_time_sub(val['time'], total_datas[
                        shadow_place_order_cancel_index]['val']["time"])) <= 1:
                        real_place_order_index = min(i + 1, total_datas[-1]['index'])
                        async_log_util.info(logger_debug,
                                            f"{code} 执行位:{exec_buy_index} 根据影子单的买撤获取真实下单位置:{real_place_order_index}")
                        return real_place_order_index
    except Exception as e:
        async_log_util.error(logger_debug, f"真实下单位置(影子单撤单)出错:{code} - {str(e)}")
    exec_data = total_datas[exec_buy_index]
    THRESH_MS = 20 if code.find('00') == 0 else 100
    for i in range(exec_buy_index, total_datas[-1]["index"]):
@@ -129,7 +163,7 @@
            real_place_index_info = real_place_index, RELIABILITY_TYPE_REAL
    elif tool.trade_time_sub(datas[-1]['val']['time'], exec_data['val']['time']) >= estimate_time_space:
        # 下单超过2s
        estimate_index = __compute_estimate_order_position(code, exec_data["index"])
        estimate_index = __compute_estimate_order_position(code, exec_data["index"], shadow_price)
        if estimate_index:
            real_place_index_info = estimate_index, RELIABILITY_TYPE_ESTIMATE
    if real_place_index_info:
l2/l2_data_util.py
@@ -429,10 +429,12 @@
        if int(val["operateType"]) != 1:
            return False
        price = float(val["price"])
        num = int(val["num"])
        # if price * num * 100 < 50 * 10000:
        #     return False
        return True
    @classmethod
    def is_buy_cancel(cls, val):
        if int(val["operateType"]) != 1:
            return False
        return True
    # 是否卖撤
test/test.py
@@ -31,7 +31,11 @@
if __name__ == "__main__":
    code = "000333"
    LCancelRateManager.set_block_limit_up_count(code, 100)
    LCancelRateManager.set_big_num_deal_rate(code, 10)
    print(LCancelRateManager.get_cancel_rate(code))
    q: queue.Queue = queue.Queue()
    while True:
        try:
            temp = q.get(timeout=10)
        except:
            time.sleep(0.02)
        finally:
            pass
third_data/code_plate_key_manager.py
@@ -99,9 +99,10 @@
                if price_rate > 0.07:
                    jx_blocks_info = self.get_jx_blocks_cache(code)
                    if not jx_blocks_info:
                        start_time = time.time()
                        blocks = kpl_api.getCodeBlocks(code)
                        self.save_jx_blocks(code, blocks, current_limit_up_blocks)
                        async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块-{blocks}")
                        async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块-{blocks}  耗时:{int(time.time() - start_time)}s")
                    else:
                        # 还没涨停的需要更新精选板块 更新精选板块
                        if abs(float(buy_1_price) - float(limit_up_price)) >= 0.001:
@@ -116,17 +117,19 @@
                                    UPDATE_TIME_SPACE = 5 * 60
                            if time.time() - jx_blocks_info[1] > UPDATE_TIME_SPACE:
                                start_time = time.time()
                                # 距离上次更新时间过去了5分钟
                                blocks = kpl_api.getCodeBlocks(code)
                                self.save_jx_blocks(code, blocks, current_limit_up_blocks)
                                async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(更新)-{blocks}")
                                async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(更新)-{blocks}  耗时:{int(time.time() - start_time)}s")
                elif price_rate > 0.03:
                    # 添加备用板块
                    if not self.get_jx_blocks_cache(code, by=True):
                        start_time = time.time()
                        blocks = kpl_api.getCodeBlocks(code)
                        self.save_jx_blocks(code, blocks, current_limit_up_blocks, by=True)
                        async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(备用)-{blocks}")
                        async_log_util.info(logger_kpl_block_can_buy, f"{code}:获取到精选板块(备用)-{blocks}  耗时:{int(time.time() - start_time)}s")
        except Exception as e:
            logger_kpl_block_can_buy.error(f"{code} 获取板块出错")
            logger_kpl_block_can_buy.exception(e)
trade/huaxin/huaxin_trade_api_server.py
@@ -460,7 +460,8 @@
                                limit_up_price = gpcode_manager.get_limit_up_price(d[0])
                                if limit_up_price:
                                    # 默认设置涨停,量为0
                                    datas.append((code, 0, float(limit_up_price), tool.get_shadow_price(float(limit_up_price)),100))
                                    datas.append((code, 0, float(limit_up_price),
                                                  tool.get_shadow_price(float(limit_up_price)), 100))
                        except Exception as e:
                            logger_l2_codes_subscript.exception(e)
                    if not datas:
trade/huaxin/huaxin_trade_server.py
@@ -1383,7 +1383,7 @@
                            total_datas = l2_data_util.local_today_datas.get(code)
                            trade_index, is_default = transaction_progress.TradeBuyQueue().get_traded_index(code)
                            if trade_index is None:
                                continue
                                trade_index = 0
                            # 下单位置
                            place_order_index = SecondCancelBigNumComputer().get_real_place_order_index_cache(code)
                            # 计算信号位置到真实下单位置的总买(不管是否已撤)
utils/tool.py
@@ -232,7 +232,7 @@
    # if price - 0.1 < fprice:
    #     fprice = price - 0.1
    # return round(fprice, 2)
    return round(get_buy_min_price(price), 2)
    return round(get_buy_min_price(price) - 0.03, 2)
if __name__ == "__main__":