vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 3
声望: 0

在Jupyter模式模式下,运行engine.buy(vt_symbol = "rb2001.SHFE",price = "3539",volume = "1",order_type=OrderType.LIMIT)
运行结果如下:
NameError Traceback (most recent call last)

<ipython-input-52-694b0f0f4424> in <module>
----> 1 engine.buy(vt_symbol = "rb2001.SHFE",price = "3539",volume = "1",order_type=OrderType.LIMIT)

NameError: name 'OrderType' is not defined

Administrator
avatar
加入于:
帖子: 1868
声望: 85

在你的Jupyter顶部,加上from vnpy.trader.constant import OrderType

Member
avatar
加入于:
帖子: 3
声望: 0

用Python的交易员 wrote:

在你的Jupyter顶部,加上from vnpy.trader.constant import OrderType
加过后还是有问题,错误信息如下:
RuntimeError Traceback (most recent call last)

<ipython-input-2-bac28c7f81bd> in <module>
----> 1 engine.buy(vt_symbol = "rb2001.SHFE",price = "3393",volume = "1",order_type=OrderType.LIMIT)

c:\vnstudio\lib\site-packages\vnpy\app\script_trader\engine.py in buy(self, vt_symbol, price, volume, order_type)
144 def buy(self, vt_symbol: str, price: str, volume: str, order_type: OrderType = OrderType.LIMIT) -> str:
145 """"""
--> 146 return self.send_order(vt_symbol, price, volume, Direction.LONG, Offset.OPEN, order_type)
147
148 def sell(self, vt_symbol: str, price: str, volume: str, order_type: OrderType = OrderType.LIMIT) -> str:

c:\vnstudio\lib\site-packages\vnpy\app\script_trader\engine.py in send_order(self, vt_symbol, price, volume, direction, offset, order_type)
128 )
129
--> 130 vt_orderid = self.main_engine.send_order(req, contract.gateway_name)
131 return vt_orderid
132

c:\vnstudio\lib\site-packages\vnpy\trader\engine.py in send_order(self, req, gateway_name)
171 gateway = self.get_gateway(gateway_name)
172 if gateway:
--> 173 return gateway.send_order(req)
174 else:
175 return ""

c:\vnstudio\lib\site-packages\vnpy\gateway\ctp\ctp_gateway.py in send_order(self, req)
172 def send_order(self, req: OrderRequest):
173 """"""
--> 174 return self.td_api.send_order(req)
175
176 def cancel_order(self, req: CancelRequest):

c:\vnstudio\lib\site-packages\vnpy\gateway\ctp\ctp_gateway.py in send_order(self, req)
749
750 self.reqid += 1
--> 751 self.reqOrderInsert(ctpreq, self.reqid)
752
753 orderid = f"{self.frontid}
{self.sessionid}_{self.order_ref}"

RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)

Administrator
avatar
加入于:
帖子: 1868
声望: 85

price和volume应该是float,而不是str类型,之前注释写错,不好意思

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3