| | |
| | | from ths import client_manager |
| | | import constant |
| | | from code_attribute import gpcode_manager |
| | | from trade.huaxin import huaxin_trade_api |
| | | from utils import tool, import_util |
| | | from ths.l2_code_operate import L2CodeOperate |
| | | from trade import trade_manager, l2_trade_util |
| | |
| | | # -------------------------------处理交易位置分配--------------------------------- |
| | | # 排序 |
| | | new_code_list = sorted(_code_list, key=lambda e: (e.__getitem__(2), e.__getitem__(0)), reverse=True) |
| | | # 预填充下单代码 |
| | | _buy_win_codes = [] |
| | | for d in new_code_list: |
| | | _buy_win_codes.append(d[1]) |
| | | for d in _delete_list: |
| | | _buy_win_codes.append(d[1]) |
| | | try: |
| | | if not constant.API_TRADE_ENABLE and trade_gui is not None: |
| | | trade_gui.THSBuyWinManagerNew.fill_codes(_buy_win_codes) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | pass |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: |
| | | # 预填充下单代码 |
| | | _buy_win_codes = [] |
| | | for d in new_code_list: |
| | | _buy_win_codes.append(d[1]) |
| | | for d in _delete_list: |
| | | _buy_win_codes.append(d[1]) |
| | | try: |
| | | if not constant.API_TRADE_ENABLE and trade_gui is not None: |
| | | trade_gui.THSBuyWinManagerNew.fill_codes(_buy_win_codes) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | pass |
| | | |
| | | # -------------------------------处理L2监听--------------------------------- |
| | | |
| | | client_ids = client_manager.getValidL2Clients() |
| | | # 最多填充的代码数量 |
| | | max_count = len(client_ids) * constant.L2_CODE_COUNT_PER_DEVICE |
| | | if max_count == 0: |
| | | max_count = constant.L2_CODE_COUNT_PER_DEVICE |
| | | max_count = 0 |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: |
| | | client_ids = client_manager.getValidL2Clients() |
| | | # 最多填充的代码数量 |
| | | max_count = len(client_ids) * constant.L2_CODE_COUNT_PER_DEVICE |
| | | if max_count == 0: |
| | | max_count = constant.L2_CODE_COUNT_PER_DEVICE |
| | | else: |
| | | max_count = constant.HUAXIN_L2_MAX_CODES_COUNT |
| | | |
| | | _delete_list = [] |
| | | for item in new_code_list: |
| | |
| | | for d in _delete_list: |
| | | del_code_list.append(d[1]) |
| | | |
| | | # 后面的代码数量 |
| | | # 先删除应该删除的代码 |
| | | for code in del_code_list: |
| | | if gpcode_manager.is_listen_old(code): |
| | | cid, pid = gpcode_manager.get_listen_code_pos(code) |
| | | # 强制移除 |
| | | if cid and pid: |
| | | gpcode_manager.set_listen_code_by_pos(cid, pid, "") |
| | | # 判断是否在监听里面 |
| | | L2CodeOperate.get_instance().add_operate(0, code, "现价变化") |
| | | # 增加应该增加的代码 |
| | | for code in add_code_list: |
| | | if not gpcode_manager.is_listen_old(code): |
| | | L2CodeOperate.get_instance().add_operate(1, code, "现价变化") |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN: |
| | | # 华鑫L2,获取加入代码的涨停价 |
| | | add_datas = [] |
| | | for d in add_code_list: |
| | | limit_up_price = gpcode_manager.get_limit_up_price(d) |
| | | min_volume = 50 * 10000 // limit_up_price |
| | | add_datas.append((d, min_volume, limit_up_price)) |
| | | try: |
| | | huaxin_trade_api.set_l2_codes_data(add_datas) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | else: |
| | | # 后面的代码数量 |
| | | # 先删除应该删除的代码 |
| | | for code in del_code_list: |
| | | if gpcode_manager.is_listen_old(code): |
| | | cid, pid = gpcode_manager.get_listen_code_pos(code) |
| | | # 强制移除 |
| | | if cid and pid: |
| | | gpcode_manager.set_listen_code_by_pos(cid, pid, "") |
| | | # 判断是否在监听里面 |
| | | L2CodeOperate.get_instance().add_operate(0, code, "现价变化") |
| | | # 增加应该增加的代码 |
| | | for code in add_code_list: |
| | | if not gpcode_manager.is_listen_old(code): |
| | | L2CodeOperate.get_instance().add_operate(1, code, "现价变化") |
| | | |
| | | # 获取卡位数量 |
| | | free_count = gpcode_manager.get_free_listen_pos_count() |
| | | if free_count < 2: |
| | | # 空闲位置不足 |
| | | listen_codes = gpcode_manager.get_listen_codes() |
| | | for code in listen_codes: |
| | | if not gpcode_manager.is_in_gp_pool(code): |
| | | client_id, pos = gpcode_manager.get_listen_code_pos(code) |
| | | gpcode_manager.set_listen_code_by_pos(client_id, pos, "") |
| | | free_count += 1 |
| | | if free_count > 2: |
| | | break |
| | | # 获取卡位数量 |
| | | free_count = gpcode_manager.get_free_listen_pos_count() |
| | | if free_count < 2: |
| | | # 空闲位置不足 |
| | | listen_codes = gpcode_manager.get_listen_codes() |
| | | for code in listen_codes: |
| | | if not gpcode_manager.is_in_gp_pool(code): |
| | | client_id, pos = gpcode_manager.get_listen_code_pos(code) |
| | | gpcode_manager.set_listen_code_by_pos(client_id, pos, "") |
| | | free_count += 1 |
| | | if free_count > 2: |
| | | break |
| | | |
| | | print(add_code_list, del_code_list) |
| | | print(add_code_list, del_code_list) |