| | |
| | | code = d[0] |
| | | codes.add(code) |
| | | self.codes_volume_and_price_dict[code] = (d[1], d[2], d[3], d[4]) |
| | | self.l2_data_upload_manager.set_order_fileter_condition(code, d[1], float(d[2]), d[3], d[4]) |
| | | self.l2_data_upload_manager.set_order_fileter_condition(code, d[1], round(float(d[2]), 2), d[3], d[4]) |
| | | add_codes = codes - self.subscripted_codes |
| | | del_codes = self.subscripted_codes - codes |
| | | print("add del codes", add_codes, del_codes) |
| | |
| | | # special_price:过滤的1手的价格 |
| | | def set_order_fileter_condition(self, code, min_volume, limit_up_price, shadow_price, buy_volume): |
| | | if code not in self.filter_order_condition_dict: |
| | | self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, shadow_price, buy_volume, min_volume//10 if code.find("00")==0 else min_volume)] |
| | | self.filter_order_condition_dict[code] = [(min_volume, limit_up_price, shadow_price, buy_volume, |
| | | min_volume // 25 if code.find("00") == 0 else min_volume)] |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_subscript, |
| | | f"({code})常规过滤条件设置:{self.filter_order_condition_dict[code]}") |
| | | |
| | |
| | | if item[2] == filter_condition[0][3]: |
| | | return item |
| | | |
| | | # 卖大于10w |
| | | if item[3] != '1' and item[2] > filter_condition[0][4]: |
| | | # 卖大于2w且是涨停卖 |
| | | if item[3] != '1' and item[2] > filter_condition[0][4] and item[1] == filter_condition[0][1]: |
| | | return item |
| | | |
| | | return None |
| | |
| | | "mainSeq": item[6], "subSeq": item[7]} |
| | | |
| | | |
| | | # 处理l2数据 |
| | | # filter_not_limit_up : 过滤掉非涨停数据 |
| | | def __format_l2_data(origin_datas, code, limit_up_price, filter_not_limit_up=True): |
| | | def __format_l2_data(origin_datas, code, limit_up_price, filter_not_limit_up=True, filter_limit_up_sell=False): |
| | | """ |
| | | 处理l2数据 |
| | | @param origin_datas:原始数据 |
| | | @param code:代码 |
| | | @param limit_up_price:涨停价 |
| | | @param filter_not_limit_up:是否过滤掉非涨停数据 |
| | | @param filter_limit_up_sell:是否过滤涨停卖 |
| | | @return:格式化过后的数据 |
| | | """ |
| | | datas = [] |
| | | dataIndexs = {} |
| | | same_time_num = {} |
| | |
| | | if filter_not_limit_up and int(item["limitPrice"]) != 1 and ( |
| | | int(operateType) == 0 or int(operateType) == 1) and num != 1: |
| | | continue |
| | | |
| | | if filter_limit_up_sell and int(item["limitPrice"]) == 1 and int(operateType) == 2: |
| | | # 过滤涨停卖 |
| | | continue |
| | | |
| | | key = "{}-{}-{}".format(code, item["mainSeq"], item["subSeq"]) |
| | | if key in dataIndexs: |
| | | # 数据重复次数+1 |
| | |
| | | return datas |
| | | |
| | | |
| | | def get_format_l2_datas(code, origin_datas, limit_up_price, start_index): |
| | | def get_format_l2_datas(code, origin_datas, limit_up_price, start_index, filter_limit_up_sell=False): |
| | | """ |
| | | 华鑫L2数据格式化 |
| | | @param code: |
| | | @param origin_datas: |
| | | @param limit_up_price:涨停价 |
| | | @param start_index: |
| | | @param filter_limit_up_sell:是否过滤涨停卖 |
| | | @return: |
| | | """ |
| | | |
| | | # 先转变数据格式 |
| | | datas = [__convert_order(x, float(limit_up_price)) for x in origin_datas] |
| | | # 在9:25之前不过滤非涨停金额 |
| | |
| | | # filter_not_limit_up = False |
| | | # 不过滤非涨停金额 |
| | | filter_not_limit_up = False |
| | | fdatas = __format_l2_data(datas, code, float(limit_up_price), filter_not_limit_up=filter_not_limit_up) |
| | | fdatas = __format_l2_data(datas, code, float(limit_up_price), filter_not_limit_up=filter_not_limit_up, |
| | | filter_limit_up_sell=filter_limit_up_sell) |
| | | for i in range(0, len(fdatas)): |
| | | fdatas[i]["index"] = start_index + i |
| | | return fdatas |
| | |
| | | local_today_datas[code] = [] |
| | | if total_datas: |
| | | _start_index = total_datas[-1]["index"] + 1 |
| | | datas = l2_huaxin_util.get_format_l2_datas(code, origin_datas, |
| | | gpcode_manager.get_limit_up_price(code), _start_index) |
| | | |
| | | # 如果是板上,就需要剔除板上卖数据, 默认不剔除 |
| | | filter_limit_up_sell = False |
| | | trade_price_info = HuaXinSellOrderStatisticManager.get_latest_trade_price_info(code) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price: |
| | | limit_up_price = round(float(limit_up_price), 2) |
| | | if trade_price_info and limit_up_price and trade_price_info[0] == limit_up_price: |
| | | filter_limit_up_sell = True |
| | | datas = l2_huaxin_util.get_format_l2_datas(code, origin_datas, limit_up_price, _start_index, |
| | | filter_limit_up_sell) |
| | | __start_time = round(t.time() * 1000) |
| | | if len(datas) > 0: |
| | | cls.process_add_datas(code, datas, 0, __start_time) |
| | |
| | | start_time_str = total_datas[start_index]["val"]["time"] |
| | | # 获取最近的总卖信息 |
| | | refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, start_time_str) |
| | | if refer_sell_data is None: |
| | | if refer_sell_data is None and start_time_str != '09:30:00': |
| | | return False, -1, "总卖为空" |
| | | if refer_sell_data is None: |
| | | refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0)) |
| | | l2_log.debug(code, f"丢失总卖额,设置默认为0,计算范围:{start_index}-{end_index}") |
| | | # 获取当前是否可激进买 |
| | | # 获取板块是否可以激进买 |
| | | # 可买的板块, 是否独苗, 消息, 可买的强势板块, 关键词, 激进买的板块 |
| | |
| | | if not trigger_buy: |
| | | not_buy_msg = f"【{i}】没有买单触发" |
| | | continue |
| | | if buy_count < 1: |
| | | not_buy_msg = f"【{i}】安全笔数不足,{buy_count}/{1}" |
| | | |
| | | safe_count = 1 |
| | | if threshold_money <= 0: |
| | | # 板上下单需要安全笔数3笔 |
| | | safe_count = 3 |
| | | |
| | | if buy_count < safe_count: |
| | | not_buy_msg = f"【{i}】安全笔数不足,{buy_count}/{safe_count}" |
| | | continue |
| | | |
| | | # max_buy_num_set = cls.__filter_not_deal_indexes(code, max_buy_num_set) |
| | |
| | | # 最近所有的卖单 |
| | | __latest_all_sell_orders_dict = {} |
| | | |
| | | # 保存最近成交的价格 |
| | | __latest_trade_price_dict = {} |
| | | |
| | | # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...]) |
| | | @classmethod |
| | | def add_transaction_datas(cls, code, datas, buy_exec_index=None): |
| | | def add_transaction_datas(cls, code, datas, limit_up_price=None): |
| | | # 是否为主动卖 |
| | | def is_active_sell(sell_no, buy_no): |
| | | return sell_no > buy_no |
| | |
| | | total_datas = local_today_datas.get(code) |
| | | if not sell_no_map: |
| | | sell_no_map = {} |
| | | |
| | | # 保存最近的成交价格:(价格,成交时间) |
| | | cls.__latest_trade_price_dict[code] = (datas[-1][1], datas[-1][3]) |
| | | |
| | | for d in datas: |
| | | if not is_active_sell(d[7], d[6]): |
| | | # 获取当前是否为主动买 |
| | | _is_active_sell = is_active_sell(d[7], d[6]) |
| | | if not _is_active_sell and d[1] == limit_up_price: |
| | | # TODO 被动涨停卖,这个卖的订单是否在最近的涨停卖列表中 |
| | | pass |
| | | |
| | | if not _is_active_sell: |
| | | continue |
| | | cls.__latest_sell_order_info_list_dict[code].append(d) |
| | | if code not in cls.__latest_sell_order_dict: |
| | |
| | | total_big_sell_datas = cls.__big_sell_order_info_list_dict.get(code) |
| | | |
| | | total_sell_info = [0, None] # 总资金,开始成交信息,结束成交信息 |
| | | latest_sell_order_info = cls.__latest_sell_order_dict[code] |
| | | big_sell_order_ids = cls.__big_sell_order_ids_dict[code] |
| | | # print("大卖单", big_sell_order_ids) |
| | | big_sell_orders = [] |
| | | temp_sell_order_ids = set() |
| | | # 统计已经结算出的大单 |
| | | for i in range(len(total_big_sell_datas) - 1, -1, -1): |
| | | bd = total_big_sell_datas[i] |
| | | if min_time_int > int( |
| | | l2_huaxin_util.convert_time(bd[3][0], with_ms=True).replace(":", "").replace(".", "")): |
| | | break |
| | | if bd[0] != latest_sell_order_info[0]: |
| | | # 不是最近的成交且不是大单直接过滤 |
| | | if bd[0] not in big_sell_order_ids: |
| | | continue |
| | | latest_sell_order_info = cls.__latest_sell_order_dict.get(code) |
| | | if latest_sell_order_info: |
| | | # 不是第一次非主动卖上传 |
| | | big_sell_order_ids = cls.__big_sell_order_ids_dict[code] |
| | | # print("大卖单", big_sell_order_ids) |
| | | big_sell_orders = [] |
| | | temp_sell_order_ids = set() |
| | | # 统计已经结算出的大单 |
| | | for i in range(len(total_big_sell_datas) - 1, -1, -1): |
| | | bd = total_big_sell_datas[i] |
| | | if min_time_int > int( |
| | | l2_huaxin_util.convert_time(bd[3][0], with_ms=True).replace(":", "").replace(".", "")): |
| | | break |
| | | if bd[0] != latest_sell_order_info[0]: |
| | | # 不是最近的成交且不是大单直接过滤 |
| | | if bd[0] not in big_sell_order_ids: |
| | | continue |
| | | else: |
| | | if bd[0] not in temp_sell_order_ids: |
| | | big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(bd[0])) |
| | | temp_sell_order_ids.add(bd[0]) |
| | | else: |
| | | if bd[0] not in temp_sell_order_ids: |
| | | big_sell_orders.append(cls.__big_sell_order_info_dict[code].get(bd[0])) |
| | | temp_sell_order_ids.add(bd[0]) |
| | | else: |
| | | # 是最近的但不是大单需要过滤 |
| | | if latest_sell_order_info[1] * latest_sell_order_info[2] < 500000: |
| | | continue |
| | | else: |
| | | if latest_sell_order_info[0] not in temp_sell_order_ids: |
| | | big_sell_orders.append(latest_sell_order_info) |
| | | temp_sell_order_ids.add(latest_sell_order_info[0]) |
| | | # 是最近的但不是大单需要过滤 |
| | | if latest_sell_order_info[1] * latest_sell_order_info[2] < 500000: |
| | | continue |
| | | else: |
| | | if latest_sell_order_info[0] not in temp_sell_order_ids: |
| | | big_sell_orders.append(latest_sell_order_info) |
| | | temp_sell_order_ids.add(latest_sell_order_info[0]) |
| | | |
| | | # 统计最近1s的大卖单数据 |
| | | total_sell_info[0] += int(bd[1] * bd[2]) |
| | | # 统计最近的大单 |
| | | if latest_sell_order_info[1] * latest_sell_order_info[2] >= 500000: |
| | | if latest_sell_order_info[0] not in temp_sell_order_ids: |
| | | # if is_active_sell(latest_sell_order_info[0], latest_sell_order_info[3][1]): |
| | | big_sell_orders.append(latest_sell_order_info) |
| | | temp_sell_order_ids.add(latest_sell_order_info[0]) |
| | | total_sell_info[0] += int(latest_sell_order_info[1] * latest_sell_order_info[2]) |
| | | big_sell_orders.reverse() |
| | | total_sell_info[1] = big_sell_orders |
| | | # 统计最近1s的大卖单数据 |
| | | total_sell_info[0] += int(bd[1] * bd[2]) |
| | | # 统计最近的大单 |
| | | if latest_sell_order_info[1] * latest_sell_order_info[2] >= 500000: |
| | | if latest_sell_order_info[0] not in temp_sell_order_ids: |
| | | # if is_active_sell(latest_sell_order_info[0], latest_sell_order_info[3][1]): |
| | | big_sell_orders.append(latest_sell_order_info) |
| | | temp_sell_order_ids.add(latest_sell_order_info[0]) |
| | | total_sell_info[0] += int(latest_sell_order_info[1] * latest_sell_order_info[2]) |
| | | big_sell_orders.reverse() |
| | | total_sell_info[1] = big_sell_orders |
| | | return total_sell_info |
| | | |
| | | # 获取最近成交数据 |
| | |
| | | else: |
| | | total_orders.append(cls.__latest_sell_order_dict[code]) |
| | | return total_orders |
| | | |
| | | # 获取最近成交价格信息, 返回格式:(价格,时间) |
| | | @classmethod |
| | | def get_latest_trade_price_info(cls, code): |
| | | return cls.__latest_trade_price_dict.get(code) |
| | |
| | | import logging |
| | | import time |
| | | |
| | | 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 |
| | |
| | | |
| | | big_sell_order_info = None |
| | | try: |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price: |
| | | limit_up_price = round(float(limit_up_price), 2) |
| | | # 统计卖单 |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, datas, |
| | | order_begin_pos.buy_exec_index if is_placed_order else None) |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, datas, limit_up_price) |
| | | need_cancel, cancel_msg = SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, |
| | | big_sell_order_info, |
| | | order_begin_pos) |
| | |
| | | total_datas) |
| | | |
| | | if order_begin_pos and order_begin_pos.buy_exec_index and order_begin_pos.buy_exec_index > -1: |
| | | cancel_result = FCancelBigNumComputer().need_cancel_for_deal_fast(code,buy_progress_index) |
| | | cancel_result = FCancelBigNumComputer().need_cancel_for_deal_fast(code, buy_progress_index) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, cancel_result[1]) |
| | | HourCancelBigNumComputer().set_transaction_index(code, order_begin_pos.buy_single_index, |
| | |
| | | use_time = int((time.time() - __start_time) * 1000) |
| | | if use_time > 10: |
| | | async_log_util.info(hx_logger_l2_upload, f"{code}处理成交用时:{use_time}") |
| | | |
| | |
| | | |
| | | # 卖单统计 |
| | | def statistic_sell_order(): |
| | | code = "002248" |
| | | def is_active_sell(sell_no, buy_no): |
| | | return sell_no > buy_no |
| | | |
| | | code = "002761" |
| | | data_map = log_export.load_huaxin_transaction_map(date=tool.get_now_date_str()) |
| | | datas = data_map.get(code) |
| | | __latest_sell_order_dict = {} |
| | | total_money = 0 |
| | | limit_up_price = 9.2 |
| | | last_type = -1 |
| | | |
| | | for data in datas: |
| | | for d in data: |
| | | if d[7] == 559018: |
| | | if d[7] > d[6]: |
| | | print("主动卖", d) |
| | | else: |
| | | print("被动卖", d) |
| | | |
| | | type = -1 |
| | | if d[7] > d[6]: |
| | | type = 0 |
| | | else: |
| | | type = 1 |
| | | if type == 0 and last_type == 1 and d[1] == limit_up_price: |
| | | print("被动卖变主动卖", d) |
| | | last_type = type |
| | | |
| | | # if d[6] == 21296620: |
| | | # if d[7] > d[6]: |
| | | # print("主动卖", d) |
| | | # else: |
| | | # print("被动卖", d[1] * d[2], d) |
| | | if code not in __latest_sell_order_dict: |
| | | __latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])] |
| | | else: |
| | |
| | | __latest_sell_order_dict[code][4] = (d[3], d[6]) |
| | | else: |
| | | info = __latest_sell_order_dict[code] |
| | | money = info[1] * info[2] |
| | | if is_active_sell(info[0], info[3][1]) and 1000 * 10000 > money > 10 * 10000 and 7852775 > info[ |
| | | 0] > 7807625: |
| | | total_money += money |
| | | # print("主动卖:", round(money / 10000), total_money, info) |
| | | |
| | | # 上个卖单成交完成 |
| | | # 封存数据,计算新起点 |
| | | # 大于50w的卖单才会保存 |
| | | # 大于50w加入卖单 |
| | | money = info[1] * info[2] |
| | | if tool.trade_time_sub(l2_huaxin_util.convert_time(info[3][0]), "10:08:30") >= 0: |
| | | if info[2] >= 11.54: |
| | | total_money += money |
| | | print(money, round(total_money), info) |
| | | if money >= 500000: |
| | | pass |
| | | |
| | | # if tool.trade_time_sub(l2_huaxin_util.convert_time(info[3][0]), "10:08:30") >= 0: |
| | | # if info[2] >= 11.54: |
| | | # total_money += money |
| | | # print(money, round(total_money), info) |
| | | # if money >= 500000: |
| | | # pass |
| | | __latest_sell_order_dict[code] = [d[7], d[2], d[1], (d[3], d[6]), (d[3], d[6])] |
| | | |
| | | |
| | |
| | | |
| | | |
| | | def test_sell_order_info(): |
| | | code = "002248" |
| | | code = "600490" |
| | | l2_data_util.load_l2_data(code, force=True) |
| | | date = tool.get_now_date_str() |
| | | data_map = log_export.load_huaxin_transaction_map(date=date) |
| | |
| | | cancel_buy_strategy.SCancelBigNumComputer().set_real_place_order_index(code, 208, False) |
| | | cancel_buy_strategy.SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, big_sell_order_info, |
| | | OrderBeginPosInfo( |
| | | mode=OrderBeginPosInfo.MODE_ACTIVE,buy_single_index=0,buy_exec_index=13)) |
| | | mode=OrderBeginPosInfo.MODE_ACTIVE, |
| | | buy_single_index=0, |
| | | buy_exec_index=13)) |
| | | # if big_sell_order_info[0] < 50 * 10000: |
| | | # continue |
| | | # print(i, sum([x[1] * x[2] for x in big_sell_order_info[1]]), big_sell_order_info) |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | test_sell_order_info() |
| | | statistic_sell_order() |