buy和cover都是做多啊,你要是想平掉多仓那应该用sell
simnow不要选ctptest,直接用ctp
点功能没反应应该是你在启动的时候没勾选功能,登录不合法是账号密码错了
可以用engine.main_engine.get_engine('RiskManager')访问到已经创建的riskengine
wp61413 wrote:
谢谢,使用engine.get_gateway('CTP').td_api.connect_status后,还是报错了:
from vnpy_scripttrader import init_cli_trading
from vnpy_ctp import CtpGateway
engine = init_cli_trading([CtpGateway])
Traceback (most recent call last):
File "c:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 286, in <module>
run()
File "c:\Users\wp61413_114147317492\期权交易\终稿\ScriptTrader_vnpy_impvplace_commodityDos.py", line 42, in run
print(engine.get_gateway('CTP').td_api.connect_status)
AttributeError: 'ScriptEngine' object has no attribute 'get_gateway'
哦你是脚本引擎啊,那在engine后面还需要加个main_engine
engine.get_gateway('CTP').td_api.connect_status
如果vnpy_rohon版本比较老的话,可能是委托状态映射里没有THOST_FTDC_OST_NoTradeNotQueueing和THOST_FTDC_OST_PartTradedNotQueueing,我之前遇到过类似的问题
应该是要把OmsEngine里面的数据清掉,活动是active_orders,委托是orders,这个类init时候的其他数据建议也清空,不然可能内存占用会越来越大。
18650802653 wrote:
wp61413 wrote:
使用说明的文档上写:
get_position
入参:vt_positionid: str, use_df: bool = False
出参:PositionData
根据vt_positionid来查询持仓情况,返回对象包含接口名称、交易所、合约代码、数量、冻结数量等。
position = engine.get_position(vt_positionid='rb2202.SHFE.多')这是查询某个交易所某个合约某个方向的持仓情况的语句,如果想查询所有的持仓,该如何写呢?
请问你说的这个说明文档,是在哪里看的?我没找到过类似的这种文档?
simnow好像是只支持上期和中金所的期权吧
xiaohe wrote:
你vnpy_rohon的版本是?用station启动【交易】界面的右侧有报错信息输出吗?
vnpy是2.8的,vnpy_rohon后续没有手动升级过。我用的是脚本策略,就是出现这个问题之后get_order()得到的是初始的OrderData,此外没有任何报错
MTF wrote:
建议去vnpy_rohon仓库开个issue,把这里的详细信息贴一下
另外有没有检查过主窗口【日志】区域,是否有什么连接断开之类的输出记录?
没有,都是正常交易的时候出现的,没出现断开
融航报单的代码是这样的,难道是在self.reqOrderInsert(rohon_req, self.reqid)这里卡的太久,以至于已经收到了订单回报才执行到下一段self.gateway.on_order(order)?
def send_order(self, req: OrderRequest) -> str:
self.order_ref += 1
rohon_req: dict = {
"InstrumentID": req.symbol,
"ExchangeID": req.exchange.value,
"LimitPrice": req.price,
"VolumeTotalOriginal": int(req.volume),
"OrderPriceType": ORDERTYPE_VT2ROHON.get(req.type, ""),
"Direction": DIRECTION_VT2ROHON.get(req.direction, ""),
"CombOffsetFlag": OFFSET_VT2ROHON.get(req.offset, ""),
"OrderRef": str(self.order_ref),
"InvestorID": self.userid,
"UserID": self.userid,
"BrokerID": self.brokerid,
"CombHedgeFlag": THOST_FTDC_HF_Speculation,
"ContingentCondition": THOST_FTDC_CC_Immediately,
"ForceCloseReason": THOST_FTDC_FCC_NotForceClose,
"IsAutoSuspend": 0,
"TimeCondition": THOST_FTDC_TC_GFD,
"VolumeCondition": THOST_FTDC_VC_$,
"MinVolume": 1
}
if req.type == OrderType.FAK:
rohon_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
rohon_req["TimeCondition"] = THOST_FTDC_TC_IOC
rohon_req["VolumeCondition"] = THOST_FTDC_VC_$
elif req.type == OrderType.FOK:
rohon_req["OrderPriceType"] = THOST_FTDC_OPT_LimitPrice
rohon_req["TimeCondition"] = THOST_FTDC_TC_IOC
rohon_req["VolumeCondition"] = THOST_FTDC_VC_CV
self.reqid += 1
self.reqOrderInsert(rohon_req, self.reqid)
orderid: str = f"{self.frontid}_{self.sessionid}_{self.order_ref}"
order: OrderData = req.create_order_data(orderid, self.gateway_name)
self.gateway.on_order(order)
return order.vt_orderid
最近老是出现订单状态卡在提交中的情况,所以在process_order_event的时候把orderdata写到日志里了,结果发现这个处理的顺序有点问题。从代码来看,在报单的时候,首先会生成的是初始的OrderData,并调用一次on_order(),也就是这时process_order_event()收到的data状态为提交中,时间为None;之后收到的就是订单回报了,这部分处理的顺序没发现什么问题。
根据《郑州商品交易所期货交易细则》第二十六条规定,经研究决定,自2021年12月16日起,红枣期货合约交易指令每次最小开仓下单量调整为4手,限价指令每次最大下单量调整为100手,市价指令每次最大下单量调整为20手。
特此公告。
郑州商品交易所
2021年12月14日
MTF wrote:
write_log的日志内容,加一个[策略名]区分下
谢谢,看了几遍代码搞定了:我是在登录账号后给LogEngine重新添加了一个log/账户名文件夹下的file_handler,然后把之前的handler移除了,这样就可以解决我的问题了
如题,由于目前有多个账户在运行,用的script_engine调用write_log()输出日志会输出到同一个文件中,混到一起查看日志会有些错乱,这个问题该怎么解决呢?
`
def process_order_event(self, event: Event) -> None:
""""""
order: OrderData = event.data
self.orders[order.vt_orderid] = order
if order.vt_orderid not in self.order_to_trades:
self.order_to_trades[order.vt_orderid]=[]
# If order is active, then update data in dict.
if order.is_active():
self.active_orders[order.vt_orderid] = order
# Otherwise, pop inactive order from in dict
elif order.vt_orderid in self.active_orders:
self.active_orders.pop(order.vt_orderid)
`
从process_order_event来看,应该是self.orders[order.vt_orderid] = order出了问题?但是没有发现过报错信息,我在这个函数里打印信息后续再检查检查吧