| | |
| | | from huaxin_client import l2_data_transform_protocol |
| | | from huaxin_client.trade_transform_protocol import TradeResponse |
| | | from l2 import l2_data_manager_new, l2_log, code_price_manager, l2_data_util, transaction_progress, \ |
| | | l2_data_source_util, l2_data_log |
| | | l2_data_source_util, l2_data_log, data_callback |
| | | from l2.cancel_buy_strategy import GCancelBigNumComputer, \ |
| | | DCancelBigNumComputer, RDCancelBigNumComputer |
| | | from l2.code_price_manager import Buy1PriceManager |
| | |
| | | from log_module import async_log_util, log_export |
| | | from log_module.log import hx_logger_contact_debug, hx_logger_trade_callback, \ |
| | | hx_logger_l2_orderdetail, hx_logger_l2_market_data, logger_l2_g_cancel, logger_debug, \ |
| | | logger_system, logger_trade, logger_l2_radical_buy, logger_l2_not_buy_reasons |
| | | logger_system, logger_trade, logger_l2_radical_buy |
| | | from third_data import block_info, kpl_data_manager, history_k_data_manager, huaxin_l1_data_manager, kpl_api, kpl_util |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, CodePlateKeyBuyManager, RealTimeKplMarketData, \ |
| | | from third_data.code_plate_key_manager import KPLCodeJXBlockManager, RealTimeKplMarketData, \ |
| | | KPLPlateForbiddenManager |
| | | from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils |
| | | from third_data.kpl_limit_up_data_manager import LatestLimitUpBlockManager |
| | | from trade import l2_trade_util, \ |
| | | trade_data_manager, trade_constant, buy_open_limit_up_strategy |
| | | from trade.buy_radical import radical_buy_data_manager, radical_buy_strategy |
| | |
| | | def l2_transaction(cls, code, datas): |
| | | # async_log_util.info(hx_logger_l2_transaction, f"{code}#{datas}") |
| | | if datas: |
| | | HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas(code, datas) |
| | | HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas_v2(code, datas) |
| | | |
| | | @classmethod |
| | | def l2_market_data(cls, code, data): |
| | |
| | | l2_log.info(code, logger_debug, f"扫入处理时长:{code}-{use_time}") |
| | | |
| | | 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, "处理涨停成交数据") |
| | | # 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, "处理涨停成交数据") |
| | | pass |
| | | |
| | | def OnLastLimitUpSellDeal(self, code, data): |
| | | """ |
| | | 最后一笔涨停卖数据成交 |
| | | @param code: |
| | | @param data: (data['SecurityID'], data['TradePrice'], data['TradeVolume'], data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], data['SellNo'], data['ExecType']) |
| | | @return: |
| | | """ |
| | | if data[6] < data[7]: |
| | | # 非主动买 |
| | | return |
| | | # 根据板块判断是否可买 |
| | | state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | if not trade_util.is_can_order_by_state(state): |
| | | # 不处于可下单状态 |
| | | return |
| | | |
| | | l2_log.info(code, logger_l2_radical_buy, f"最后一笔涨停卖被吃:{code}-{data}") |
| | | deal_codes = RadicalBuyDealCodesManager().get_deal_codes() |
| | | # 判断今日扫入的代码数量是否大于阈值 |
| | | radical_buy_setting = BuyMoneyAndCountSetting().get_radical_buy_setting() |
| | | MAX_COUNT = 4 if radical_buy_setting is None else radical_buy_setting[0] |
| | | if not WantBuyCodesManager().is_in_cache(code): |
| | | # 加绿不判断板块是否成交 |
| | | if len(deal_codes) >= MAX_COUNT: |
| | | l2_log.info(code, logger_l2_radical_buy, f"扫入成交代码个数大于{MAX_COUNT}个:{code}-{deal_codes}") |
| | | return |
| | | if code in deal_codes: |
| | | l2_log.info(code, logger_l2_radical_buy, f"该代码已经成交:{code}") |
| | | return |
| | | |
| | | # 单票是否可买 |
| | | can_buy_result = RadicalBuyDataManager.is_code_can_buy(code) |
| | | if not can_buy_result[0]: |
| | | return |
| | | # 获取激进买的板块 |
| | | f_buy_blocks, orgin_buy_blocks = radical_buy_strategy.compute_can_radical_buy_blocks(code, deal_codes) |
| | | if not orgin_buy_blocks: |
| | | l2_log.info(code, logger_l2_radical_buy, f"没有可扫入的板块:{code}") |
| | | return |
| | | |
| | | if not f_buy_blocks: |
| | | return |
| | | # 买入的板块 |
| | | buy_blocks = f_buy_blocks |
| | | # 判断当前时间段是否可以买入 |
| | | mode = OrderBeginPosInfo.MODE_RADICAL |
| | | can_buy, money, msg = BuyMoneyUtil.get_buy_data(tool.get_now_time_str(), mode, |
| | | DealAndDelegateWithBuyModeDataManager().get_deal_codes_info( |
| | | mode), |
| | | DealAndDelegateWithBuyModeDataManager().get_delegates_codes_info( |
| | | mode)) |
| | | if not can_buy: |
| | | l2_log.info(code, logger_l2_radical_buy, f"当前时间段已不能扫入:{code}-{msg}") |
| | | return |
| | | |
| | | in_blocks = RealTimeKplMarketData.get_top_market_jingxuan_blocks() |
| | | buy_blocks_with_money = [(b, RealTimeKplMarketData.get_jx_block_in_money(b), |
| | | in_blocks.index(b) if b in in_blocks else -1) for b in buy_blocks] |
| | | if not WantBuyCodesManager().is_in_cache(code): |
| | | # 判断是否开得太高 |
| | | open_price = L1DataManager.get_open_price(code) |
| | | if not radical_buy_strategy.is_can_buy_with_open_price(code, open_price): |
| | | l2_log.info(code, logger_l2_radical_buy, f"开得太高:{code}") |
| | | radical_buy_data_manager.ExcludeIndexComputeCodesManager.add_code(code) |
| | | return |
| | | radical_buy_data_manager.ExcludeIndexComputeCodesManager.remove_code(code) |
| | | |
| | | # 根据L2下单 |
| | | latest_buy_no = data[6] |
| | | latest_deal_time = l2_huaxin_util.convert_time(data[3]) |
| | | |
| | | RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict[code] = ( |
| | | time.time() + 1, latest_buy_no, buy_blocks, |
| | | latest_deal_time, buy_blocks_with_money, False) |
| | | |
| | | |
| | | # 回调 |
| | |
| | | # L2成交信号回调 |
| | | global l2_trade_single_callback |
| | | l2_trade_single_callback = MyL2TradeSingleCallback() |
| | | data_callback.l2_trade_single_callback = l2_trade_single_callback |
| | | |
| | | L2TradeSingleDataManager.set_callback(l2_trade_single_callback) |
| | | # 加载自由流通量 |