| | |
| | | """ |
| | | |
| | | # 比较时间的大小 |
| | | import datetime |
| | | import json |
| | | import time |
| | | from tool import async_call |
| | | |
| | | import l2_data_manager |
| | | import tool |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from utils.tool import async_call |
| | | |
| | | from l2 import l2_data_manager |
| | | from utils import tool |
| | | |
| | | |
| | | def run_time(): |
| | |
| | | return infunc |
| | | |
| | | return decorator |
| | | |
| | | |
| | | # 是否为大单 |
| | | def is_big_money(val, is_ge=False): |
| | | """ |
| | | 判断是否为大单 |
| | | @param val: l2数据 |
| | | @param is_ge: 是否为创业板 |
| | | @return: |
| | | """ |
| | | price = float(val["price"]) |
| | | money = round(price * val["num"], 2) |
| | | if is_ge: |
| | | if money >= 29900 or val["num"] >= 2999: |
| | | return True |
| | | else: |
| | | return False |
| | | else: |
| | | if price > 3.0: |
| | | if money >= 29900 or val["num"] >= 7999: |
| | | return True |
| | | else: |
| | | return False |
| | | else: |
| | | max_money = price * 10000 |
| | | if money >= max_money * 0.95: |
| | | return True |
| | | else: |
| | | return False |
| | | |
| | | |
| | | # 获取大资金的金额 |
| | | def get_big_money_val(limit_up_price, is_ge=False): |
| | | if is_ge: |
| | | return min(299 * 10000, round(limit_up_price * 2900 * 100)) |
| | | else: |
| | | if limit_up_price > 3.0: |
| | | return min(299 * 10000, round(limit_up_price * 7999 * 100)) |
| | | else: |
| | | max_money = limit_up_price * 10000 * 100 |
| | | return int(max_money * 0.95) |
| | | |
| | | # if int(val["num"]) >= constant.BIG_MONEY_NUM: |
| | | # return True |
| | | # if int(val["num"]) * limit_up_price >= constant.BIG_MONEY_AMOUNT: |
| | | # return True |
| | | # return False_ |
| | | |
| | | |
| | | def compare_time(time1, time2): |
| | |
| | | json_value = json.loads(value) |
| | | _data = {"key": key, "val": item, "re": json_value["re"], "index": int(json_value["index"])} |
| | | return _data |
| | | |
| | | |
| | | # 将数据根据num-operate分类 |
| | | def load_num_operate_map(local_today_num_operate_map, code, source_datas, clear=False): |
| | | if local_today_num_operate_map.get(code) is None: |
| | | local_today_num_operate_map[code] = {} |
| | | if clear: |
| | | local_today_num_operate_map[code] = {} |
| | | |
| | | for data in source_datas: |
| | | key = "{}-{}-{}".format(data["val"]["num"], data["val"]["operateType"], data["val"]["price"]) |
| | | if local_today_num_operate_map[code].get(key) is None: |
| | | local_today_num_operate_map[code].setdefault(key, []) |
| | | local_today_num_operate_map[code].get(key).append(data) |
| | | |
| | | |
| | | # 减去时间 |
| | |
| | | max_time = __sub_time(cancel_data["val"]["time"], min_space) |
| | | min_time = __sub_time(cancel_data["val"]["time"], max_space) |
| | | return min_time, max_time |
| | | |
| | | |
| | | # 根据买撤数据(与今日总的数据)计算买入数据 |
| | | def get_buy_data_with_cancel_data(cancel_data, local_today_num_operate_map): |
| | | 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) |
| | | buy_datas = local_today_num_operate_map.get( |
| | | "{}-{}-{}".format(cancel_data["val"]["num"], "0", cancel_data["val"]["price"])) |
| | | 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 min_space == 0 and max_space == 0: |
| | | if compare_time(data["val"]["time"], min_time) == 0: |
| | | return data["index"], data |
| | | |
| | | elif compare_time(data["val"]["time"], min_time) > 0 and compare_time(data["val"]["time"], max_time) <= 0: |
| | | return data["index"], data |
| | | return None, None |
| | | |
| | | |
| | | # 判断卖撤的卖信号是否在目标信号之前 |
| | |
| | | # 保存快照 |
| | | # logger_l2_big_data.debug("code:{} d1:{} d2:{}", code, d1[i - 60: i + 30], d2[i - 60: i + 30]) |
| | | break |
| | | time_str = datetime.datetime.now().strftime("%H:%M:%S") |
| | | time_str = tool.get_now_time_str() |
| | | |
| | | for time_ in same_time_nums: |
| | | # 只保留最近3s内的大数据 |
| | | if abs(get_time_as_seconds(time_str) - get_time_as_seconds(time_)) > 3: |
| | | continue |
| | | if same_time_nums[time_] > 20: |
| | | redis = l2_data_manager._redisManager.getRedis() |
| | | redis.setex("big_data-{}-{}".format(code, int(round(time.time() * 1000))), tool.get_expire(), d1) |
| | | RedisUtils.setex(l2_data_manager._redisManager.getRedis(), |
| | | "big_data-{}-{}".format(code, int(round(time.time() * 1000))), tool.get_expire(), |
| | | d1) |
| | | break |
| | | |
| | | |
| | | # 保存l2最新数据的大小 |
| | | @async_call |
| | | # @async_call |
| | | def save_l2_latest_data_number(code, num): |
| | | redis = l2_data_manager._redisManager.getRedis() |
| | | redis.setex("l2_latest_data_num-{}".format(code), 3, num) |
| | | RedisUtils.setex(l2_data_manager._redisManager.getRedis(), "l2_latest_data_num-{}".format(code), 3, num) |
| | | |
| | | |
| | | # 获取最新数据条数 |
| | | def get_l2_latest_data_number(code): |
| | | redis = l2_data_manager._redisManager.getRedis() |
| | | num = redis.get("l2_latest_data_num-{}".format(code)) |
| | | num = RedisUtils.get(l2_data_manager._redisManager.getRedis(), "l2_latest_data_num-{}".format(code)) |
| | | if num is not None: |
| | | return int(num) |
| | | return None |
| | | |
| | | |
| | | # l2数据拼接工具 TODO 暂时还未启用 |
| | | # l2数据拼接工具 暂时还未启用 |
| | | class L2DataConcatUtil: |
| | | |
| | | # 初始化 |