| | |
| | | import time |
| | | import datetime |
| | | import utils |
| | | # 引入掘金API |
| | | |
| | | from utils import huaxin_util |
| | | # 引入华鑫API(小辉整理) |
| | | from strategy import l1_data_api |
| | | from strategy import data_cache |
| | |
| | | # 获取logger实例 |
| | | logger = get_logger() |
| | | |
| | | |
| | | # 获取tick数据 |
| | | def on_tick(context, tick): |
| | | pass |
| | | __process(context, tick) |
| | | print(f"启动on_tick") |
| | | print(f"tick-===={tick}") |
| | | |
| | | |
| | | # 驱动调用所有以current数据为核心策略的函数 |
| | | def __process(context, current_data): |
| | | pass |
| | | # print(f"current_data===={current_data}") |
| | | # 调用交易策略模块中的涨幅视界策略 |
| | | # buying_strategy.growth_horizon_strategy(context, current_data) |
| | | # selling_strategy.instantaneous_increase_strategy(context, current_data) |
| | | |
| | | # |
| | | # # 获取掘金current数据 |
| | | # def get_current_data(): |
| | | # logging.info(f"get_current_data进入") |
| | | # while True: |
| | | # try: |
| | | # now_start = time.time() |
| | | # current_datas = current(symbols=data_cache.DataCache().min_stocks, |
| | | # fields='open,high,low,symbol,price,created_at,cum_volume,cum_amount,last_volume,quotes') |
| | | # # current_datas = l1_data_api.get_current_info() |
| | | # # print(f"l1_data_current_datas===={current_datas}") |
| | | # # print(f"current_datas====={current_datas}") |
| | | # now_end = time.time() |
| | | # now_start_to_end = now_end - now_start |
| | | # # index = 0 |
| | | # for current_data in current_datas: |
| | | # # index+=1 |
| | | # try: |
| | | # __process(data_cache.context, current_data) |
| | | # # if index == 100: |
| | | # # print(current_data) |
| | | # # print(f"第几个{index}") |
| | | # except Exception as error: |
| | | # logging.exception(error) |
| | | # print("异常:", current_data) |
| | | # print(f"运行中=={round(now_start_to_end, 2)}秒") |
| | | # # logger.info(f"运行中=={round(now_start_to_end, 2)}秒") |
| | | # except Exception as error: |
| | | # logging.exception(error) |
| | | # finally: |
| | | # time.sleep(1) |
| | | ''' |
| | | 创建一个函数来对主要指数的实时行情作处理 |
| | | ''' |
| | | 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}") |
| | | |
| | | |
| | | """ |
| | | 另外创建一个线程来驱动拉取华鑫l1数据 给各个策略模块 |
| | | 创建一个线程来驱动拉取华鑫l1数据 给各个策略模块 |
| | | """ |
| | | |
| | | |
| | |
| | | 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 |
| | | |