From 48fb7a00951f91bdc707e5dd2d196e5bccb752c3 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 18 六月 2025 18:41:30 +0800 Subject: [PATCH] 异常保护 --- inited_data.py | 276 +++++++++---------------------------------------------- 1 files changed, 46 insertions(+), 230 deletions(-) diff --git a/inited_data.py b/inited_data.py index ff0753b..33d8497 100644 --- a/inited_data.py +++ b/inited_data.py @@ -4,55 +4,22 @@ from __future__ import print_function, absolute_import -import schedule - -import gm.api as gmapi - +from cancel_strategy.s_l_h_cancel_strategy import LCancelBigNumComputer from code_attribute import big_money_num_manager, global_data_loader, gpcode_manager, gpcode_first_screen_manager -from db.redis_manager import RedisUtils -from ths import client_manager -import constant -from utils import global_util, tool -import threading +from code_attribute.code_nature_analyse import LatestMaxVolumeManager, HighIncreaseCodeManager, CodeNatureRecordManager +from l2.l2_sell_manager import L2MarketSellManager +from l2.l2_transaction_data_manager import HuaXinBuyOrderManager +from third_data.third_blocks_manager import InvalidBlockManager, CodeThirdBlocksManager +from trade.buy_money_count_setting import BuyMoneyAndCountSetting +from trade.deal_big_money_manager import DealOrderNoManager +from trade.trade_manager import AutoCancelSellModeManager +from utils import tool -import server - -from db import redis_manager -from user import authority -import decimal - -from third_data.history_k_data_util import HistoryKDatasUtils -from trade import l2_trade_util, trade_manager -from l2.cancel_buy_strategy import L2LimitUpSellStatisticUtil, LCancelBigNumComputer, DCancelBigNumComputer -from log_module.log import logger_juejin_tick, logger_system -from trade.trade_data_manager import CodeActualPriceProcessor -from trade.trade_queue_manager import JueJinBuy1VolumnManager - -redisManager = redis_manager.RedisManager(0) -__jueJinBuy1VolumnManager = JueJinBuy1VolumnManager() -__actualPriceProcessor = CodeActualPriceProcessor() - - -# 璁剧疆璐︽埛淇℃伅 -def setAccountInfo(accountId, strategyId, token): - redis = redisManager.getRedis() - try: - RedisUtils.set(redis, "juejin-account-id", accountId, auto_free=False) - RedisUtils.set(redis, "juejin-strategy-id", strategyId, auto_free=False) - RedisUtils.set(redis, "juejin-token", token, auto_free=False) - finally: - RedisUtils.realse(redis) - - -def getAccountInfo(): - redis = redisManager.getRedis() - try: - account_id = RedisUtils.get(redis, "juejin-account-id", auto_free=False) - strategy_id = RedisUtils.get(redis, "juejin-strategy-id", auto_free=False) - token = RedisUtils.get(redis, "juejin-token", auto_free=False) - return account_id, strategy_id, token - finally: - RedisUtils.realse(redis) +from trade import l2_trade_util +from l2.cancel_buy_strategy import L2LimitUpSellStatisticUtil +from log_module.log import logger_system +from trade.trade_data_manager import PlaceOrderCountManager, AccountMoneyManager +from utils.ths_industry_util import ThsCodeIndustryManager def init_data(): @@ -60,37 +27,57 @@ L2LimitUpSellStatisticUtil().clear() # 閲嶇疆鎵�鏈夌殑澶у崟鏁版嵁 big_money_num_manager.reset_all() - # 娓呴櫎姘翠笅鎹炴暟鎹� - __actualPriceProcessor.clear_under_water_data() # 杞藉叆琛屼笟鑲$エ浠g爜 global_data_loader.load_industry() # 杞藉叆浠g爜鑷敱娴侀�氬競鍊� global_data_loader.load_zyltgb() # 杞藉叆閲� global_data_loader.load_volumn() + # 鍒濆鍖栬浇鍏� + AccountMoneyManager() + # 鍒濆鍖栬浇鍏� + AutoCancelSellModeManager() + + ThsCodeIndustryManager() + + InvalidBlockManager() + + CodeThirdBlocksManager() + + BuyMoneyAndCountSetting() + + gpcode_manager.WantBuyCodesManager() # 9鐐�25涔嬪墠鍒犻櫎鎵�鏈変唬鐮� - if tool.trade_time_sub(tool.get_now_time_str(), "09:25:00") <= 0 or True: + if tool.trade_time_sub(tool.get_now_time_str(), "09:25:00") <= 0: # 鍒犻櫎L2鐩戝惉浠g爜 gpcode_manager.clear_listen_codes() # 鍒犻櫎棣栨澘浠g爜 gpcode_manager.clear_first_codes() # 鍒犻櫎棣栨澘鏈瓫閫変唬鐮� - gpcode_first_screen_manager.clear_first_no_screen_codes() + gpcode_first_screen_manager.FirstNoScreenCodesManager().clear_first_no_screen_codes() # 鍒犻櫎绂佹浠g爜 l2_trade_util.init_forbidden_trade_codes() # 娓呯┖鐧藉悕鍗� - l2_trade_util.WhiteListCodeManager().clear() + gpcode_manager.WhiteListCodeManager().clear() # 娓呯┖鎯宠涔� gpcode_manager.WantBuyCodesManager().clear() - # 娓呯┖鍒嗘暟绂佹浠g爜 - trade_manager.ForbiddenBuyCodeByScoreManager().clear() # 娓呯┖鏆傚仠浜ゆ槗浠g爜 gpcode_manager.PauseBuyCodesManager().clear() # 娓呴櫎L鎾ゆ暟鎹� LCancelBigNumComputer().clear() - # 娓呴櫎D鎾ゆ暟鎹� - DCancelBigNumComputer().clear() + # 娓呴櫎澶у崟鎴愪氦鏁版嵁 + DealOrderNoManager().clear() + # 鏈�杩戞槸鍚︽湁鏈�澶ч噺 + LatestMaxVolumeManager().clear() + # L2鍗栬鎯呮竻闄� + L2MarketSellManager().clear() + # 娑ㄥ箙杩囬珮浠g爜 + HighIncreaseCodeManager().clear() + # 鑲℃�ф竻闄� + CodeNatureRecordManager().clear() + # 涓嬪崟娆℃暟娓呴櫎 + PlaceOrderCountManager().clear() # 姣忔棩鍒濆鍖� @@ -99,183 +86,12 @@ # if not tool.is_init_time() or True: # raise Exception("浜ゆ槗鏃堕棿涓嶈兘鍒濆鍖�") init_data() - codes = gpcode_manager.get_gp_list() logger_system.info("姣忔棩鍒濆鍖�") - # 浠婃棩瀹炴椂娑ㄥ仠 - global_data_loader.add_limit_up_codes([], True) - # 涓昏鑾峰彇鏀剁洏浠� - __get_latest_info(None) - # 鑾峰彇60澶╂渶澶ч噺涓庢槰鏃ラ噺 - global_util.today_volumn.clear() - global_util.max60_volumn.clear() - global_util.yesterday_volumn.clear() - # 娓呴櫎澶у崟鏁版嵁 - global_util.big_money_num.clear() - # 鍒濆鍖栧ぇ鍗曟暟鎹� - for code in codes: - big_money_num_manager.add_num(code, 0) - big_money_num_manager.expire(code) - # 娓呴櫎娑ㄥ仠鏃堕棿 - global_util.limit_up_time.clear() - # 鍒濆鍖栧悓鑺遍『涓荤珯 - if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: - l2_clients = client_manager.getValidL2Clients() - for client in l2_clients: - try: - server.repair_ths_main_site(client) - except Exception as e: - pass - - -def __run_schedule(): - while True: - schedule.run_pending() - - -def init(context): - # gmapi.subscribe(symbols="SZSE.002529", frequency="1d", count=30) - # 璁㈤槄娴﹀彂閾惰, bar棰戠巼涓轰竴澶╁拰涓�鍒嗛挓 - # 璁㈤槄璁㈤槄澶氫釜棰戠巼鐨勬暟鎹紝鍙娆¤皟鐢╯ubscribe - # 鑾峰彇闇�瑕佺洃鍚殑鑲$エ - init_data() - logger_system.info("鎺橀噾鍒濆鍖�") - schedule.every().day.at("09:15:00").do(everyday_init) - t1 = threading.Thread(target=lambda: __run_schedule()) - # 鍚庡彴杩愯 - t1.setDaemon(True) - t1.start() - - # 澶氫釜鏃堕棿鐐硅幏鍙栨敹鐩樹环 - gmapi.schedule(schedule_func=__get_latest_info, date_rule='1d', time_rule='09:28:00') - - # 鍒濆鍖栧唴瀹� - clients = authority.get_l2_clients() - for client in clients: - for i in range(0, constant.L2_CODE_COUNT_PER_DEVICE): - gpcode_manager.init_listen_code_by_pos(client, i) - - -def __get_latest_info(context): - # 鍒濆鍖栧唴瀹� - clients = authority.get_l2_clients() - for c in clients: - for i in range(0, constant.L2_CODE_COUNT_PER_DEVICE): - gpcode_manager.init_listen_code_by_pos(int(c), i) - codes = gpcode_manager.get_gp_list() - result = HistoryKDatasUtils.get_gp_latest_info(codes) - for item in result: - sec_level = item['sec_level'] - symbol = item['symbol'] - symbol = symbol.split(".")[1] - pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) - if sec_level == 1: - if symbol in codes: - gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close) - else: - gpcode_manager.rm_gp(symbol) - - -# 鑾峰彇鏈�鏂扮殑淇℃伅 -def __get_current_info(): - data = gpcode_manager.get_gp_list() - results = HistoryKDatasUtils.get_gp_current_info(data) - logger_juejin_tick.debug("瀹氭椂鑾峰彇锛歿}", results) - for result in results: - price = result["price"] - symbol = result['symbol'] - # 淇濆瓨鏈�鏂颁环 - symbol = symbol.split(".")[1] - - -# 璁剧疆鏀剁洏浠� -def re_set_price_pre(code): - codes = [code] - re_set_price_pres(codes) - - -def re_set_price_pres(codes, force=False): - result = HistoryKDatasUtils.get_gp_latest_info(codes) - for item in result: - symbol = item['symbol'] - symbol = symbol.split(".")[1] - pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) - gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force) - - -__prices_now = {} - - -# 鑾峰彇杩�90澶╃殑鏈�澶ч噺涓庢渶杩戠殑閲� -# 鑾峰彇鏈�杩戜竴娆℃定鍋�/娑ㄥ仠涓嬩竴涓氦鏄撴棩鐨勬渶澶у�� -def get_volumns_by_code(code, count=60) -> object: - datas = HistoryKDatasUtils.get_history_tick_n(code, count, "open,high,low,close,volume,pre_close,bob") - # 璁$畻 - datas.sort(key=lambda x: x["bob"], reverse=True) - return datas - - -# 瑙f瀽鏈�澶ч噺 -def parse_max_volume(datas, is_new_top=False): - max_volume = 0 - - max_volume_date = None - if is_new_top: - # 濡傛灉鏄獊鐮村墠楂樺氨鍙栨渶澶ч噺 - for item in datas: - if max_volume < item["volume"]: - max_volume = item["volume"] - max_volume_date = item["bob"] - return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d") - else: - - date = None - target_volume = None - for i in range(len(datas)): - # 鏌ヨ娑ㄥ仠 - item = datas[i] - volume = item["volume"] - if max_volume < volume: - max_volume = volume - max_volume_date = item['bob'] - # 鏄惁鏈夋定鍋� - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) - if abs(limit_up_price - item["high"]) < 0.01: - # 娑ㄥ仠 - next_volume = 0 - if i > 0: - next_volume = datas[i - 1]["volume"] - date = datas[i]["bob"] - if volume < next_volume: - volume = next_volume - date = datas[i - 1]["bob"] - target_volume = (volume, date) - break - if not target_volume: - target_volume = (max_volume, max_volume_date) - - # --鍒ゆ柇杩�60澶╂棤娑ㄥ仠鐨勬渶澶ч噺 - max_60_volume_info = [0, None] - # 60澶╁唴鏄惁鏈夋定鍋� - has_60_limit_up = False - for i in range(60): - if i >= len(datas): - break - item = datas[i] - volume = item["volume"] - if max_60_volume_info[0] < volume: - max_60_volume_info = [volume, item["bob"]] - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) - if abs(limit_up_price - item["high"]) < 0.01: - has_60_limit_up = True - break - - if not has_60_limit_up and target_volume[0] > max_60_volume_info[0] * 3: - # 60澶╁唴鏃犳定鍋�,涓�60澶╁唴鏈�澶ч噺灏忎簬鏈�澶ч噺鐨�1/3,鍒ゆ柇涓哄湴閲�,杩斿洖杩�60涓氦鏄撴棩鐨勬渶澶ч噺 - return max_60_volume_info[0], max_60_volume_info[0], max_60_volume_info[1].strftime("%Y-%m-%d") - else: - return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d") +# 淇濆瓨杩愯鏃舵暟鎹� +def save_running_data(): + HuaXinBuyOrderManager().sync_dealing_data_to_db() if __name__ == '__main__': -- Gitblit v1.8.0