如何启用TWS延迟行情数据?
How to enable TWS delayed market data?
这是我用来请求市场数据的脚本。
我还没有订阅数据源,所以我虽然它会自动 return 延迟市场数据,但显然我必须启用它,但找不到在哪里做。
这是脚本和我得到的错误,我只需要接收延迟数据,所以我可以测试我的算法。
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from time import sleep
def fundamentalData_handler(msg):
print(msg)
def error_handler(msg):
print(msg)
tws = ibConnection(port=7496, clientId=100)
tws.register(error_handler, message.Error)
tws.register(fundamentalData_handler, message.fundamentalData)
tws.connect()
c = Contract()
c.m_symbol = 'AAPL'
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "USD"
print "on it"
tws.reqMktData(897,c,"",False)
sleep(50)
tws.disconnect()
错误:
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:hfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:eufarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:jfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfuture>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm.us>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ilhmds>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:euhmds>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:fundfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds>
<error id=897, errorCode=10168, errorMsg=Requested market data is not subscribed. Delayed market data is not enabled>
文档建议(添加了重点和格式):
The API can request Live, Frozen, Delayed and Delayed Frozen market data from Trader Workstation by switching market data type via the IBApi.EClient.reqMarketDataType
# Switch to live (1) frozen (2) delayed (3) delayed frozen (4).
from ibapi.client import MarketDataTypeEnum
.reqMarketDataType(MarketDataTypeEnum.DELAYED)
或
.reqMarketDataType(3)
that has to be called before making a market data request with .reqMktData()
.
使用reqMktData
功能时,有四种“市场数据模式”(Market Data Type)可用:
- 直播(默认)
- 冻结(通常用于 bid/ask 收市后的价格)
- 延迟(如果用户名没有实时市场数据订阅)
- 延迟冷冻(类型 2 和 3 的组合)
这是我用来请求市场数据的脚本。
我还没有订阅数据源,所以我虽然它会自动 return 延迟市场数据,但显然我必须启用它,但找不到在哪里做。
这是脚本和我得到的错误,我只需要接收延迟数据,所以我可以测试我的算法。
from ib.opt import ibConnection, message
from ib.ext.Contract import Contract
from time import sleep
def fundamentalData_handler(msg):
print(msg)
def error_handler(msg):
print(msg)
tws = ibConnection(port=7496, clientId=100)
tws.register(error_handler, message.Error)
tws.register(fundamentalData_handler, message.fundamentalData)
tws.connect()
c = Contract()
c.m_symbol = 'AAPL'
c.m_secType = 'STK'
c.m_exchange = "SMART"
c.m_currency = "USD"
print "on it"
tws.reqMktData(897,c,"",False)
sleep(50)
tws.disconnect()
错误:
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:hfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:eufarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:jfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfuture>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm.us>
<error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ilhmds>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:euhmds>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:fundfarm>
<error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds>
<error id=897, errorCode=10168, errorMsg=Requested market data is not subscribed. Delayed market data is not enabled>
文档建议(添加了重点和格式):
The API can request Live, Frozen, Delayed and Delayed Frozen market data from Trader Workstation by switching market data type via the
IBApi.EClient.reqMarketDataType
# Switch to live (1) frozen (2) delayed (3) delayed frozen (4).
from ibapi.client import MarketDataTypeEnum .reqMarketDataType(MarketDataTypeEnum.DELAYED)
或
.reqMarketDataType(3)
that has to be called before making a market data request with
.reqMktData()
.
使用reqMktData
功能时,有四种“市场数据模式”(Market Data Type)可用:
- 直播(默认)
- 冻结(通常用于 bid/ask 收市后的价格)
- 延迟(如果用户名没有实时市场数据订阅)
- 延迟冷冻(类型 2 和 3 的组合)