Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tickNewsEvent does not map tickerId #110

Open
Fredrik-C opened this issue Feb 4, 2025 · 4 comments
Open

tickNewsEvent does not map tickerId #110

Fredrik-C opened this issue Feb 4, 2025 · 4 comments

Comments

@Fredrik-C
Copy link

I have a loop to subscribe for streaming news for a set of tickers:

for ticker in tickers:
    contract = Stock(ticker, 'SMART', 'USD')
    ib.qualifyContracts(contract)
    ib.reqMktData(contract, f'mdoff,292:{codes}', False, False)
    
ib.sleep(5)
ib.tickNewsEvent += on_tick_news

The passed argument to the eventhandler on_tick_news is a NewsTick:

class NewsTick(NamedTuple):
    timeStamp: int
    providerCode: str
    articleId: str
    headline: str
    extraData: str

According to TWS Api documentation the is a tickerId:

Image

This tickerId however seems to be "lost in translation".

In my use case it is essential to know which ticker the news is related to.

@mattsta
Copy link
Contributor

mattsta commented Feb 4, 2025

Thanks for pointing that out!

I'll look into fixing the data structure and API there for the next update cycle.

The entire "news API" adapters are under-tested and under-used apparently since we keep finding edge cases and data mismatches.

@Fredrik-C
Copy link
Author

I figured out that it is most likely the unused _reqid that is tickerid:

Image

But that id is not what I was hoping for (was hoping it would be conid in the contract)

@Fredrik-C
Copy link
Author

Hm... If I do a modification to also return the reqid when starting the subscription, then I can use a dictionary to map reqId => contract. I bit ugly, but solves my problem:

Image

Image

@mattsta
Copy link
Contributor

mattsta commented Feb 5, 2025

also return the reqid when starting the subscription, then I can use a dictionary to map reqId => contract.

This is a reasonable approach. We can automate it at the API level (remembering the mapping internally) so it can populate a Ticker or Contract object on the news event results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants