如何从InteractiveBrokersAPI获取新闻合约的详细信息?

2024-09-27 23:23:59 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

Tags: selfnoneidfalseappiscodeerror
1条回答
网友
1楼 · 发布于 2024-09-27 23:23:59

对于broad tape news,使用函数reqMktData,并为新闻提供者定义契约对象。你知道吗

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

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

TWS API Documentation

相关问题 更多 >

    热门问题