# 成交数据统计
|
from log_module import async_log_util, log_export
|
from log_module.log import hx_logger_l2_transaction_big_buy_order
|
from utils import l2_huaxin_util
|
|
|
class HuaXinBuyOrderManager:
|
__instance = None
|
|
# 正在成交的订单
|
__dealing_order_info_dict = {}
|
# 最近成交的订单{"code":(订单号,是否成交完成)}
|
__latest_deal_order_info_dict = {}
|
|
__total_big_buy_orders_dict = {}
|
|
def __new__(cls, *args, **kwargs):
|
if not cls.__instance:
|
cls.__instance = super(HuaXinBuyOrderManager, cls).__new__(cls, *args, **kwargs)
|
cls.__load_datas()
|
return cls.__instance
|
|
@classmethod
|
def __load_datas(cls):
|
fdatas = log_export.load_big_buy_order()
|
for code in fdatas:
|
cls.__total_big_buy_orders_dict[code] = fdatas[code]
|
|
@classmethod
|
def get_big_buy_orders(cls, code):
|
"""
|
获取正在成交的订单信息
|
:param code:
|
:return:[(订单号,总股数,成交金额,成交开始时间,成交结束时间)]
|
"""
|
return cls.__total_big_buy_orders_dict.get(code)
|
|
@classmethod
|
def get_big_buy_orders_from_file(cls, code):
|
fdatas = log_export.load_big_buy_order()
|
return fdatas.get(code)
|
|
@classmethod
|
def get_dealing_order_info(cls, code):
|
"""
|
获取当前正在成交的数据
|
@param code:
|
@return: [订单号,总股数,成交金额,成交开始时间,成交结束时间]
|
"""
|
return cls.__dealing_order_info_dict.get(code)
|
|
@classmethod
|
def statistic_big_buy_data(cls, code, datas):
|
"""
|
统计大单买
|
@param code:
|
@param datas:
|
@return: 返回数据里面(成交的大单,50w以上的单)
|
"""
|
big_buy_datas = []
|
normal_buy_datas = []
|
# 大单阈值
|
threshold_big_money = l2_huaxin_util.get_big_money_val(datas[-1][1])
|
for data in datas:
|
# q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'],
|
# data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],
|
# data['SellNo'], data['ExecType']))
|
|
if code not in cls.__dealing_order_info_dict:
|
# 数据格式[订单号,总股数,成交金额,成交开始时间,成交结束时间]
|
cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3], data[3]]
|
if cls.__dealing_order_info_dict[code][0] == data[6]:
|
# 成交同一个订单号
|
cls.__dealing_order_info_dict[code][1] += data[2]
|
cls.__dealing_order_info_dict[code][2] += data[2] * data[1]
|
cls.__dealing_order_info_dict[code][4] = data[3]
|
else:
|
# 设置最近成交完成的一条数据
|
deal_info = cls.__dealing_order_info_dict[code]
|
cls.__latest_deal_order_info_dict[code] = deal_info
|
# 是否为大买单
|
if deal_info[2] >= threshold_big_money:
|
big_buy_datas.append(deal_info)
|
async_log_util.info(hx_logger_l2_transaction_big_buy_order, f"{code}#{deal_info}")
|
if deal_info[2] >= 500000:
|
normal_buy_datas.append(deal_info)
|
# 初始化本条数据
|
cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3], data[3]]
|
if big_buy_datas:
|
if code not in cls.__total_big_buy_orders_dict:
|
cls.__total_big_buy_orders_dict[code] = []
|
cls.__total_big_buy_orders_dict[code].extend(big_buy_datas)
|
|
return big_buy_datas, normal_buy_datas
|