Python 如何从InteractiveBrokersAPI获取新闻合同详细信息?

Python 如何从InteractiveBrokersAPI获取新闻合同详细信息?,python,tws,Python,Tws,我试图获取不特定于任何股票的新闻提要(宽频带),但在运行此代码后遇到错误 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)

我试图获取不特定于任何股票的新闻提要(宽频带),但在运行此代码后遇到错误

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()
返回的输出是

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

对于宽频带新闻,您可以使用函数
reqMktData
,为新闻提供者定义合同对象

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

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