尝试使用 ibpy 在正常交易时间 (rth) 之外发送订单

trying to send order outside regular trading hours (rth) using ibpy

我是 Python 和 ibpy 的新手,但我能够使用两者测试 运行 我的策略。我的问题是我无法在正常交易时间 (RTH) 之外发送订单,当市场开放时但 ib 不认为它们是 'regular trading hour'.

以下是我发送这些订单的方式。

from ib.opt import Connection
from ib.ext.Contract import Contract
from ib.ext.Order import Order

import time

port = 7496
client = 1
account = "XXXXX"

newContract = Contract()
newContract.m_symbol = "CL"
newContract.m_secType = "FUT"
newContract.m_exchange = "NYMEX"
newContract.m_currency = "USD"
newContract.m_expiry = "201806"

newOrder = Order()
newOrder.m_orderType = "LMT"
newOrder.m_totalQuantity = 1
newOrder.m_action = "BUY"
newOrder.m_lmtPrice = "65"

tws_conn = Connection.create(port=port, clientId=client)
print("------ Connecting.... --------")
tws_conn.connect()
time.sleep(1)
#to simplify I am using a number, but this needs to be updated every new order.
orderId = 1
tws_conn.placeOrder(orderId, newContract, newOrder)

在 RTH 期间,秩序很好,但当我们在 RTH 之外时,我收到这条消息,:

07:45:45:392 -> 4-2-1-399-Order Message:
BUY 1 CL JUN'18 (CLM8) 
Warning: your order will not be placed at the exchange until 2018-05-14 09:30:00 US/Eastern-

有没有办法启用返航指令?

阅读文档以获取大量有用的信息。 http://interactivebrokers.github.io/tws-api/classIBApi_1_1Order.html#a60dcca6e3c3ae6ae6e0c5f3fdffc5a4a

bool OutsideRth [get, set] If set to true, allows orders to also trigger or fill outside of regular trading hours.

这看起来像 C# 文档,但在 ibpy 中也是如此。如果查看源代码,Order 有一个字段 m_outsideRth = bool()。只需将其设置为 true。