VeighNa量化社区
你的开源社区量化交易平台
fy758496805's Avatar
Member
离线
8 帖子
声望: 0

hxxjava wrote:

fy758496805 wrote:

大佬
在过程中 出现了一个错误

File "E:\VNPY\lib\site-packages\vnpy\trader\ui\mainwindow.py", line 276, in open_widget
2023-02-23 09:33:34 widget = widget_class(self.main_engine, self.event_engine)
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 100, in init
2023-02-23 09:33:35 self.init_ui()
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 259, in init_ui
self.candle_dialog: CandleChartDialog = CandleChartDialog()
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 1257, in init
self.init_ui()
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 1270, in init_ui
self.trade_item: TradeItem = TradeItem(plot=candle_plot, manager=manager)
File "E:\VNPY\lib\site-packages\vnpy\usertools\chart_items.py", line 1041, in init
super().init(plot=plot, manager=manager, size=15, pxMode=True, pen=pg.mkPen(None),
File "E:\VNPY\lib\site-packages\vnpy\usertools\chart_items.py", line 980, in init
self.plot.addItem(self)
AttributeError: 'NoneType' object has no attribute 'addItem'

是不是继承类的时候有问题呀?

答复:

你好像在策略中用了K线图表了,但是需要区分是用在实盘还是回测环境,回测时显示ChartWidget给谁看呀?

解决方法

把你的策略这样写:

def __init__(self, ... ...): # 你的策略的初始化函数
        ... ...
        self.chart:CandleChartDialog = None
        ... ...

def on_start(self):  # 策略的启动函数
        is_live = self.cta_engine.get_engine_type() == EngineType.LIVE    
        if is_live and self.show_chart and not self.chart:
            # 实盘,配置了显示图表同时未成交的情况下,创建图表——测试环境不会创建图表
            self.chart = CandleChartDialog(
                                strategy = self,
                               ... ... # 你的参数
                        )
            self.chart.update_dir_history(self.bars)
            self.chart.show()

感谢大佬解惑

大佬
在过程中 出现了一个错误

File "E:\VNPY\lib\site-packages\vnpy\trader\ui\mainwindow.py", line 276, in open_widget
2023-02-23 09:33:34 widget = widget_class(self.main_engine, self.event_engine)
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 100, in init
2023-02-23 09:33:35 self.init_ui()
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 259, in init_ui
self.candle_dialog: CandleChartDialog = CandleChartDialog()
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 1257, in init
self.init_ui()
File "E:\VNPY\lib\site-packages\vnpy_ctabacktester\ui\widget.py", line 1270, in init_ui
self.trade_item: TradeItem = TradeItem(plot=candle_plot, manager=manager)
File "E:\VNPY\lib\site-packages\vnpy\usertools\chart_items.py", line 1041, in init
super().init(plot=plot, manager=manager, size=15, pxMode=True, pen=pg.mkPen(None),
File "E:\VNPY\lib\site-packages\vnpy\usertools\chart_items.py", line 980, in init
self.plot.addItem(self)
AttributeError: 'NoneType' object has no attribute 'addItem'

是不是继承类的时候有问题呀?

File "E:\VNPY\lib\runpy.py", line 196, in _run_module_as_main
2022-12-26 18:18:08 return _run_code(code, main_globals, None,
File "E:\VNPY\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "build\bdist.win-amd64\egg\veighna_station\trader.py", line 39, in <module>
2022-12-26 18:18:08 File "build\bdist.win-amd64\egg\veighna_station\trader.py", line 30, in run_trader
File "E:\VNPY\lib\site-packages\vnpy\trader\engine.py", line 101, in add_app
engine: BaseEngine = self.add_engine(app.engine_class)
File "E:\VNPY\lib\site-packages\vnpy\trader\engine.py", line 72, in add_engine
engine: BaseEngine = engine_class(self, self.event_engine)
File "E:\VNPY\lib\site-packages\vnpy_ctastrategy\engine.py", line 111, in init
self.datafeed: BaseDatafeed = get_datafeed()
File "E:\VNPY\lib\site-packages\vnpy\trader\datafeed.py", line 50, in get_datafeed
module: ModuleType = import_module(module_name)
File "E:\VNPY\lib\importlib__init.py", line 128, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "E:\VNPY\lib\site-packages\vnpy_rqdata\
init.py", line 26, in <module>
from .rqdata_datafeed import RqdataDatafeed as Datafeed
File "E:\VNPY\lib\site-packages\vnpy_rqdata\rqdata_datafeed.py", line 5, in <module>
from pandas import DataFrame
File "E:\VNPY\lib\site-packages\pandas\
init__.py", line 48, in <module>
from pandas.core.api import (
ImportError: cannot import name 'ArrowDtype' from 'pandas.core.api' (E:\VNPY\lib\site-packages\pandas\core\api.py)

annot import name 'ArrowDtype' from 'pandas.core.api' (E:\VNPY\lib\site-packages\pandas\core\api.py)

description

我登录用的实盘账号 进的是CTP实盘6.6.7 使用自己写的策略 跑出来的还是本地仿真测试 不是实盘交易 不知道是不是自己哪里操作错了

为什么之前都能成功连接 今天连接CTP账号没有反映了?

miro wrote:

https://www.vnpy.com/docs/cn/paper_account.html#id8
看起来是本地仿真环境吧,这个文档应该可以解决你的问题
疑惑倒是解决了 请问有办法实现仿真资金的计算吗?主要是想先尝试一下模拟实盘收益情况,才敢真金白银的实盘交易

description
我自定的策略有买卖下单记录 但是仿真账号的资金信息没有变化

© 2015-2022 微信 18391752892
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】