| | |
| | | """ |
| | | import json |
| | | |
| | | import l2_data_util |
| | | from db import redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2 import l2_log |
| | |
| | | |
| | | class BigOrderDealManager: |
| | | """ |
| | | 大单成交管理 |
| | | 成交大单管理 |
| | | """ |
| | | __total_buy_datas_dict = {} |
| | | __total_sell_datas_dict = {} |
| | |
| | | return 0 |
| | | return int(sum([x[2] for x in self.__total_buy_datas_dict[code]])) |
| | | |
| | | def get_total_buy_count(self, code): |
| | | """ |
| | | 获取大单成交的笔数 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code not in self.__total_buy_datas_dict: |
| | | return 0 |
| | | return len(self.__total_buy_datas_dict[code]) |
| | | |
| | | def get_total_buy_money_list(self, code): |
| | | """ |
| | | 获取大单列表 |
| | | @param code: |
| | | @return: |
| | | """ |
| | | if code not in self.__total_buy_datas_dict: |
| | | return 0 |
| | | return [x[2] for x in self.__total_buy_datas_dict[code]] |
| | | |
| | | def get_total_sell_money(self, code): |
| | | """ |
| | | 获取总共的大单卖金额 |
| | |
| | | return cls.__dealing_order_info_dict.get(code) |
| | | |
| | | @classmethod |
| | | def statistic_big_buy_data(cls, code, datas): |
| | | def statistic_big_buy_data(cls, code, datas, limit_up_price): |
| | | """ |
| | | 统计大单买 |
| | | @param code: |
| | |
| | | """ |
| | | big_buy_datas = [] |
| | | normal_buy_datas = [] |
| | | # 大单阈值 |
| | | threshold_big_money = l2_data_util.get_big_money_val(limit_up_price) |
| | | for data in datas: |
| | | # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'], |
| | | # data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'], |
| | |
| | | deal_info = cls.__dealing_order_info_dict[code] |
| | | cls.__latest_deal_order_info_dict[code] = deal_info |
| | | # 是否为大买单 |
| | | if deal_info[2] >= 2990000: |
| | | if deal_info[2] >= threshold_big_money: |
| | | big_buy_datas.append(deal_info) |
| | | if deal_info[2] >= 500000: |
| | | normal_buy_datas.append(deal_info) |
| | |
| | | time_dict.clear() |
| | | |
| | | @classmethod |
| | | def get_latest_2s_continue_deal_volume(cls, code): |
| | | def get_latest_3s_continue_deal_volumes(cls, code): |
| | | """ |
| | | 获取最近连续2s的成交量 |
| | | 获取最近3s的成交量分布 |
| | | @param code: |
| | | @return: 成交量,详细信息 |
| | | @return: [(时间,量)] |
| | | """ |
| | | deal_list = cls.__deal_volume_list_dict.get(code) |
| | | if not deal_list: |
| | | return 0, None |
| | | if len(deal_list) == 0: |
| | | return deal_list[0][1], deal_list |
| | | if tool.trade_time_sub(deal_list[-1][0], deal_list[-2][0]) > 1: |
| | | return deal_list[-1][1], deal_list |
| | | else: |
| | | return deal_list[-1][1] + deal_list[-2][1], deal_list |
| | | return [] |
| | | fdatas = [deal_list[-1]] |
| | | # 从倒数第二个数据计算 |
| | | for i in range(len(deal_list) - 2, -1, -1): |
| | | if tool.trade_time_sub(fdatas[0][0], deal_list[i][0]) < 3: |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | | @classmethod |
| | | def get_latest_2s_continue_deal_volumes(cls, code): |
| | | """ |
| | | 获取最近2s的成交量分布 |
| | | @param code: |
| | | @return: [(时间,量)] |
| | | """ |
| | | deal_list = cls.__deal_volume_list_dict.get(code) |
| | | if not deal_list: |
| | | return [] |
| | | fdatas = [deal_list[-1]] |
| | | # 从倒数第二个数据计算 |
| | | for i in range(len(deal_list) - 1, -1, -1): |
| | | if tool.trade_time_sub(fdatas[0][0], deal_list[i][0]) < 2: |
| | | fdatas.append(deal_list[i]) |
| | | return fdatas |
| | | |
| | | @classmethod |
| | | def clear_latest_deal_volume(cls, code): |
| | | if code in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict.pop(code) |
| | | |
| | | # 返回最近1s的大单卖:(总卖金额,[(卖单号,总手数,价格,('开始时间',买单号),('结束时间',买单号)),...]) |
| | | @classmethod |