| | |
| | | # l2数据工具 |
| | | # 比较时间的大小 |
| | | import hashlib |
| | | import json |
| | | import time |
| | | |
| | | import l2_data_manager |
| | | import tool |
| | | from log import logger_l2_trade, logger_l2_big_data |
| | | from trade_gui import async_call |
| | | |
| | | |
| | | def compare_time(time1, time2): |
| | |
| | | return time_seconds |
| | | |
| | | |
| | | |
| | | # 计算时间的区间 |
| | | def __compute_time_space_as_second(cancel_time, cancel_time_unit): |
| | | __time = int(cancel_time) |
| | |
| | | |
| | | |
| | | # 根据买撤数据(与今日总的数据)计算买入数据 |
| | | def get_buy_data_with_cancel_data(cancel_data, today_datas): |
| | | def get_buy_data_with_cancel_data(cancel_data): |
| | | # 计算时间区间 |
| | | min_space, max_space = __compute_time_space_as_second(cancel_data["val"]["cancelTime"], |
| | | cancel_data["val"]["cancelTimeUnit"]) |
| | | max_time = __sub_time(cancel_data["val"]["time"], min_space) |
| | | min_time = __sub_time(cancel_data["val"]["time"], max_space) |
| | | |
| | | for data in today_datas: |
| | | buy_datas = l2_data_manager.local_today_num_operate_map.get("{}-{}".format(cancel_data["val"]["num"], "0")) |
| | | if buy_datas is None: |
| | | # 无数据 |
| | | return None, None |
| | | for i in range(0, len(buy_datas)): |
| | | data = buy_datas[i] |
| | | if int(data["val"]["operateType"]) != 0: |
| | | continue |
| | | if int(data["val"]["num"]) != int(cancel_data["val"]["num"]): |
| | | continue |
| | | if compare_time(data["val"]["time"], min_time) > 0 and compare_time(data["val"]["time"], max_time) <= 0: |
| | | return data |
| | | return None |
| | | return data["index"], data |
| | | return None, None |
| | | |
| | | |
| | | __last_big_data = {} |
| | | |
| | | |
| | | @async_call |
| | | def save_big_data(code, same_time_nums, datas): |
| | | latest_datas = __last_big_data.get(code) |
| | | d1 = json.dumps(datas) |
| | | d2 = json.dumps(latest_datas) |
| | | if latest_datas is not None and d1.strip() == d2.strip(): |
| | | return None |
| | | __last_big_data[code] = datas |
| | | # 获取不一样的快照 |
| | | if latest_datas is not None: |
| | | for i in range(len(d1)): |
| | | if d1[i] != d2[i]: |
| | | # 保存快照 |
| | | logger_l2_big_data.debug("code:{} d1:{} d2:{}", code, d1[i - 60: i + 30], d2[i - 60: i + 30]) |
| | | break |
| | | |
| | | for key in same_time_nums: |
| | | if same_time_nums[key] > 20: |
| | | redis = l2_data_manager._redisManager.getRedis() |
| | | redis.setex("big_data-{}-{}".format(code, int(round(time.time() * 1000))), tool.get_expire(), d1) |
| | | break |
| | | |
| | | |
| | | def test(datas): |
| | |
| | | # today_datas=[{"val": {"operateType": 1, "num": 1520, "cancelTime": 1, "cancelTimeUnit": 0, "time": "09:32:30"}},{"val": {"operateType": 0, "num": 1520, "cancelTime": 0, "cancelTimeUnit": 0, "time": "09:31:31"}}] |
| | | # result= get_buy_data_with_cancel_data(cancel_data,today_datas) |
| | | # print(result) |
| | | __datas = {} |
| | | test(__datas) |
| | | print(__datas) |
| | | redis = l2_data_manager._redisManager.getRedis() |
| | | keys = redis.keys("big_data-*") |
| | | for k in keys: |
| | | redis.delete(k) |