Administrator
2025-06-10 efe62c0c92bee36da5179f34bb73e8ee4db6f814
third_data/custom_block_in_money_manager.py
@@ -6,17 +6,29 @@
import os
import constant
import l2_data_util
from db import mysql_data_delegate as mysql_data
from huaxin_client import l1_subscript_codes_manager
from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager
from third_data.third_blocks_manager import BlockMapManager
from utils import tool
from utils import tool, global_util
@tool.singleton
class CodeInMoneyManager:
    def __init__(self):
        # 总的净流入
        self.__code_money_dict = {}
        # 总买单信息:{"code":[金额, 数量]}
        self.__code_buy_money_dict = {}
        # 总卖单信息:{"code":[金额, 数量]}
        self.__code_sell_money_dict = {}
        # 净流入大单买金额
        self.__code_big_buy_money_list_dict = {}
        # 净流出大单卖金额
        self.__code_big_sell_money_list_dict = {}
        self.__latest_price = {}
        self.__load_data()
    def __load_data(self):
@@ -30,17 +42,51 @@
                    self.add_data(item)
    def add_data(self, item):
        """
        添加数据
        @param item: (代码,类型, 订单数据)  订单数据:(订单号, 量, 金额, 时间, 最新成交价格)
        @return:
        """
        code = item[0]
        if code not in self.__code_money_dict:
            self.__code_money_dict[code] = 0
        if not tool.is_ge_code(code) and item[2][2] < 299e4:
            return
        if code not in self.__code_buy_money_dict:
            self.__code_buy_money_dict[code] = [0, 0]
        if code not in self.__code_sell_money_dict:
            self.__code_sell_money_dict[code] = [0, 0]
        if not tool.is_ge_code(code):
            big_money = l2_data_util.get_big_money_val(item[2][4])
            if item[2][2] < big_money:
                # 不是常规定义的大单就返回
                return
        if tool.is_ge_code(code) and item[2][2] < 299e4 and item[2][1] < 290000:
            return
        if item[1] == 0:
            # item[2]的数据结构:  (买单号, 量, 金额, 时间, 最新成交价格)
            self.__code_money_dict[code] += item[2][2]
            self.__code_buy_money_dict[code][0] += item[2][2]
            self.__code_buy_money_dict[code][1] += 1
            if code not in self.__code_big_buy_money_list_dict:
                self.__code_big_buy_money_list_dict[code] = []
            # 大买单信息:(金额, 最新价格, 订单号)
            if len(item[2]) >= 5:
                self.__code_big_buy_money_list_dict[code].append((item[2][2], item[2][4], item[2][0]))
        else:
            self.__code_money_dict[code] -= item[2][2]
            self.__code_sell_money_dict[code][0] += item[2][2]
            self.__code_sell_money_dict[code][1] += 1
            # 大卖单信息
            if code not in self.__code_big_sell_money_list_dict:
                self.__code_big_sell_money_list_dict[code] = []
            if len(item[2]) >= 5:
                # 大卖单信息:(金额, 最新价格, 订单号)
                self.__code_big_sell_money_list_dict[code].append((item[2][2], item[2][4], item[2][0]))
        self.__latest_price[code] = item[2][4]
    def get_code_money_dict(self):
        return self.__code_money_dict
@@ -50,8 +96,36 @@
            return self.__code_money_dict.get(code)
        return 0
    def get_money_info(self, code):
        """
        获取代码流入信息
        @param code: 代码信息
        @return: 净流入金额,[大单买金额, 大单买数量],[大单卖金额,大单卖数量]
        """
        return self.__code_money_dict.get(code), self.__code_buy_money_dict.get(code), self.__code_sell_money_dict.get(
            code)
    def set_money(self, code, money):
        self.__code_money_dict[code] = money
    def get_big_buy_money_list(self, code):
        """
        获取代码的大买单列表
        @param code:
        @return:[(金额, 价格, 订单号)]
        """
        return self.__code_big_buy_money_list_dict.get(code)
    def get_big_sell_money_list(self, code):
        """
        获取代码的大买单列表
        @param code:
        @return:[(金额, 价格, 订单号)]
        """
        return self.__code_big_sell_money_list_dict.get(code)
    def get_latest_price(self, code):
        return self.__latest_price.get(code)
@tool.singleton
@@ -155,6 +229,13 @@
            money = CodeInMoneyManager().get_money(code)
            if money is None:
                continue
            # 大自由流通市值的流出不算
            if money < 0:
                price = CodeInMoneyManager().get_latest_price(code)
                zylt_volume = global_util.zylt_volume_map.get(code)
                if price and zylt_volume and zylt_volume * price > 200e8:
                    continue
            before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code)
            if not before_fblocks:
                before_fblocks = set()
@@ -186,6 +267,12 @@
            money = CodeInMoneyManager().get_money(code)
            if money is None:
                continue
            # 大自由流通市值的流出不算
            if money < 0:
                price = CodeInMoneyManager().get_latest_price(code)
                zylt_volume = global_util.zylt_volume_map.get(code)
                if price and zylt_volume and zylt_volume * price > 200e8:
                    continue
            before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code)
            if not before_fblocks:
                before_fblocks = set()
@@ -203,7 +290,10 @@
if __name__ == '__main__':
    BlockInMoneyRankManager()
    code = "600839"
    before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code)
    print(before_fblocks)
    # print(CodeInMoneyManager().get_money("300264"))
    # BlockInMoneyRankManager().compute()
    # print(BlockInMoneyRankManager().get_in_list()[:20])