| | |
| | | from l2.huaxin import l2_huaxin_util |
| | | from l2.l2_data_manager import OrderBeginPosInfo |
| | | from l2.l2_sell_manager import L2LimitUpSellManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | from log_module import async_log_util |
| | | from trade.deal_big_money_manager import DealOrderNoManager |
| | | from trade.sell.sell_rule_manager import TradeRuleManager |
| | |
| | | block_rate = rates[count] |
| | | |
| | | deal_rate = 0 |
| | | # if code in cls.__big_num_deal_rate_dict: |
| | | # temp_rate = cls.__big_num_deal_rate_dict[code] |
| | | if code in cls.__big_num_deal_rate_dict: |
| | | deal_rate =round( cls.__big_num_deal_rate_dict[code]/100) |
| | | # if temp_rate >= 1: |
| | | # if temp_rate > 3: |
| | | # temp_rate = 3 |
| | |
| | | for c in codes: |
| | | cls.__block_limit_up_count_dict[c] = len(codes) - 1 |
| | | |
| | | # 设置大单成交金额➗固定m值比例 |
| | | @classmethod |
| | | def set_big_num_deal_rate(cls, code, rate): |
| | | def set_big_num_deal_info(cls, code, buy_money, sell_money): |
| | | left_money_w = (buy_money-sell_money)//10000 |
| | | if left_money_w > 0: |
| | | rate = ((left_money_w+300)//900)*2 |
| | | else: |
| | | rate = ((left_money_w + 599) // 900) * 2 |
| | | if rate <-10: |
| | | rate = -10 |
| | | if rate > 10: |
| | | rate = 10 |
| | | cls.__big_num_deal_rate_dict[code] = rate |
| | | l2_log.l_cancel_debug(code, f"设置大单成交金额比值:{rate}") |
| | | |
| | | |
| | | @classmethod |
| | | def compute_big_num_deal_rate(cls, code): |
| | | total_datas = local_today_datas.get(code) |
| | | order_no_map = local_today_buyno_map.get(code) |
| | | # 获取成交大单手数 |
| | | total_deal_nums = DealOrderNoManager().get_deal_nums(code, order_no_map) |
| | | # 获取板上卖手数 |
| | | total_sell_nums = 0 |
| | | sell_indexs = L2LimitUpSellManager().get_limit_up_sell_indexes(code) |
| | | if sell_indexs: |
| | | for index in sell_indexs: |
| | | total_sell_nums += total_datas[int(index)]["val"]["num"] |
| | | l2_log.l_cancel_debug(code, f"大单买-{total_deal_nums} 板上卖-{total_sell_nums}") |
| | | total_deal_nums -= total_sell_nums |
| | | if total_deal_nums < 0: |
| | | total_deal_nums = 0 |
| | | thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price: |
| | | rate = round(total_deal_nums / (thresh_hold_money // (float(limit_up_price) * 100)), 2) |
| | | cls.set_big_num_deal_rate(code, rate) |
| | | def compute_big_num_deal_info(cls, code): |
| | | total_buy_money = BigOrderDealManager().get_total_buy_money(code) |
| | | total_sell_money = BigOrderDealManager().get_total_sell_money(code) |
| | | cls.set_big_num_deal_info(code, total_buy_money, total_sell_money) |
| | | |
| | | |
| | | # 计算成交位置之后的大单(特定笔数)的撤单比例 |
| | |
| | | |
| | | if not self.__is_l_down_can_cancel(code, buy_single_index): |
| | | # L后已经不能守护 |
| | | l2_log.l_cancel_debug(code, f"L后已经无法生效:buy_single_index-{buy_single_index}") |
| | | HourCancelBigNumComputer().start_compute_watch_indexes(code, buy_single_index) |
| | | |
| | | real_place_order_index_info = self.__real_place_order_index_dict.get(code) |
| | |
| | | need_find_by = True |
| | | for i in origin_watch_index_by: |
| | | if i >= start_index: |
| | | # 在成交位置之后 |
| | | # 只要有一个还没成交就不需要重新计算 |
| | | need_find_by = False |
| | | break |
| | | if need_find_by and (not is_default or not watch_indexes): |
| | |
| | | for i in range(THRESH_COUNT): |
| | | l2_log.g_cancel_debug(code, f"小单备用监听位置:{temp_list[i][1]['index']}") |
| | | watch_indexes.add(temp_list[i][1]["index"]) |
| | | self.__watch_indexes_by_dict[code] = origin_watch_index_by | watch_indexes |
| | | self.__watch_indexes_by_dict[code] = watch_indexes |
| | | |
| | | def set_trade_progress(self, code, buy_single_index, index): |
| | | if self.__trade_progress_index_dict.get(code) != index: |
| | |
| | | if watch_indexes_by is None: |
| | | watch_indexes_by = set() |
| | | need_compute = False |
| | | need_compute_by = False |
| | | for i in range(start_index, end_index + 1): |
| | | data = total_datas[i] |
| | | val = data["val"] |
| | |
| | | if buy_index is not None and buy_index < real_place_order_index and ( |
| | | buy_index in watch_indexes or buy_index in watch_indexes_by): |
| | | if buy_index in watch_indexes_by: |
| | | need_compute_by = True |
| | | break |
| | | # 备用撤单,直接撤 |
| | | return True, data, f"次大单撤:{buy_index}" |
| | | # return True, data, f"次大单撤:{buy_index}" |
| | | elif buy_index in watch_indexes: |
| | | # 大单撤需要重新计算大单撤单比例 |
| | | need_compute = True |
| | |
| | | canceled_indexes_list = list(canceled_indexes) |
| | | canceled_indexes_list.sort() |
| | | return True, total_datas[canceled_indexes_list[-1]], f"撤单比例:{cancel_rate}" |
| | | # 计算备用 |
| | | if need_compute_by and watch_indexes_by: |
| | | canceled_indexes = set() |
| | | for index in watch_indexes_by: |
| | | cancel_data = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_canceled_data_v2(code, index, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if cancel_data: |
| | | canceled_indexes.add(cancel_data["index"]) |
| | | cancel_rate = round(len(canceled_indexes) / len(watch_indexes_by), 2) |
| | | threshhold_rate = constant.G_CANCEL_RATE |
| | | situation = trade_manager.MarketSituationManager().get_situation_cache() |
| | | if situation == trade_manager.MarketSituationManager.SITUATION_GOOD: |
| | | threshhold_rate = constant.G_CANCEL_RATE_FOR_GOOD_MARKET |
| | | if cancel_rate > threshhold_rate: |
| | | canceled_indexes_list = list(canceled_indexes) |
| | | canceled_indexes_list.sort() |
| | | return True, total_datas[canceled_indexes_list[-1]], f"次大单撤单比例:{cancel_rate}" |
| | | |
| | | return False, None, "" |
| | | |
| | |
| | | cls.__L2LimitUpSellManager.add_limit_up_sell(code, d["index"]) |
| | | has_limit_up_sell = True |
| | | if has_limit_up_sell: |
| | | LCancelRateManager.compute_big_num_deal_rate(code) |
| | | LCancelRateManager.compute_big_num_deal_info(code) |
| | | # elif L2DataUtil.is_limit_up_price_sell_cancel(d["val"]): |
| | | # cls.__L2LimitUpSellManager.add_limit_up_sell(code, d["index"]) |
| | | except Exception as e: |
| | |
| | | from l2.l2_data_util import local_today_sellno_map, local_today_datas |
| | | from l2.place_order_single_data_manager import L2TradeSingleDataProcessor, L2TradeSingleDataManager |
| | | |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_l2_transaction_desc, hx_logger_l2_transaction_sell_order, hx_logger_l2_active_sell |
| | | from log_module import async_log_util, log_export |
| | | from log_module.log import hx_logger_l2_transaction_desc, hx_logger_l2_transaction_sell_order, hx_logger_l2_active_sell, \ |
| | | hx_logger_l2_transaction_big_buy_order, hx_logger_l2_transaction_big_sell_order |
| | | |
| | | from utils import tool |
| | | |
| | | |
| | | class BigOrderDealManager: |
| | | """ |
| | | 大单成交管理 |
| | | """ |
| | | __total_buy_datas_dict = {} |
| | | __total_sell_datas_dict = {} |
| | | __instance=None |
| | | |
| | | def __new__(cls, *args, **kwargs): |
| | | if not cls.__instance: |
| | | cls.__instance = super(BigOrderDealManager, cls).__new__(cls, *args, **kwargs) |
| | | cls.__load_datas() |
| | | return cls.__instance |
| | | |
| | | @classmethod |
| | | def __load_datas(cls): |
| | | # 从日志加载数据 |
| | | buy_order_map = log_export.load_huaxin_big_buy_order() |
| | | if buy_order_map: |
| | | for code in buy_order_map: |
| | | cls.__total_buy_datas_dict[code] = buy_order_map[code] |
| | | |
| | | sell_order_map = log_export.load_huaxin_big_sell_order() |
| | | if sell_order_map: |
| | | for code in sell_order_map: |
| | | cls.__total_sell_datas_dict[code] = sell_order_map[code] |
| | | |
| | | def add_buy_datas(self, code, datas): |
| | | """ |
| | | 添加大买单数据 |
| | | @param code: 代码 |
| | | @param datas:[(买单号,总股数,总成交额)] |
| | | @return: |
| | | """ |
| | | if not datas: |
| | | return |
| | | if code not in self.__total_buy_datas_dict: |
| | | self.__total_buy_datas_dict[code] = [] |
| | | self.__total_buy_datas_dict[code].extend(datas) |
| | | # 将数据保存到日志 |
| | | l2_log.info(code, hx_logger_l2_transaction_big_buy_order, f"{datas}") |
| | | |
| | | def add_sell_datas(self, code, datas): |
| | | """ |
| | | 添加大卖单数据 |
| | | @param code: 代码 |
| | | @param datas:[(卖单号,总股数,总成交额)] |
| | | @return: |
| | | """ |
| | | if not datas: |
| | | return |
| | | if code not in self.__total_sell_datas_dict: |
| | | self.__total_sell_datas_dict[code] = [] |
| | | self.__total_sell_datas_dict[code].extend(datas) |
| | | l2_log.info(code, hx_logger_l2_transaction_big_sell_order, f"{datas}") |
| | | |
| | | def get_total_buy_money(self, code): |
| | | """ |
| | | 获取总共的大单买金额 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code not in self.__total_buy_datas_dict: |
| | | return 0 |
| | | return int(sum([x[2] for x in self.__total_buy_datas_dict[code]])) |
| | | |
| | | def get_total_sell_money(self, code): |
| | | """ |
| | | 获取总共的大单卖金额 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code not in self.__total_sell_datas_dict: |
| | | return 0 |
| | | return int(sum([x[2] for x in self.__total_sell_datas_dict[code]])) |
| | | |
| | | |
| | | # 成交数据统计 |
| | |
| | | RedisUtils.setex(self.__get_redis(), f"dealing_order_info-{code}", tool.get_expire(), |
| | | json.dumps(self.__dealing_order_info_dict[code])) |
| | | |
| | | # 获取代码正在成交的信息 |
| | | # 返回数据:[订单号,总股数,开始成交时间,结束成交时间, 总买] |
| | | @classmethod |
| | | def get_dealing_order_info(cls, code): |
| | | """ |
| | | 获取当前正在成交的数据 |
| | | @param code: |
| | | @return: [买单号,总股数,总金额] |
| | | """ |
| | | return cls.__dealing_order_info_dict.get(code) |
| | | |
| | | # 统计成交的情况 |
| | | @classmethod |
| | | def statistic_deal_desc(cls, code, data, total_buy_num): |
| | | if code not in cls.__dealing_order_info_dict: |
| | | # 数据格式[订单号,总股数,开始成交时间,结束成交时间, 总买] |
| | | cls.__dealing_order_info_dict[code] = [data[6], 0, data[3], data[3], total_buy_num] |
| | | if cls.__dealing_order_info_dict[code][0] == data[6]: |
| | | # 成交同一个订单号 |
| | | cls.__dealing_order_info_dict[code][1] += data[2] |
| | | cls.__dealing_order_info_dict[code][3] = data[3] |
| | | else: |
| | | # 保存上一条数据 |
| | | async_log_util.info(hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}") |
| | | # 设置最近成交完成的一条数据 |
| | | deal_info = ( |
| | | cls.__dealing_order_info_dict[code][0], |
| | | cls.__dealing_order_info_dict[code][4] == cls.__dealing_order_info_dict[code][1]) |
| | | cls.__latest_deal_order_info_dict[code] = deal_info |
| | | # 初始化本条数据 |
| | | cls.__dealing_order_info_dict[code] = [data[6], data[2], data[3], data[3], total_buy_num] |
| | | return deal_info |
| | | return None |
| | | def statistic_big_buy_data(cls, code, datas): |
| | | """ |
| | | 统计大单买 |
| | | @param code: |
| | | @param datas: |
| | | @return: 返回数据里面成交的大单 |
| | | """ |
| | | big_buy_datas = [] |
| | | for data in datas: |
| | | # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | | # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], |
| | | # data['SellNo'], data['ExecType'])) |
| | | |
| | | if code not in cls.__dealing_order_info_dict: |
| | | # 数据格式[订单号,总股数,成交金额] |
| | | cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1]] |
| | | if cls.__dealing_order_info_dict[code][0] == data[6]: |
| | | # 成交同一个订单号 |
| | | cls.__dealing_order_info_dict[code][1] += data[2] |
| | | cls.__dealing_order_info_dict[code][2] += data[2] * data[1] |
| | | else: |
| | | # 保存上一条数据 |
| | | async_log_util.info(hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}") |
| | | # 设置最近成交完成的一条数据 |
| | | deal_info = cls.__dealing_order_info_dict[code] |
| | | cls.__latest_deal_order_info_dict[code] = deal_info |
| | | # 是否为大买单 |
| | | if deal_info[2] >= 2990000: |
| | | big_buy_datas.append(deal_info) |
| | | # 初始化本条数据 |
| | | cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1]] |
| | | return big_buy_datas |
| | | |
| | | |
| | | # 卖单统计数据 |
| | |
| | | |
| | | __last_trade_data_dict = {} |
| | | |
| | | # 用来暂时存放统计结果 |
| | | __dealing_order_info_dict = {} |
| | | |
| | | @classmethod |
| | | def statistic_big_sell_data(cls, code, datas): |
| | | """ |
| | | 统计大卖单 |
| | | @param code: |
| | | @param datas: |
| | | @return: 返回数据里面成交的大单 |
| | | """ |
| | | big_sell_datas = [] |
| | | for data in datas: |
| | | # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | | # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], |
| | | # data['SellNo'], data['ExecType'])) |
| | | if code not in cls.__dealing_order_info_dict: |
| | | # 数据格式[订单号,总股数,成交金额] |
| | | cls.__dealing_order_info_dict[code] = [data[7], data[2], data[2] * data[1]] |
| | | if cls.__dealing_order_info_dict[code][0] == data[7]: |
| | | # 成交同一个订单号 |
| | | cls.__dealing_order_info_dict[code][1] += data[2] |
| | | cls.__dealing_order_info_dict[code][2] += data[2] * data[1] |
| | | else: |
| | | # 保存上一条数据 |
| | | async_log_util.info(hx_logger_l2_transaction_desc, f"{code}#{cls.__dealing_order_info_dict[code]}") |
| | | # 设置最近成交完成的一条数据 |
| | | deal_info = cls.__dealing_order_info_dict[code] |
| | | # 是否为大买单 |
| | | if deal_info[2] >= 2990000: |
| | | big_sell_datas.append(deal_info) |
| | | # 初始化本条数据 |
| | | cls.__dealing_order_info_dict[code] = [data[7], data[2], data[2] * data[1]] |
| | | return big_sell_datas |
| | | |
| | | # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...]) |
| | | @classmethod |
| | | def add_transaction_datas(cls, code, datas, limit_up_price=None): |
| | |
| | | import logging |
| | | import time |
| | | |
| | | import constant |
| | | from code_attribute import gpcode_manager |
| | | from l2 import l2_data_util, l2_data_manager, transaction_progress |
| | | from l2.cancel_buy_strategy import FCancelBigNumComputer, LCancelBigNumComputer, LCancelRateManager, \ |
| | | GCancelBigNumComputer, SCancelBigNumComputer, HourCancelBigNumComputer |
| | | from l2.l2_data_manager_new import L2TradeDataProcessor |
| | | from l2.l2_data_util import L2DataUtil |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_l2_debug, logger_l2_trade_buy_queue, logger_debug, hx_logger_l2_upload |
| | | from trade import current_price_process_manager |
| | | from trade.deal_big_money_manager import DealOrderNoManager |
| | | import concurrent.futures |
| | | |
| | | |
| | | class HuaXinTransactionDatasProcessor: |
| | | __statistic_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=constant.HUAXIN_L2_MAX_CODES_COUNT + 2) |
| | | __TradeBuyQueue = transaction_progress.TradeBuyQueue() |
| | | |
| | | # 计算成交进度 |
| | |
| | | buy_progress_index = buyno_map[buy_no]["index"] |
| | | break |
| | | return buy_progress_index |
| | | |
| | | @classmethod |
| | | def statistic_big_order_infos(cls, code, datas): |
| | | """ |
| | | 统计大单成交 |
| | | @param code: |
| | | @param datas: |
| | | @return: |
| | | """ |
| | | buy_datas = HuaXinBuyOrderManager.statistic_big_buy_data(code, datas) |
| | | if buy_datas: |
| | | BigOrderDealManager().add_buy_datas(code, buy_datas) |
| | | |
| | | sell_datas = HuaXinSellOrderStatisticManager.statistic_big_sell_data(code, datas) |
| | | if sell_datas: |
| | | BigOrderDealManager().add_sell_datas(code, sell_datas) |
| | | |
| | | if buy_datas or sell_datas: |
| | | buy_money = BigOrderDealManager().get_total_buy_money(code) |
| | | sell_money = BigOrderDealManager().get_total_sell_money(code) |
| | | LCancelRateManager.set_big_num_deal_info(code, buy_money, sell_money) |
| | | |
| | | @classmethod |
| | | def process_huaxin_transaction_datas(cls, code, datas): |
| | |
| | | |
| | | _start_time = time.time() |
| | | # 计算已经成交的大单 |
| | | big_money_count = 0 |
| | | for d in datas: |
| | | data = buyno_map.get(f"{d[6]}") |
| | | buy_num = None |
| | | if data: |
| | | buy_num = data["val"]["num"] * 100 |
| | | # 统计成交单 |
| | | deal_info = HuaXinBuyOrderManager.statistic_deal_desc(code, d, buy_num) |
| | | if deal_info and deal_info[1]: |
| | | data = buyno_map.get(f"{deal_info[0]}") |
| | | print("已经成交索引:", data["index"]) |
| | | val = data["val"] |
| | | if l2_data_util.is_big_money(val) and L2DataUtil.is_limit_up_price_buy(val): |
| | | big_money_count += 1 |
| | | DealOrderNoManager().add_orderno(code, f"{deal_info[0]}") |
| | | # L后是否有成交,如果有成交就需要除去当前笔数,然后重新囊括一笔 |
| | | # 暂时不需要这种复杂的机制 |
| | | # LCancelBigNumComputer().add_deal_index(code, data["index"], order_begin_pos.buy_single_index) |
| | | # big_money_count = 0 |
| | | # for d in datas: |
| | | # data = buyno_map.get(f"{d[6]}") |
| | | # buy_num = None |
| | | # if data: |
| | | # buy_num = data["val"]["num"] * 100 |
| | | # # 统计成交单 |
| | | # deal_info = HuaXinBuyOrderManager.statistic_deal_desc(code, d, buy_num) |
| | | # if deal_info and deal_info[1]: |
| | | # data = buyno_map.get(f"{deal_info[0]}") |
| | | # print("已经成交索引:", data["index"]) |
| | | # val = data["val"] |
| | | # if l2_data_util.is_big_money(val) and L2DataUtil.is_limit_up_price_buy(val): |
| | | # big_money_count += 1 |
| | | # DealOrderNoManager().add_orderno(code, f"{deal_info[0]}") |
| | | # # L后是否有成交,如果有成交就需要除去当前笔数,然后重新囊括一笔 |
| | | # # 暂时不需要这种复杂的机制 |
| | | # # LCancelBigNumComputer().add_deal_index(code, data["index"], order_begin_pos.buy_single_index) |
| | | cls.__statistic_thread_pool.submit(cls.statistic_big_order_infos, code, datas) |
| | | |
| | | use_time_list.append(("统计买单数据", time.time() - _start_time)) |
| | | _start_time = time.time() |
| | | if big_money_count > 0: |
| | | LCancelRateManager.compute_big_num_deal_rate(code) |
| | | # if big_money_count > 0: |
| | | # LCancelRateManager.compute_big_num_deal_rate(code) |
| | | |
| | | buy_progress_index = cls.__compute_latest_trade_progress(code, buyno_map, datas) |
| | | |
| | |
| | | logger.add(self.get_hx_path("l2", "transaction_desc"), |
| | | filter=lambda record: record["extra"].get("name") == "hx_l2_transaction_desc", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_hx_path("l2", "l2_transaction_big_buy"), |
| | | filter=lambda record: record["extra"].get("name") == "hx_l2_transaction_big_buy", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_hx_path("l2", "l2_transaction_big_sell"), |
| | | filter=lambda record: record["extra"].get("name") == "hx_l2_transaction_big_sell", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | | |
| | | logger.add(self.get_hx_path("l2", "orderdetail"), |
| | | filter=lambda record: record["extra"].get("name") == "hx_l2_orderdetail", |
| | | rotation="00:00", compression="zip", enqueue=True) |
| | |
| | | logger_l2_market_sell = __mylogger.get_logger("l2_market_sell") |
| | | logger_l2_not_buy_reasons = __mylogger.get_logger("l2_not_buy_reasons") |
| | | |
| | | |
| | | |
| | | logger_l2_trade = __mylogger.get_logger("l2_trade") |
| | | logger_l2_trade_cancel = __mylogger.get_logger("l2_trade_cancel") |
| | | logger_l2_s_cancel = __mylogger.get_logger("s_cancel") |
| | |
| | | logger_real_place_order_position = __mylogger.get_logger("l2_real_place_order_position") |
| | | # 代码订阅日志 |
| | | logger_l2_codes_subscript = __mylogger.get_logger("l2_codes_subscript") |
| | | |
| | | |
| | | logger_l2_big_data = __mylogger.get_logger("l2_big_data") |
| | | logger_juejin_tick = __mylogger.get_logger("juejin_tick") |
| | |
| | | hx_logger_l2_transaction = __mylogger.get_logger("hx_l2_transaction") |
| | | hx_logger_l2_transaction_sell_order = __mylogger.get_logger("hx_l2_transaction_sell_order") |
| | | hx_logger_l2_transaction_desc = __mylogger.get_logger("hx_l2_transaction_desc") |
| | | hx_logger_l2_transaction_big_buy_order = __mylogger.get_logger("hx_l2_transaction_big_buy") |
| | | hx_logger_l2_transaction_big_sell_order = __mylogger.get_logger("hx_l2_transaction_big_sell") |
| | | hx_logger_l2_market_data = __mylogger.get_logger("hx_l2_market_data") |
| | | hx_logger_l2_upload = __mylogger.get_logger("hx_l2_upload") |
| | | hx_logger_l2_debug = __mylogger.get_logger("hx_l2_debug") |
| | |
| | | logger_local_huaxin_l2_special_volume = __mylogger.get_logger("local_huaxin_l2_special_volume") |
| | | |
| | | |
| | | |
| | | def close_print(): |
| | | logging.basicConfig(level=logging.ERROR) |
| | | if not constant.is_windows(): |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | open_limit_up_codes = set({"000333","000222"}) |
| | | open_limit_up_codes = set({"000333", "000222"}) |
| | | logger_kpl_open_limit_up.info(f"炸板代码:{open_limit_up_codes}") |
| | |
| | | return fdatas |
| | | |
| | | |
| | | def load_huaxin_big_buy_order(date=tool.get_now_date_str()): |
| | | """ |
| | | 加载华鑫大买单 |
| | | @param date: |
| | | @return: |
| | | """ |
| | | path = f"{constant.get_path_prefix()}/logs/huaxin/l2/l2_transaction_big_buy.{date}.log" |
| | | fdatas = {} |
| | | lines = __load_file_content(path) |
| | | for line in lines: |
| | | if line: |
| | | try: |
| | | data = line.split(" - ")[1].strip() |
| | | if data.startswith("["): |
| | | time_str = data[data.find("[") + 1:data.find("]")].strip() |
| | | data = data[data.find("]") + 1:].strip() |
| | | |
| | | data = data.split("code=")[1].strip() |
| | | code = data[:data.find(" ")].strip() |
| | | data = data[data.find(" "):].strip() |
| | | data = eval(data) |
| | | if code not in fdatas: |
| | | fdatas[code] = [] |
| | | fdatas[code].extend(data) |
| | | except: |
| | | pass |
| | | return fdatas |
| | | |
| | | |
| | | def load_huaxin_big_sell_order(date=tool.get_now_date_str()): |
| | | """ |
| | | 加载华鑫大买单 |
| | | @param date: |
| | | @return: |
| | | """ |
| | | path = f"{constant.get_path_prefix()}/logs/huaxin/l2/l2_transaction_big_sell.{date}.log" |
| | | fdatas = {} |
| | | lines = __load_file_content(path) |
| | | for line in lines: |
| | | if line: |
| | | try: |
| | | data = line.split(" - ")[1].strip() |
| | | if data.startswith("["): |
| | | time_str = data[data.find("[") + 1:data.find("]")].strip() |
| | | data = data[data.find("]") + 1:].strip() |
| | | |
| | | data = data.split("code=")[1].strip() |
| | | code = data[:data.find(" ")].strip() |
| | | data = data[data.find(" "):].strip() |
| | | data = eval(data) |
| | | if code not in fdatas: |
| | | fdatas[code] = [] |
| | | fdatas[code].extend(data) |
| | | except: |
| | | pass |
| | | return fdatas |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | fdatas = load_huaxin_active_sell_map() |
| | | fdatas = load_huaxin_big_buy_order() |
| | | print(len(fdatas)) |
| | | # print(get_h_cancel_compute_info("603912")) |
| | | |
| | |
| | | import multiprocessing |
| | | import queue |
| | | import time |
| | | |
| | | from l2.cancel_buy_strategy import LCancelRateManager |
| | | |
| | | __queue = queue.Queue() |
| | | |
| | | |
| | | def add_data(msg): |
| | | time.sleep(1) |
| | | start_time = time.time() |
| | | __queue.put({"msg": msg}) |
| | | end_time = time.time() |
| | | if end_time - start_time > 0.002: |
| | | print("加入日志耗时") |
| | | |
| | | |
| | | def test_process_1(pipe): |
| | | while True: |
| | | for i in range(10): |
| | | pipe.send_bytes(f"hello world:{i}".encode("utf-8")) |
| | | time.sleep(1) |
| | | |
| | | |
| | | def test_process_2(pipe): |
| | | while True: |
| | | results = pipe.recv_bytes() |
| | | if results: |
| | | print("接受到内容:", results) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | q: queue.Queue = queue.Queue() |
| | | while True: |
| | | try: |
| | | temp = q.get(timeout=10) |
| | | except: |
| | | time.sleep(0.02) |
| | | finally: |
| | | pass |
| | | left_money_w = -3900 |
| | | for w in [-3900, -3600, -3300,-3000, -2700, -2400,-2100,-900,3900,3900,4200,4500]: |
| | | if w > 0: |
| | | rate = ((w + 300) // 900) * 2 |
| | | else: |
| | | rate = ((w + 599) // 900) * 2 |
| | | if rate < -10: |
| | | rate = -10 |
| | | if rate > 10: |
| | | rate = 10 |
| | | print(w, rate) |
| | |
| | | from l2.huaxin import l2_huaxin_util |
| | | from l2.l2_data_manager import OrderBeginPosInfo |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | from l2 import l2_data_util, cancel_buy_strategy |
| | | from l2.l2_transaction_data_processor import HuaXinTransactionDatasProcessor |
| | | from l2.place_order_single_data_manager import L2TradeSingleDataProcessor |
| | | from log_module import log_export, async_log_util |
| | | from utils import tool |
| | |
| | | |
| | | def test_process_transaction_datas(): |
| | | data_map = log_export.load_huaxin_transaction_map(date="2024-04-17") |
| | | code = "002376" |
| | | code = "000035" |
| | | datas = data_map.get(code) |
| | | l2_data_util.load_l2_data(code) |
| | | |
| | | L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell(code, {"val": {"orderNo": 123123}, "index": 123}) |
| | | |
| | | for data in datas: |
| | | L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, data, 5.78) |
| | | HuaXinTransactionDatasProcessor.statistic_big_order_infos(code, data) |
| | | |
| | | async_log_util.run_sync() |
| | | |
| | | # L2TradeSingleDataProcessor.add_l2_delegate_limit_up_sell(code, {"val": {"orderNo": 123123}, "index": 123}) |
| | | # |
| | | # for data in datas: |
| | | # L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, data, 5.78) |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | |
| | | # if real_order_time_ms: |
| | | # if tool.trade_time_sub_with_ms(deal_time, real_order_time_ms) >= 0: |
| | | # print("123123") |
| | | test_process_transaction_datas() |
| | | # test_process_transaction_datas() |
| | | # BigOrderDealManager() |
| | | pass |
| | | |
| | |
| | | |
| | | @classmethod |
| | | def trading_order_canceled(cls, code, order_no): |
| | | is_normal = l2_data_util.load_l2_data(code, load_latest=False) |
| | | volume_rate = code_volumn_manager.get_volume_rate(code) |
| | | volume_rate_index = code_volumn_manager.get_volume_rate_index(volume_rate) |
| | | m_val = L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | m_val_num = int(m_val / (float(limit_up_price) * 100)) |
| | | # 处理成交大单 |
| | | DealOrderNoManager().remove_orderno(code, f"{order_no}") |
| | | total_deal_nums = DealOrderNoManager().get_deal_nums(code, l2_data_util.local_today_buyno_map.get(code)) |
| | | thresh_hold_money = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | if limit_up_price: |
| | | rate = round(total_deal_nums / (thresh_hold_money // (float(limit_up_price) * 100)), 2) |
| | | LCancelRateManager().set_big_num_deal_rate(code, rate) |
| | | pass |
| | | |
| | | @classmethod |
| | | def test_sell(cls): |