[英]How to obtain News Contract Details from the Interactive Brokers API?
I am trying to get news feed (Broad Tape) not specific to any equity but running into error after running this code 我正在尝试获取不特定于任何股权的新闻提要(宽带),但在运行此代码后遇到错误
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import *
class MyWrapper(EWrapper):
def nextValidId(self, orderId:int):
print("setting nextValidOrderId: %d", orderId)
self.nextValidOrderId = orderId
# start program here or use threading
app.reqContractDetails(4444, contract)
def newsProviders(self, newsProviders: ListOfNewsProviders):
print("NewsProviders: ")
for provider in newsProviders:
print("NewsProvider.", provider)
def contractDetails(self, reqId: int, contractDetails: ContractDetails):
super().contractDetails(reqId, contractDetails)
print(contractDetails)
def contractDetailsEnd(self, reqId: int):
super().contractDetailsEnd(reqId)
print("ContractDetailsEnd. ReqId:", reqId)
# this is the logical end of your program
app.disconnect() # delete if threading and you want to stay connected
def error(self, reqId, errorCode, errorString):
print("Error. Id: " , reqId, " Code: " , errorCode , " Msg: " , errorString)
wrapper = MyWrapper()
app = EClient(wrapper)
app.connect("127.0.0.1", 7496, clientId=123)
print("serverVersion:%s connectionTime:%s" % (app.serverVersion(), app.twsConnectionTime()))
from ibapi.contract import Contract
contract = Contract()
contract.symbol = ""`enter code here`
contract.secType = "NEWS"`enter code here`
contract.exchange = "BRFG"
contract.currency = ""
app.run()
And the output that is returned is 而返回的输出是
serverVersion:148 connectionTime:b'20190227 22:17:03 EST'
setting nextValidOrderId: %d 1
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm.nj
Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:euhmds
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:fundfarm
Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:ushmds
100145087,BRFG:BRFG_SMU,News,,0.0,,,NEWS,,,,Stock Market Update:Stock Market Update,False,,combo:,,0.01,,NEWS,1,0,Stock Market Update,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
100283238,BRFG:BRFG_ALL,News,,0.0,,,NEWS,,,,All News:All News,False,,combo:,,0.01,,NEWS,1,0,All News,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
100756401,BRFG:BRFG_STS,News,,0.0,,,NEWS,,,,Story Stocks:Story Stocks,False,,combo:,,0.01,,NEWS,1,0,Story Stocks,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
100756487,BRFG:BRFG_DSW,News,,0.0,,,NEWS,,,,Daily Sector Wrap:Daily Sector Wrap,False,,combo:,,0.01,,NEWS,1,0,Daily Sector Wrap,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
100756760,BRFG:BRFG_TECS,News,,0.0,,,NEWS,,,,Tech Stocks:Tech Stocks,False,,combo:,,0.01,,NEWS,1,0,Tech Stocks,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
100756828,BRFG:BRFG_RTB,News,,0.0,,,NEWS,,,,Rate Brief:Rate Brief,False,,combo:,,0.01,,NEWS,1,0,Rate Brief,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
100756938,BRFG:BRFG_FEDB,News,,0.0,,,NEWS,,,,Fed Brief:Fed Brief,False,,combo:,,0.01,,NEWS,1,0,Fed Brief,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
209736932,BRFG:BRFG_WKW,News,,0.0,,,NEWS,,,,Weekly Wrap:Weekly Wrap,False,,combo:,,0.01,,NEWS,1,0,Weekly Wrap,,,,,,,,,0,1,,,,2147483647,None,,,,,,,False,False,0,False,,,,,False,
ContractDetailsEnd. ReqId: 4444
For broad tape news you use the function reqMktData
with the Contract object defined for the news provider. 对于宽磁带新闻,您可以使用带有为新闻提供者定义的Contract对象的reqMktData
函数。
contract = Contract()
contract.symbol = "BRFG:BRFG_ALL"
contract.secType = "NEWS"
contract.exchange = "BRFG"
reqMktData(1, contract, "mdoff,292", False, False, [])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.