Skip to content

Commit 72b2016

Browse files
webhelper: 不直接引用 tqsdk
1 parent 6feb50e commit 72b2016

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tqsdk/tqwebhelper.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import simplejson
1313
from aiohttp import web
1414

15-
import tqsdk
15+
import tqsdk.api
16+
import tqsdk.sim
17+
import tqsdk.backtest
1618
from tqsdk.datetime import _get_trading_day_start_time
1719

1820

@@ -36,12 +38,12 @@ def __init__(self, api):
3638
self._api._backtest = None
3739
self._logger.info("正在使用账户 {bid}, {aid} 运行策略。".format(bid=args["_broker_id"], aid=args["_account_id"]))
3840
elif args["_action"] == "backtest":
39-
self._api._account = tqsdk.api.TqSim(args["_init_balance"])
40-
self._api._backtest = tqsdk.api.TqBacktest(start_dt=datetime.strptime(args["_start_dt"], '%Y%m%d'),
41+
self._api._account = tqsdk.sim.TqSim(args["_init_balance"])
42+
self._api._backtest = tqsdk.backtest.TqBacktest(start_dt=datetime.strptime(args["_start_dt"], '%Y%m%d'),
4143
end_dt=datetime.strptime(args["_end_dt"], '%Y%m%d'))
4244
self._logger.info("当前回测区间 {sdt} - {edt}。".format(sdt=args["_start_dt"], edt=args["_end_dt"]))
4345
elif args["_action"] == "replay":
44-
self._api._backtest = tqsdk.api.TqReplay(datetime.strptime(args["_replay_dt"], '%Y%m%d'))
46+
self._api._backtest = tqsdk.backtest.TqReplay(datetime.strptime(args["_replay_dt"], '%Y%m%d'))
4547
self._logger.info("当前复盘日期 {rdt}。".format(rdt=args["_replay_dt"]))
4648
if args["_http_server_address"]:
4749
self._api._web_gui = True # 命令行 _http_server_address, 一定打开 _web_gui
@@ -69,9 +71,9 @@ async def _run(self, api_send_chan, api_recv_chan, web_send_chan, web_recv_chan)
6971
# 初始化数据截面
7072
self._data = {
7173
"action": {
72-
"mode": "replay" if isinstance(self._api._backtest, tqsdk.api.TqReplay) else "backtest" if isinstance(self._api._backtest, tqsdk.api.TqBacktest) else "run",
74+
"mode": "replay" if isinstance(self._api._backtest, tqsdk.backtest.TqReplay) else "backtest" if isinstance(self._api._backtest, tqsdk.backtest.TqBacktest) else "run",
7375
"md_url_status": '-',
74-
"td_url_status": True if isinstance(self._api._account, tqsdk.api.TqSim) else '-',
76+
"td_url_status": True if isinstance(self._api._account, tqsdk.sim.TqSim) else '-',
7577
"account_id": self._api._account._account_id,
7678
"broker_id": self._api._account._broker_id if isinstance(self._api._account, tqsdk.api.TqAccount) else 'TQSIM',
7779
"file_path": file_path[0].upper() + file_path[1:],
@@ -302,7 +304,7 @@ async def link_httpserver(self):
302304
"md_url": self._api._md_url,
303305
}
304306
# TODO:在复盘模式下发送 replay_dt 给 web 端,服务器改完后可以去掉
305-
if isinstance(self._api._backtest, tqsdk.api.TqReplay):
307+
if isinstance(self._api._backtest, tqsdk.backtest.TqReplay):
306308
url_response["replay_dt"] = int(datetime.combine(self._api._backtest._replay_dt, datetime.min.time()).timestamp() * 1e9)
307309
app = web.Application()
308310
app.router.add_get(path='/url', handler=lambda request: TqWebHelper.httpserver_url_handler(url_response))

0 commit comments

Comments
 (0)