| | |
| | | """ |
| | | 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: |
| | | @param datas: |
| | | @return: 返回数据里面成交的大单 |
| | | @return: 返回数据里面(成交的大单,50w以上的单) |
| | | """ |
| | | 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) |
| | | |
| | | # 初始化本条数据 |
| | | cls.__dealing_order_info_dict[code] = [data[6], data[2], data[2] * data[1], data[3], data[3]] |
| | | return big_buy_datas |
| | | return big_buy_datas, normal_buy_datas |
| | | |
| | | |
| | | # 卖单统计数据 |
| | |
| | | # 初始化本条数据 |
| | | cls.__dealing_order_info_dict[code] = [data[7], data[2], data[2] * data[1]] |
| | | return big_sell_datas |
| | | |
| | | # 统计所有的成交量 |
| | | __deal_volume_list_dict = {} |
| | | |
| | | @classmethod |
| | | def statistic_total_deal_volume(cls, code, datas): |
| | | # 只统计被动买 |
| | | if code not in cls.__deal_volume_list_dict: |
| | | cls.__deal_volume_list_dict[code] = [] |
| | | time_dict = {} |
| | | for d in datas: |
| | | # 只统计被动买 |
| | | if d[7] < d[6]: |
| | | continue |
| | | time_str = '' |
| | | if d[3] in time_dict: |
| | | time_str = time_dict[d[3]] |
| | | else: |
| | | time_dict[d[3]] = l2_huaxin_util.convert_time(d[3]) |
| | | time_str = time_dict[d[3]] |
| | | if cls.__deal_volume_list_dict[code]: |
| | | if cls.__deal_volume_list_dict[code][-1][0] == time_str: |
| | | # 如果是同一秒 |
| | | cls.__deal_volume_list_dict[code][-1][1] += d[2] |
| | | else: |
| | | # 不是同一秒 |
| | | cls.__deal_volume_list_dict[code].append([time_str, d[2]]) |
| | | else: |
| | | cls.__deal_volume_list_dict[code].append([time_str, d[2]]) |
| | | # 删除超过5条数据 |
| | | if len(cls.__deal_volume_list_dict[code]) > 5: |
| | | cls.__deal_volume_list_dict[code] = cls.__deal_volume_list_dict[code][-5:] |
| | | time_dict.clear() |
| | | |
| | | @classmethod |
| | | def get_latest_3s_continue_deal_volumes(cls, code): |
| | | """ |
| | | 获取最近3s的成交量分布 |
| | | @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) - 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 |
| | |
| | | |
| | | # 获取最近成交数据 |
| | | @classmethod |
| | | def get_latest_transaction_datas(cls, code, min_sell_order_no=None, min_deal_time=None): |
| | | def get_latest_transaction_datas(cls, code, min_sell_order_no=None, min_deal_time=None, min_sell_money=None): |
| | | """ |
| | | 获取最近的主动卖成交信息 |
| | | @param code: |
| | | @param min_sell_order_no: |
| | | @param min_deal_time: |
| | | @param min_sell_money: |
| | | @return: |
| | | """ |
| | | total_orders = [] |
| | | sell_orders = cls.__latest_all_sell_orders_dict.get(code) |
| | | if sell_orders: |
| | |
| | | |
| | | if min_sell_order_no and min_sell_order_no > sell_orders[i][0]: |
| | | continue |
| | | if min_sell_money and sell_orders[i][1] * sell_orders[i][2] < min_sell_money: |
| | | # 过滤小金额 |
| | | continue |
| | | |
| | | total_orders.append(sell_orders[i]) |
| | | if code in cls.__latest_sell_order_dict: |
| | | if min_sell_order_no: |