用backtrader连接CTP实盘仿真,用btplottinglive在线实时绘图报500: Internal Server Error错误
安装了btplotting绘图包,
在回测时,from btplotting import BacktraderPlotting 可以绘图
在实盘交易时间仿真时,from btplotting import BacktraderPlottingLive
同时也添加了:
cerebro.addanalyzer(BacktraderPlottingLive, barup='red', bardown='green',
port=8889, lookback=100, autostart=True, force_plot_legend=True)
测试能够能够连接上CTP,同时也能收到仿真交易数据
但是在 在线绘图时,报:500: Internal Server Error
是什么原因呢?
后面尝试改成使用: backtrader_bokeh
实盘仿真时,from backtrader_bokeh import Backtrader_BokehLive就能够实时绘图了
但是回测时,from backtrader_bokeh import Backtrader_Bokeh就报错了
是什么原因呢?
如果我想用 backtrader_bokeh 在回测和实时仿真时都可以绘图,该怎么改?
错误代码:
O H L C SA309.CZCE_10s 2358.0 2358.0 2357.0 2358.0
Uncaught exception GET / (::1)
HTTPServerRequest(protocol='http', host='localhost:8889', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "C:\Python\3.8.10\lib\site-packages\tornado\web.py", line 1713, in _execute
result = await result
File "C:\Python\3.8.10\lib\site-packages\bokeh\server\views\doc_handler.py", line 54, in get
session = await self.get_session()
File "C:\Python\3.8.10\lib\site-packages\bokeh\server\views\session_handler.py", line 145, in get_session
session = await self.application_context.create_session_if_needed(session_id, self.request, token)
File "C:\Python\3.8.10\lib\site-packages\bokeh\server\contexts.py", line 242, in create_session_if_needed
self._application.initialize_document(doc)
File "C:\Python\3.8.10\lib\site-packages\bokeh\application\application.py", line 192, in initialize_document
h.modify_document(doc)
File "C:\Python\3.8.10\lib\site-packages\bokeh\application\handlers\function.py", line 142, in modify_document
self._func(doc)
File "C:\Python\3.8.10\lib\site-packages\btplotting-0.2.1-py3.8.egg\btplotting\webapp.py", line 54, in make_document
model = self._model_factory_fnc(doc)
File "C:\Python\3.8.10\lib\site-packages\btplotting-0.2.1-py3.8.egg\btplotting\analyzers\plot.py", line 64, in _app_cb_build_root_model
client = LiveClient(doc,
File "C:\Python\3.8.10\lib\site-packages\btplotting-0.2.1-py3.8.egg\btplotting\live\client.py", line 55, in __init__
self.model, self._refresh_fnc = self._createmodel()
File "C:\Python\3.8.10\lib\site-packages\btplotting-0.2.1-py3.8.egg\btplotting\live\client.py", line 177, in _createmodel
tabs = Tabs(
File "C:\Python\3.8.10\lib\site-packages\bokeh\model\model.py", line 97, in __new__
raise ValueError("'id' cannot be used together with property initializers")
ValueError: 'id' cannot be used together with property initializers
500 GET / (::1) 123.67ms
你把报错复制到记事本发给我