简体   繁体   English

如何从Interactive Brokers API获取新闻合同详细信息?

[英]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, [])

TWS API Documentation TWS API文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从盈透证券 API 获取合约详情? - How to obtain Contract Details from the Interactive Brokers API? 如何等待交互式经纪人从 tws api 下载数据? - how to wait for data to download in tws api from interactive brokers? 如何从交互式经纪人API获取历史股价数据? - How to get historical stock price data from interactive brokers API? 如何始终如一地从 IBKR API(互动经纪商)返回头寸? - How to return positions from IBKR API (interactive brokers) consistently? 互动经纪人 API 执行细节,我如何获得我得到的期货的入场价格? - interactive brokers API execute details, how I get the entry price of a Future that i got? 使用python从交互式经纪人获取帐户摘要详细信息 - Get account summary details from interactive brokers using python 如何从API Interactive Brokers的ib.reqHistoricalData生成的元组列表中获取元素 - How do I get the elements from list of tuples generated by ib.reqHistoricalData from API Interactive Brokers 使用 Python API 下载数据时如何消除(或从控制台抑制)盈透证券错误 - How to eliminate (or suppress from console) Interactive Brokers error when downloading data with Python API 期权价差与盈透证券的 API? - Option spreads with Interactive Brokers' API? 捕获盈透证券交易执行详细信息 python - Capture Interactive Brokers Trade Execution details python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM