How to obtain News Contract Details from the Interactive Brokers API?

孤人 提交于 2021-02-11 13:55:19

问题


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

回答1:


For broad tape news you use the function reqMktData with the Contract object defined for the news provider.

contract = Contract()
contract.symbol  = "BRFG:BRFG_ALL"
contract.secType = "NEWS"
contract.exchange = "BRFG"

reqMktData(1, contract, "mdoff,292", False, False, [])

TWS API Documentation



来源:https://stackoverflow.com/questions/54917982/how-to-obtain-news-contract-details-from-the-interactive-brokers-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!