| | |
| | | # 过滤涨停卖 |
| | | continue |
| | | |
| | | |
| | | |
| | | key = "{}-{}-{}".format(code, item["mainSeq"], item["subSeq"]) |
| | | if key in dataIndexs: |
| | | # 数据重复次数+1 |
| | |
| | | # filter_not_limit_up = True |
| | | # if int(datas[0]["time"][:5].replace(":", "")) <= 925: |
| | | # filter_not_limit_up = False |
| | | # 不过滤非涨停金额 |
| | | filter_not_limit_up = False |
| | | # 过滤掉非涨停买与买撤 |
| | | filter_not_limit_up = True |
| | | 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)): |
| | |
| | | |
| | | if __name__ == "__main__": |
| | | # 测试涨停总卖吃掉的情况 |
| | | code = "300253" |
| | | code = "002681" |
| | | datas = log_export.load_huaxin_l2_sell_deal_list(code).get(code) |
| | | print(datas) |
| | | deal_datas = [] |
| | | deal_order_nos = set() |
| | | for i in range(len(datas)): |
| | | if 133320 <= int(datas[i][0].replace(":", "")) <= 142039: |
| | | if 100100 <= int(datas[i][0].replace(":", "")) <= 100230: |
| | | deal_datas.append(datas[i]) |
| | | for x in deal_datas: |
| | | for xx in x[1]: |
| | |
| | | fdatas = [] |
| | | for x in datas: |
| | | # if int("101821") < int(x[0].replace(":", "")) < int("102841"): |
| | | if 42886361 >= x[2][0] >= 35522478: |
| | | if 14578165 >= x[2][0] >= 14565438: |
| | | fdatas.append(x) |
| | | delegate_order_nos = set() |
| | | total_delegate = 0 |
| | |
| | | # 保存最近的成交价格:(价格,成交时间) |
| | | cls.__latest_trade_price_dict[code] = (datas[-1][1], datas[-1][3]) |
| | | |
| | | L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, datas, limit_up_price) |
| | | # 是否还有涨停卖剩下 |
| | | no_left_limit_up_sell = L2TradeSingleDataProcessor.process_passive_limit_up_sell_data(code, datas, limit_up_price) |
| | | |
| | | for d in datas: |
| | | # 获取当前是否为主动买 |
| | |
| | | if d[1] == limit_up_price: |
| | | # 有涨停主动买 |
| | | limit_up_active_buy_datas.append(d) |
| | | L2TradeSingleDataManager.set_limit_up_active_buy(code, limit_up_active_buy_datas) |
| | | L2TradeSingleDataManager.set_limit_up_active_buy(code, limit_up_active_buy_datas, no_left_limit_up_sell) |
| | | except: |
| | | pass |
| | | |
| | |
| | | @param data: 数据格式:(data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | | # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], |
| | | # data['SellNo'], data['ExecType']) |
| | | @return: |
| | | @return: 涨停卖是否已经吃完 |
| | | """ |
| | | try: |
| | | start_time = time.time() |
| | | sell_list = cls.__latest_limit_up_sell_list_dict.get(code) |
| | | if not sell_list: |
| | | return |
| | | return False |
| | | sell_info = sell_list[-1] |
| | | for data in datas: |
| | | # 过滤被动买 |
| | |
| | | use_time = round((time.time() - start_time) * 1000, 3) |
| | | l2_log.info(code, logger_l2_trade_buy, |
| | | f"找到最近的被动涨停卖单数据:{sell_info['val']['orderNo']}, 成交数据:{data} 计算耗时:{use_time}ms, 可以触发下单") |
| | | |
| | | |
| | | |
| | | # 将历史大单列表与最近的大单加入列表 |
| | | big_buy_order_datas = [] |
| | | if code in cls.__active_buy_order_datas_dict: |
| | |
| | | # 成交完成 |
| | | L2TradeSingleDataManager.set_latest_sell_data(code, data, big_buy_order_datas) |
| | | l2_log.info(code, logger_l2_trade_buy, "被动卖数据处理完毕") |
| | | if tool.is_sz_code(code): |
| | | # 涨停主动卖已经被吃完,可以清除 |
| | | return True |
| | | break |
| | | # l2_log.info(code, logger_l2_trade_buy, f"找到最近的被动涨停卖单数据:{data['val']['orderNo']}, 可以触发下单") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | return False |
| | | |
| | | @classmethod |
| | | def add_active_limit_up_sell_data(cls, data): |
| | |
| | | @return: |
| | | """ |
| | | |
| | | def OnLimitUpActiveBuy(self, code, transaction_data): |
| | | def OnLimitUpActiveBuy(self, code, transaction_data, no_left_limit_up_sell): |
| | | """ |
| | | 涨停主动买触发 |
| | | @param code: |
| | | @param transaction_data: 成交数据 |
| | | @param no_left_limit_up_sell: 是否还剩余涨停卖 |
| | | @return: |
| | | """ |
| | | |
| | |
| | | # cls.__callback.OnTradeSingle(code, 0, cls.TYPE_ACTIVE, cls.__latest_sell_active_deal_data_dict[code]) |
| | | |
| | | @classmethod |
| | | def set_limit_up_active_buy(cls, code, transaction_datas): |
| | | def set_limit_up_active_buy(cls, code, transaction_datas, no_left_limit_up_sell): |
| | | if transaction_datas: |
| | | cls.__callback.OnLimitUpActiveBuy(code, transaction_datas) |
| | | cls.__callback.OnLimitUpActiveBuy(code, transaction_datas, no_left_limit_up_sell) |
| | | |
| | | @classmethod |
| | | def get_valid_trade_single(cls, code, latest_time_with_ms): |
| | |
| | | logger_debug.exception(e) |
| | | |
| | | def process_limit_up_active_buy(self, code, transaction_datas, is_almost_open_limit_up=False, |
| | | l2_market_time_str=''): |
| | | l2_market_time_str='', no_left_limit_up_sell=False): |
| | | """ |
| | | 处理涨停主动买 |
| | | @param no_left_limit_up_sell: 是否还有剩余涨停卖尚未成交 |
| | | @param code: |
| | | @param transaction_datas: |
| | | @param is_almost_open_limit_up: 是否即将炸板 |
| | |
| | | |
| | | # -----根据成交比例判断是否可买------ |
| | | result_by_volume = radical_buy_strategy.process_limit_up_active_buy_deal(code, transaction_datas, |
| | | is_almost_open_limit_up) |
| | | is_almost_open_limit_up, |
| | | no_left_limit_up_sell=no_left_limit_up_sell) |
| | | async_log_util.info(logger_l2_radical_buy, f"量买入结果判断:{code}, 结果:{result_by_volume} 板块:{buy_blocks}") |
| | | in_blocks = RealTimeKplMarketData.get_top_market_jingxuan_blocks() |
| | | buy_blocks_with_money = [(b, RealTimeKplMarketData.get_jx_block_in_money(b), |
| | |
| | | if use_time > 0.005: |
| | | async_log_util.info(logger_debug, f"扫入处理时长:{code}-{use_time}") |
| | | |
| | | def OnLimitUpActiveBuy(self, code, transaction_datas): |
| | | can_clear_before_data = self.process_limit_up_active_buy(code, transaction_datas) |
| | | def OnLimitUpActiveBuy(self, code, transaction_datas, no_left_limit_up_sell): |
| | | can_clear_before_data = self.process_limit_up_active_buy(code, transaction_datas, |
| | | no_left_limit_up_sell=no_left_limit_up_sell) |
| | | if can_clear_before_data: |
| | | # 清除 |
| | | EveryLimitupBigDealOrderManager.clear(code) |
| | |
| | | for bb in bs: |
| | | if bb not in code_block_dict[b[1]]: |
| | | code_block_dict[b[1]][bb] = 0 |
| | | if tool.is_ge_code(b[1]): |
| | | # 创业板1次涨停算2次涨停 |
| | | code_block_dict[b[1]][bb] += b[2] * 2 |
| | | else: |
| | | code_block_dict[b[1]][bb] += b[2] |
| | | # if tool.is_ge_code(b[1]): |
| | | # # 创业板1次涨停算2次涨停 |
| | | # code_block_dict[b[1]][bb] += b[2] * 2 |
| | | # else: |
| | | code_block_dict[b[1]][bb] += b[2] |
| | | block_codes_dict = {} # {"板块":[(代码,涨停次数)]} |
| | | for code in code_block_dict: |
| | | for b in code_block_dict[code]: |
| | |
| | | RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict.pop(code) |
| | | |
| | | |
| | | def process_limit_up_active_buy_deal(code, transaction_datas, is_almost_open_limit_up=False): |
| | | def process_limit_up_active_buy_deal(code, transaction_datas, is_almost_open_limit_up=False, no_left_limit_up_sell = False): |
| | | """ |
| | | 计算抛压消耗之后是否能下单 |
| | | @param code: |
| | |
| | | else: |
| | | average_big_order_money = 0 |
| | | # 如果剩余总卖小于100w直接根据L2买入 |
| | | if left_limit_up_sell_money < 100e4: |
| | | return BUY_MODE_BY_L2, f"剩余总卖小于100w({left_limit_up_sell_money})" |
| | | if left_limit_up_sell_money < 100e4 or no_left_limit_up_sell: |
| | | return BUY_MODE_BY_L2, f"剩余总卖小于100w({left_limit_up_sell_money}) 是否还有剩余涨停卖-{no_left_limit_up_sell}" |
| | | |
| | | return BUY_MODE_NONE, f"均大单-{average_big_order_money}({big_order_money}/{big_order_count}),剩余涨停卖:{left_limit_up_sell_money}" |
| | | # #总卖 = 涨停主动买成交的累计金额 + 处于委托状态的涨停卖金额 |