| | |
| | | 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 ths import client_manager |
| | | import constant |
| | | from code_attribute import gpcode_manager |
| | | from utils import tool, import_util |
| | |
| | | |
| | | |
| | | def accept_prices(prices, request_id=None): |
| | | # 获取首板代码 |
| | | first_codes = gpcode_manager.FirstGPCodesManager().get_first_gp_codes_cache() |
| | | |
| | | print("总价格代码数量:", len(prices)) |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: |
| | | __actualPriceProcessor.save_current_price_codes_count(len(prices)) |
| | | # 采集的代码数量不对, 暂时不需要 |
| | | # if len(gpcode_manager.get_gp_list()) - len(prices) > 10: |
| | | # logger_l2_codes_subscript.info("采集到的代码数量不正确:{}", len(prices)) |
| | | # return |
| | | now_str = tool.get_now_time_str() |
| | | # 获取想买单 |
| | | want_codes = gpcode_manager.WantBuyCodesManager().list_code_cache() |
| | |
| | | _code_list = [] |
| | | _delete_list = [] |
| | | temp_prices = [] |
| | | temp_rates = [] |
| | | for d in prices: |
| | | code, price = d["code"], float(d["price"]) |
| | | temp_prices.append((code, price)) |
| | |
| | | if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED: |
| | | is_want_buy = True |
| | | rate = round((price - pricePre) * 100 / pricePre, 2) |
| | | if first_codes and code in first_codes: |
| | | rate = rate / 2 |
| | | if tool.is_ge_code(rate): |
| | | # 创业板的涨幅需要打折 |
| | | rate = rate/2 |
| | | if rate >= 0 and not trade_manager.ForbiddenBuyCodeByScoreManager().is_in_cache(code): |
| | | # 暂存涨幅为正的代码 |
| | | _code_list.append((rate, code, 1 if is_want_buy else 0)) |
| | |
| | | # 暂存涨幅为负的代码 |
| | | _delete_list.append((rate, code, 0)) |
| | | try: |
| | | temp_rates.append((code, rate)) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | |
| | | try: |
| | | __actualPriceProcessor.save_current_price(code, price, |
| | | gpcode_manager.get_limit_up_price_by_preprice(code, |
| | | pricePre) == tool.to_price( |
| | |
| | | logging.exception(e) |
| | | logger_l2_codes_subscript.exception(e) |
| | | gpcode_manager.set_prices(temp_prices) |
| | | __actualPriceProcessor.process_rates(temp_rates, now_str) |
| | | # -------------------------------处理交易位置分配--------------------------------- |
| | | # 排序 |
| | | new_code_list = sorted(_code_list, key=lambda e: (e.__getitem__(2), e.__getitem__(0)), reverse=True) |
| | |
| | | new_code_list.remove(item) |
| | | # 截取前几个代码填充 |
| | | add_list = new_code_list[:max_count] |
| | | async_log_util.info(logger_l2_codes_subscript, |
| | | f"({request_id})需要订阅的代码:{add_list}") |
| | | |
| | | # 后面的代码全部删除 |
| | | _delete_list.extend(new_code_list[max_count:]) |
| | | |