| | |
| | | from strategy import l1_data_api |
| | | from strategy import data_cache |
| | | from strategy import basic_methods |
| | | from strategy import buying_strategy |
| | | from strategy import selling_strategy |
| | | from strategy import buying_strategy, selling_strategy, index_market_trend_strategy |
| | | |
| | | # from low_suction.shared_memory_util import SharedMemoryObj |
| | | |
| | | # 获取logger实例 |
| | |
| | | ''' |
| | | 创建一个函数来对主要指数的实时行情作处理 |
| | | ''' |
| | | def index_market_trend(current_info): |
| | | if current_info is not None: |
| | | pass |
| | | # 设定当前时间点 |
| | | # now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | symbol_code = current_info[0] # 券商接口为纯数字编号 |
| | | symbol = basic_methods.format_stock_symbol(symbol_code) # 掘金数据来源的股票代码 |
| | | # symbol_code = symbol.split('.')[1] # 将掘金格式的股票代码转化为纯数字类型 |
| | | # pre_close = current_info[1] # 昨日收盘价 |
| | | current_price = current_info[2] # 获取当前最新价 |
| | | current_open = get_symbol_current_open(symbol) # 当日开盘价 |
| | | current_high = get_symbol_current_high(symbol) # 当日当时最高价 |
| | | current_low = get_symbol_current_low(symbol) # 当日当时最低价 |
| | | current_volume = current_info[3] # 当日当时的总成交量 |
| | | # current_last_volume = update_symbol_volume(symbol, current_volume) # 获取瞬时交易量 |
| | | # current_amount = current_info[4] # 当日当时的总成交额 |
| | | current_quotes_buy = current_info[5] # 买5档数据 |
| | | current_quotes_sell = current_info[6] # 卖5档数据 |
| | | # current_quotes_buy == [[23.25, 800], [23.24, 1100], [23.23, 1100], [23.22, 2200], [23.21, 2300]] |
| | | # current_quotes_sell == [[23.27, 500], [23.29, 200], [23.3, 6900], [23.31, 500], [23.32, 200]] |
| | | current_created_at = current_info[7] # 当前信息创建时间 |
| | | if type(current_created_at) == int: |
| | | current_created_at = huaxin_util.convert_time(current_created_at) |
| | | if symbol_code == '000001': |
| | | print(f"000001 current_price==={current_price}") |
| | | |
| | | # 获取实时指数行情函数 |
| | | def index_market_current(): |
| | | logging.info(f"index_market_trend进入") |
| | | while True: |
| | | try: |
| | | # 在data_cache中获取到推送过来的实时指数行情数据 |
| | | stock_index_dict = data_cache.stock_index_dict |
| | | now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | if len(stock_index_dict) == 0 and now_time > data_cache.L1_data_start_time: |
| | | print(f"9:15后 实时指数数据为空=stock_index_dict===={stock_index_dict}") |
| | | index_judge_thread_manager(stock_index_dict) |
| | | except Exception as error: |
| | | logging.exception(error) |
| | | finally: |
| | | time.sleep(0.5) |
| | | |
| | | |
| | | """ |
| | |
| | | def strategic_thread_manager(current_info): |
| | | if current_info is not None: |
| | | # 调用交易策略模块中的涨幅视界策略 |
| | | # 指数行情调用 |
| | | |
| | | # 买入策略调用 |
| | | buying_strategy.growth_view_strategy(current_info) |
| | | # 卖出策略调用 |
| | | selling_strategy.instantaneous_change_strategy(current_info) |
| | | # pass |
| | | |
| | | |
| | | # 调用以指数行情信息为核心策略的函数 |
| | | def index_judge_thread_manager(index_market_info): |
| | | if index_market_info is not None: |
| | | # 调用交易策略模块中的涨幅视界策略 |
| | | # 指数行情调用 |
| | | index_market_trend_strategy.instant_trend_strategy(index_market_info) |
| | | |
| | | |
| | | # 生成所有个股的开盘价字典 |
| | | def get_all_stocks_current_open(current_infos): |
| | |
| | | else: |
| | | return None |
| | | |
| | | |
| | | # def process_current_infos(): |
| | | # """ |
| | | # 处理现价 |
| | | # :param current_infos: |
| | | # :return: |
| | | # """ |
| | | # while True: |
| | | # try: |
| | | # now_start = time.time() |
| | | # current_infos = l1_data_api.get_current_info() |
| | | # now_time = datetime.datetime.now().strftime("%H:%M:%S") |
| | | # if len(current_infos) == 0 and now_time > data_cache.L1_data_start_time: |
| | | # print(f"9:15后 l1数据为空=l1_data_current_infos===={current_infos}") |
| | | # for i in current_infos: |
| | | # if i[0] == '000001': |
| | | # print(f"i===={i}") |
| | | # |
| | | # |
| | | # get_all_stocks_current_open(current_infos) |
| | | # get_all_stocks_current_high_and_low(current_infos) |
| | | # for current_info in current_infos: |
| | | # try: |
| | | # if current_info is not None: |
| | | # strategic_thread_manager(current_info) |
| | | # except Exception as error: |
| | | # logging.exception(error) |
| | | # print("异常:", current_info) |
| | | # now_end: float = time.time() |
| | | # start_to_end = now_end - now_start |
| | | # print(f"运行中=={round(start_to_end, 2)} 秒") |
| | | # # logger.info(f"运行中=={round(start_to_end, 2)}秒") |
| | | # except Exception as error: |
| | | # logging.exception(error) |
| | | # finally: |
| | | # time.sleep(0.5) |
| | | |
| | | |
| | | # 获取当前L1行情数据 |
| | | def get_current_info(): |
| | | logging.info(f"get_current_info进入") |
| | | # shm = SharedMemoryObj(name="l1_data_shared_memory", size=5 * 1024 * 1024) |