From 3cfa1332c0807a74b4ac5a2150500841f5299147 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 08 三月 2023 22:54:09 +0800 Subject: [PATCH] 首板加入,安全笔数与H撤笔数优化 --- server.py | 159 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 142 insertions(+), 17 deletions(-) diff --git a/server.py b/server.py index aad4ae7..df38144 100644 --- a/server.py +++ b/server.py @@ -16,6 +16,7 @@ import data_process import global_data_loader import global_util +import gpcode_first_screen_manager import gpcode_manager import authority import juejin @@ -27,13 +28,13 @@ import ths_industry_util import ths_util import tool -from trade import trade_gui, trade_data_manager, trade_manager +from trade import trade_gui, trade_data_manager, trade_manager, l2_trade_util import l2_code_operate from code_data_util import ZYLTGBUtil import l2.transaction_progress from log import logger_l2_error, logger_device, logger_trade_delegate, logger_buy_1_volumn_record, \ - logger_l2_trade_queue, logger_l2_latest_data, logger_l2_trade_buy_queue + logger_l2_trade_queue, logger_l2_latest_data, logger_l2_trade_buy_queue, logger_first_code_record from trade.trade_queue_manager import THSBuy1VolumnManager, Buy1PriceManager, thsl2tradequeuemanager @@ -46,6 +47,9 @@ # 濡傛灉浣跨敤寮傛鐨勫舰寮忓垯闇�瑕佸啀閲嶅啓ThreadingTCPServer class MyThreadingTCPServer(socketserver.ThreadingMixIn, MyTCPServer): pass + + +# 棣栨澘tick绾ф暟鎹� class MyBaseRequestHandle(socketserver.BaseRequestHandler): @@ -61,6 +65,7 @@ l2_trade_buy_queue_dict = {} tradeBuyQueue = l2.transaction_progress.TradeBuyQueue() last_time = {} + first_tick_datas = [] def setup(self): super().setup() # 鍙互涓嶈皟鐢ㄧ埗绫荤殑setup()鏂规硶锛岀埗绫荤殑setup鏂规硶浠�涔堥兘娌″仛 @@ -104,10 +109,11 @@ day, client, channel, code, capture_time, process_time, datas, origin_datas = l2.l2_data_util.parseL2Data( _str) l2_log.threadIds[code] = random.randint(0, 100000) + if channel == 0: now_time = round(time.time() * 1000) if self.last_time.get(channel) is not None: - #print("鎺ュ彈鍒癓2鐨勬暟鎹�", channel, now_time - self.last_time.get(channel), "瑙f瀽鑰楁椂",now_time - origin_start_time) + # print("鎺ュ彈鍒癓2鐨勬暟鎹�", channel, now_time - self.last_time.get(channel), "瑙f瀽鑰楁椂",now_time - origin_start_time) pass self.last_time[channel] = now_time @@ -179,6 +185,7 @@ True) except Exception as e: logger_l2_error.exception(e) + elif type == 1: # 璁剧疆鑲$エ浠g爜 data_list, is_add = data_process.parseGPCode(_str) @@ -222,6 +229,101 @@ # 鑾峰彇鏄惁鏈夋定鍋滄椂闂� # if limit_up_time_manager.get_limit_up_time(d["code"]) is None: # limit_up_time_manager.save_limit_up_time(d["code"], d["time"]) + elif type == 22: + try: + if int(tool.get_now_time_str().replace(":", "")) < int("092600"): + raise Exception('鏈埌鎺ュ彈鏃堕棿') + # 棣栨澘浠g爜 + dataList, is_add = data_process.parseGPCode(_str) + # {'code': '605300', 'limitUpPercent': '0009.99', 'price': '0020.14', 'time': '10:44:00', 'volume': '44529', 'volumeUnit': 2, 'zyltMoney': '0011.60', 'zyltMoneyUnit': 0} + limit_up_price_dict = {} + temp_codes = [] + codes = [] + tick_datas = [] + if dataList: + for data in dataList: + code = data["code"] + codes.append(code) + limit_up_price = gpcode_manager.get_limit_up_price(code) + if limit_up_price is not None: + limit_up_price_dict[code] = limit_up_price + else: + temp_codes.append(code) + # data["price"] + tick_datas.append({"code": code, "price": data["price"], "volumn": data["volume"], + "volumnUnit": data["volumeUnit"]}) + # 淇濆瓨鏈瓫閫夌殑棣栨澘浠g爜 + new_add_codes = gpcode_first_screen_manager.set_target_no_screen_codes(codes) + for code in new_add_codes: + if (not l2_trade_util.is_in_forbidden_trade_codes(code)) and juejin.JueJinManager.get_lowest_price_rate(code, 15) >= 0.3: + l2_trade_util.forbidden_trade(code) + + if new_add_codes: + gpcode_manager.set_first_gp_codes_with_data(juejin.JueJinManager.get_gp_latest_info(codes)) + # 鍔犲叆棣栨澘鍘嗗彶璁板綍 + gpcode_manager.FirstCodeManager.add_record(new_add_codes) + logger_first_code_record.info("鏂板棣栨澘锛歿}",new_add_codes) + # 鑾峰彇60澶╂渶澶ц褰� + for code in new_add_codes: + if code not in global_util.max60_volumn or global_util.max60_volumn.get(code) is None: + volumes = juejin.get_volumn(code) + code_volumn_manager.set_histry_volumn(code,volumes[0],volumes[1]) + + if temp_codes: + # 鑾峰彇娑ㄥ仠浠� + juejin.re_set_price_pres(temp_codes) + # 閲嶆柊鑾峰彇娑ㄥ仠浠� + for code in temp_codes: + limit_up_price = gpcode_manager.get_limit_up_price(code) + if limit_up_price is not None: + limit_up_price_dict[code] = limit_up_price + # 淇濆瓨鑷敱娴侀�氳偂鏈� + zyltgb_list = [] + for data in dataList: + code = data["code"] + if code in global_util.zyltgb_map: + continue + zyltgb_list.append( + {"code": code, "zyltgb": data["zyltMoney"], "zyltgb_unit": data["zyltMoneyUnit"]}) + if zyltgb_list: + ZYLTGBUtil.save_list(zyltgb_list) + global_data_loader.load_zyltgb() + + # 淇濆瓨鐜颁环 + self.first_tick_datas.clear() + self.first_tick_datas.extend(tick_datas) + + # 棣栨澘鏁版嵁鍔犲伐 + prices = [] + for data in dataList: + code = data["code"] + price = data["price"] + limit_up_time = data["time"] + if limit_up_time == "00:00:00": + limit_up_time = None + if code not in limit_up_price_dict: + continue + is_limit_up = abs(float(limit_up_price_dict[code]) - float(price)) < 0.01 + # 绾犳鏁版嵁 + if is_limit_up and limit_up_time is None: + limit_up_time = tool.get_now_time_str() + pricePre = gpcode_manager.get_price_pre(code) + rate = round((float(price) - pricePre) * 100 / pricePre, 1) + prices.append( + {"code": code, "time": limit_up_time, "rate": rate, + "limit_up": is_limit_up}) + if code in new_add_codes: + if is_limit_up: + place_order_count = trade_data_manager.placeordercountmanager.get_place_order_count( + code) + if place_order_count == 0: + trade_data_manager.placeordercountmanager.place_order(code) + # 鍔犲叆棣栨澘娑ㄥ仠 + gpcode_manager.FirstCodeManager.add_limited_up_record([code]) + + gpcode_first_screen_manager.process_ticks(prices) + except Exception as e: + pass elif type == 3: # 浜ゆ槗鎴愬姛淇℃伅 @@ -277,7 +379,17 @@ elif type == 4: # 琛屼笟浠g爜淇℃伅 dataList = data_process.parseList(_str) - ths_industry_util.save_industry_code(dataList) + codes = [] + for datas in dataList: + for d in datas: + name = ths_industry_util.get_name_by_code(d['code']) + if not name or name == 'None': + codes.append(d["code"]) + # 鏍规嵁浠g爜鑾峰彇浠g爜鍚嶇О + codes_name = {} + if codes: + codes_name = juejin.JueJinManager.get_gp_codes_names(codes) + ths_industry_util.save_industry_code(dataList, codes_name) elif type == 6: # 鍙敤閲戦 datas = data_process.parseData(_str) @@ -313,13 +425,17 @@ code) if buy_exec_index: try: - exec_time = l2.l2_data_util.local_today_datas.get(code)[buy_exec_index]["val"]["time"] + exec_time = l2.l2_data_util.local_today_datas.get(code)[buy_exec_index]["val"][ + "time"] except: pass - buy_progress_index = self.tradeBuyQueue.compute_traded_index(code, buy_one_price_, buy_queue_result_list,exec_time) + buy_progress_index = self.tradeBuyQueue.compute_traded_index(code, buy_one_price_, + buy_queue_result_list, + exec_time) if buy_progress_index is not None: - HourCancelBigNumComputer.set_trade_progress(code,buy_time,buy_exec_index, buy_progress_index, + HourCancelBigNumComputer.set_trade_progress(code, buy_time, buy_exec_index, + buy_progress_index, l2.l2_data_util.local_today_datas.get( code), l2.l2_data_util.local_today_num_operate_map.get( @@ -348,8 +464,8 @@ need_sync, need_cancel, cancel_msg = self.buy1_volumn_manager.save(code, buy_time, int(buy_one_volumn), buy_one_price) - if need_cancel: - l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, cancel_msg, "trade_queue") + #if need_cancel: + # l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, cancel_msg, "trade_queue") if need_sync: # 鍚屾鏁版嵁 L2LimitUpMoneyStatisticUtil.verify_num(code, int(buy_one_volumn), buy_time) @@ -367,14 +483,17 @@ return_str = data_process.toJson({"code": 1, "msg": str(e)}) # 鐜颁环鏇存柊 elif type == 40: - data = data_process.parse(_str)["data"] - if data is not None: - print("鐜颁环鏁伴噺", len(data)) - for item in data: + datas = data_process.parse(_str)["data"] + # 鑾峰彇鏆傚瓨鐨勪簩鐗堢幇浠锋暟鎹� + if datas and self.first_tick_datas: + datas.extend(self.first_tick_datas) + if datas is not None: + print("鐜颁环鏁伴噺", len(datas)) + for item in datas: volumn = item["volumn"] volumnUnit = item["volumnUnit"] code_volumn_manager.save_today_volumn(item["code"], volumn, volumnUnit) - juejin.accept_prices(data) + juejin.accept_prices(datas) elif type == 50: data = data_process.parse(_str)["data"] if data is not None: @@ -400,8 +519,8 @@ # 淇濆瓨鏁版嵁 need_sync, need_cancel, cancel_msg = self.buy1_volumn_manager.save(code, time_, volumn, price) - if need_cancel: - l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, cancel_msg, "trade_queue") + #if need_cancel: + # l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, cancel_msg, "trade_queue") if need_sync: # 鍚屾鏁版嵁 L2LimitUpMoneyStatisticUtil.verify_num(code, volumn, time_) @@ -453,6 +572,12 @@ else: return_json = {"code": 0, "msg": "寮�鍚湪绾跨姸鎬�"} return_str = json.dumps(return_json) + elif type == 201: + data = json.loads(_str) + codes = data["data"]["codes"] + for code in codes: + l2_trade_util.forbidden_trade(code) + return_str = json.dumps({"code": 0}) sk.send(return_str.encode()) @@ -515,7 +640,7 @@ # 鍚屾鐩爣鏍囩殑鍒板悓鑺遍『 def sync_target_codes_to_ths(): - codes = gpcode_manager.get_gp_list() + codes = gpcode_manager.get_second_gp_list() code_list = [] for code in codes: code_list.append(code) -- Gitblit v1.8.0