| | |
| | | |
| | | from l2.huaxin import huaxin_target_codes_manager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_l2_codes_subscript |
| | | from log_module.log import logger_l2_codes_subscript, logger_debug |
| | | import constant |
| | | from code_attribute import gpcode_manager |
| | | from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager |
| | | from trade.buy_radical.block_special_codes_manager import BlockSpecialCodesManager |
| | | from trade.buy_radical.radical_buy_data_manager import RadicalBuyBlockManager |
| | | from utils import tool, import_util |
| | | from trade import trade_manager, l2_trade_util, trade_constant |
| | | from trade.trade_data_manager import CodeActualPriceProcessor |
| | |
| | | latest_add_codes = set() |
| | | |
| | | |
| | | def accept_prices(prices, request_id=None): |
| | | print("总价格代码数量:", len(prices)) |
| | | now_str = tool.get_now_time_str() |
| | | # 获取想买单 |
| | | want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() |
| | | def __compute_code_order(code, top_in_blocks=None, yesterday_limit_up_codes=None): |
| | | """ |
| | | 计算代码的排序 |
| | | @param code: |
| | | @param top_in_blocks: 净流入前几 |
| | | @return: 排序值,若为负值不订阅 |
| | | """ |
| | | # 想买单/隔夜单排序位 |
| | | if yesterday_limit_up_codes is None: |
| | | yesterday_limit_up_codes = set() |
| | | if top_in_blocks is None: |
| | | top_in_blocks = [] |
| | | # 想买单 |
| | | if gpcode_manager.WantBuyCodesManager().is_in_cache(code): |
| | | return 0 |
| | | # 隔夜单拍一 |
| | | if gpcode_manager.BuyOpenLimitUpCodeManager().is_in_cache(code): |
| | | return 0 |
| | | |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) |
| | | # 如果当前清单处于委托状态就不能移除 |
| | | if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED: |
| | | return 0 |
| | | # 高位板 |
| | | if code in yesterday_limit_up_codes: |
| | | return -1 |
| | | # 黑名单 |
| | | if l2_trade_util.is_in_forbidden_trade_codes(code): |
| | | return -1 |
| | | # 板块 |
| | | blocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code) |
| | | if not blocks: |
| | | return -1 |
| | | for b in blocks: |
| | | if b in top_in_blocks: |
| | | index = top_in_blocks.index(b) |
| | | # 查询在板块中的排序 |
| | | info = RadicalBuyBlockManager().get_history_index(code, b, yesterday_limit_up_codes) |
| | | if info[0] < 4: |
| | | return index + 1 |
| | | elif info[0] < 6: |
| | | # 判断是否具有辨识度 |
| | | special_codes = BlockSpecialCodesManager().get_block_codes(b) |
| | | if special_codes and code in special_codes: |
| | | return index + 1 |
| | | return 10000 |
| | | |
| | | |
| | | def accept_prices(prices, request_id=None, top_in_blocks=None, yesterday_limit_up_codes=None): |
| | | """ |
| | | 接收价格,处理订阅 |
| | | @param yesterday_limit_up_codes: 昨日涨停数据 |
| | | @param history_limit_up_datas: 历史涨停数据 |
| | | @param prices: |
| | | @param request_id: |
| | | @param top_in_blocks: 净流入前几的代码 |
| | | @return: |
| | | """ |
| | | logger_debug.debug(f"接收L1数据测试:流入前20-{top_in_blocks}") |
| | | if True: |
| | | _code_list = [] |
| | | _delete_list = [] |
| | |
| | | pricePre = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code) |
| | | if pricePre is not None: |
| | | # 是否是想买单 |
| | | is_want_buy = code in want_codes |
| | | trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) |
| | | # 如果当前清单处于委托状态就不能移除 |
| | | if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED: |
| | | is_want_buy = True |
| | | |
| | | if gpcode_manager.BuyOpenLimitUpCodeManager().is_in_cache(code): |
| | | is_want_buy = True |
| | | order_index = __compute_code_order(code, top_in_blocks, yesterday_limit_up_codes) |
| | | |
| | | rate = round((price - pricePre) * 100 / pricePre, 2) |
| | | if tool.is_ge_code(code): |
| | | # 创业板的涨幅需要打折 |
| | | rate = rate / 2 |
| | | if rate >= 0: |
| | | # 暂存涨幅为正的代码 |
| | | _code_list.append((rate, code, 1 if is_want_buy else 0)) |
| | | elif is_want_buy: |
| | | _code_list.append((rate, code, 1 if is_want_buy else 0)) |
| | | if order_index >= 0: |
| | | _code_list.append((rate, code, order_index)) |
| | | else: |
| | | # 暂存涨幅为负的代码 |
| | | _delete_list.append((rate, code, 0)) |
| | |
| | | gpcode_manager.set_prices(temp_prices) |
| | | # -------------------------------处理交易位置分配--------------------------------- |
| | | # 排序 |
| | | new_code_list = sorted(_code_list, key=lambda e: (e.__getitem__(2), e.__getitem__(0)), reverse=True) |
| | | new_code_list = sorted(_code_list, key=lambda e: (e[2], -e[0])) |
| | | logger_debug.debug(f"接收L1数据测试:排序过后的代码-{new_code_list[:75]}") |
| | | # -------------------------------处理L2监听--------------------------------- |
| | | max_count = constant.HUAXIN_L2_MAX_CODES_COUNT |
| | | |
| | |
| | | if l2_trade_util.is_in_forbidden_trade_codes( |
| | | item[1]) or item[0] < 0: |
| | | # 在(黑名单)/(涨幅小于)的数据 |
| | | if trade_manager.CodesTradeStateManager().get_trade_state_cache( |
| | | item[1]) != trade_constant.TRADE_STATE_BUY_SUCCESS: |
| | | # 没成交才会加入删除 |
| | | _delete_list.append(item) |
| | | # if trade_manager.CodesTradeStateManager().get_trade_state_cache( |
| | | # item[1]) != trade_constant.TRADE_STATE_BUY_SUCCESS: |
| | | # 没成交才会加入删除 |
| | | _delete_list.append(item) |
| | | |
| | | for item in _delete_list: |
| | | new_code_list.remove(item) |