From 21d753614ea7bbe936b8560cbf466c4e438821b2 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 23 九月 2022 16:08:16 +0800 Subject: [PATCH] l2数据计算优化 --- juejin.py | 62 ++++++++++++++++++++++++++++-- 1 files changed, 57 insertions(+), 5 deletions(-) diff --git a/juejin.py b/juejin.py index d133d38..2fe4dcb 100644 --- a/juejin.py +++ b/juejin.py @@ -9,6 +9,7 @@ import big_money_num_manager import code_volumn_manager +import data_process import global_util import gpcode_manager import threading @@ -165,13 +166,15 @@ def on_tick(context, tick): + if global_util.TEST: + return # print(tick["created_at"]) relative_timestamp = t.time() % (24 * 60 * 60) + 8 * 60 * 60 # 9鐐�20-15:05鎺ュ彈鏁版嵁 - start1 = 60 * 60 * 9 + 24 * 60; - end1 = 60 * 60 * 11 + 35 * 60; - start2 = 60 * 60 * 12 + 50 * 60; - end2 = 60 * 60 * 15 + 5 * 60; + start1 = 60 * 60 * 9 + 31 * 60 + end1 = 60 * 60 * 11 + 35 * 60 + start2 = 60 * 60 * 12 + 50 * 60 + end2 = 60 * 60 * 15 + 5 * 60 # TODO 娴嬭瘯 if (start1 < relative_timestamp < end1 or start2 < relative_timestamp < end2) or global_util.TEST: symbol = tick['symbol'] @@ -205,6 +208,54 @@ # 绉婚櫎鐩戞帶 if gpcode_manager.is_listen(code) and not gpcode_manager.is_operate(code): L2CodeOperate.get_instance().add_operate(0, code, "鐜颁环鍙樺寲") + + +# 鑾峰彇鍒扮幇浠� +def accpt_prices(prices): + now_str = datetime.datetime.now().strftime("%H:%M:%S") + now_strs = now_str.split(":") + now_second = int(now_strs[0]) * 60 * 60 + int(now_strs[1]) * 60 + int(now_strs[2]) + start = 60 * 60 * 9 + 31 * 60 + if now_second > start: + for d in prices: + code, price = d["code"], float(d["price"]) + accpt_price(code, price) + else: + _code_list = [] + _delete_list = [] + for d in prices: + code, price = d["code"], float(d["price"]) + gpcode_manager.set_price(code, price) + # 鑾峰彇鏀剁洏浠� + pricePre = gpcode_manager.get_price_pre(code) + if pricePre is not None: + rate = round((price - pricePre) * 100 / pricePre, 1) + if rate >= 0: + _code_list.append((rate, code)) + else: + _delete_list.append((rate, code)) + # 鎺掑簭 + new_code_list = sorted(_code_list, key=lambda e: e.__getitem__(0), reverse=True) + client_ids = data_process.getValidL2Clients() + max_count = len(client_ids) * 8 + add_list = new_code_list[:max_count] + _delete_list.extend(new_code_list[max_count:]) + + add_code_list = [] + del_list = [] + for d in add_list: + add_code_list.append(d[1]) + + for d in _delete_list: + del_list.append(d[1]) + + for code in add_code_list: + L2CodeOperate.get_instance().add_operate(1, code, "鐜颁环鍙樺寲") + + for code in del_list: + L2CodeOperate.get_instance().add_operate(0, code, "鐜颁环鍙樺寲") + + print(add_code_list, del_list) def on_bar(context, bars): @@ -325,4 +376,5 @@ if __name__ == '__main__': - everyday_init() + accpt_prices_before_open([{"code": "001332", "price": "82.37"}, {"code": "002246", "price": "10.10"}, + {"code": "600537", "price": "6.65"}]) -- Gitblit v1.8.0