Administrator
2025-02-07 7eb1a8ed1a007d80de41d131071ee38f5872700c
l2/code_price_manager.py
@@ -2,8 +2,12 @@
代码价格管理
"""
import json
import threading
import time
from code_attribute.gpcode_manager import CodePrePriceManager
from db.redis_manager_delegate import RedisUtils
from utils import tool
from utils import tool, middle_api_protocol
from db import redis_manager_delegate as redis_manager
from log_module.log import logger_trade_queue_price_info
@@ -73,7 +77,6 @@
                                         (limit_up_time, open_limit_up_time))
        RedisUtils.setex_async(self.__db, f"buy1_price_limit_up_info-{code}", tool.get_expire(),
                               json.dumps((limit_up_time, open_limit_up_time)))
    def __get_buy1_price_limit_up_info_cache(self, code):
        cache_result = tool.CodeDataCacheUtil.get_cache(self.__buy1_price_limit_up_info_cache, code)
@@ -200,5 +203,34 @@
        return self.__latest_3m_buy1_money_list_dict.get(code)
class CurrentPriceManager:
    """
    现价管理
    """
    # 代码涨幅数据
    __current_rate_dict = {}
    # 最近上传时间
    __latest_upload_time = 0
    @classmethod
    def set_current_price(cls, code, price):
        """
        设置现价
        @param code:
        @param price:
        @return:
        """
        pre_close_price = CodePrePriceManager.get_price_pre_cache(code)
        if pre_close_price:
            rate = round((price - pre_close_price) * 100 / pre_close_price, 2)
            cls.__current_rate_dict[code] = rate
        # 判断是否要上传
        if time.time() - cls.__latest_upload_time >= 3:
            # 间隔3s上传
            cls.__latest_upload_time = time.time()
            threading.Thread(target=lambda: middle_api_protocol.request(
                middle_api_protocol.load_l2_subscript_codes_rate(cls.__current_rate_dict)), daemon=True).start()
if __name__ == "__main__":
    print(Buy1PriceManager().get_limit_up_info("002777"))