| | |
| | | """ |
| | | 设置行情信息 |
| | | :param with_log: 是否写入日志 |
| | | :param data: (代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量, 买入量, 卖出量, 昨日收盘价) |
| | | :param data: (代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量, 买入量, 卖出量, 昨日收盘价, 时间戳) |
| | | :return: |
| | | """ |
| | | if with_log: |
| | |
| | | market_call_back_queue.put_nowait((pDepthMarketData['SecurityID'], pDepthMarketData['LastPrice'], rate, |
| | | pDepthMarketData['BidPrice1'], pDepthMarketData['BidVolume1'], |
| | | pDepthMarketData['TotalVolumeTrade'], pDepthMarketData['TotalBidVolume'], |
| | | pDepthMarketData['TotalAskVolume'], pDepthMarketData['PreClosePrice'])) |
| | | pDepthMarketData['TotalAskVolume'], pDepthMarketData['PreClosePrice'], pDepthMarketData['DataTimeStamp'])) |
| | | code = pDepthMarketData['SecurityID'] |
| | | if code.find("00") == 0 or code.find("60") == 0: |
| | | if rate >= 0.05: |
| | |
| | | return fdatas |
| | | |
| | | |
| | | # 加载买入得分记录 |
| | | def load_market_info(date=tool.get_now_date_str()): |
| | | path = f"{constant.get_path_prefix()}/{constant.LOG_DIR}/huaxin_local/l2/market.{date}.log" |
| | | fdatas = {} |
| | | with open(path, 'r') as f: |
| | | lines = f.readlines() |
| | | for line in lines: |
| | | start_index = line.find("]") |
| | | line = line[start_index + 1:].strip() |
| | | data = eval(line) |
| | | code = data[0] |
| | | if code not in fdatas: |
| | | fdatas[code] = [] |
| | | fdatas[code].append(data) |
| | | return fdatas |
| | | |
| | | |
| | | def load_transactions(date=tool.get_now_date_str()): |
| | | path = f"{constant.get_path_prefix()}/{constant.LOG_DIR}/huaxin_local/l2/transaction.{date}.log" |
| | | fdatas = [] |
| | |
| | | for p in position_dict: |
| | | translation = position_dict[p] |
| | | underlying_code = translation["SecurityID"] |
| | | # TODO 获取当时的价格 |
| | | translation["buy_list"] = [{"price": str(translation['TradePrice']), |
| | | "tradeTime": l2_huaxin_util.convert_time(translation['OrderTime']), |
| | | "volume": 10}] |
| | |
| | | |
| | | position_dict = {} |
| | | |
| | | markets_list_dict = {} |
| | | |
| | | |
| | | # TODO 待完成 |
| | | def get_price_by_time(code, time_str): |
| | | markets = markets_list_dict.get(code) |
| | | if markets: |
| | | for m in markets: |
| | | pass |
| | | |
| | | |
| | | def start_backtest(date): |
| | | try: |
| | |
| | | markets_dict = log_export.load_latest_market_info(date) |
| | | for code in markets_dict: |
| | | __BuyStrategyDataManager.add_market_info(markets_dict[code]) |
| | | global markets_list_dict |
| | | markets_list_dict = log_export.load_market_info(date) |
| | | |
| | | transactions = log_export.load_transactions(date) |
| | | for t in transactions: |
| | | code = t["SecurityID"] |
| | |
| | | position_dict[code] = t |
| | | logger_debug.info(f"回测下单:{t}") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | logger_debug.exception(e) |
| | |
| | | self.__limit_up_price_dict[code] = round(float(limit_up_price), 2) |
| | | |
| | | def add_market_info(self, info): |
| | | # TODO 加入时间 |
| | | """ |
| | | 添加市场信息 |
| | | :param info: (代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量, 委托买入总量, 委托卖出总量, 昨日收盘价) |
| | | :param info: (代码, 最近的价格, 涨幅, 买1价, 买1量, 成交总量, 委托买入总量, 委托卖出总量, 昨日收盘价, 时间) |
| | | :return: |
| | | """ |
| | | code = info[0] |