erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.81k stars 750 forks source link

ಥ_ಥ indices TRIN-NYSE, TICK-NYSE in reqRealTimeBars() : Error 321, reqId 69: Error validating request.-'bT' : cause - Please enter exchangeError 321, reqId 69: Error validating request.-'bT' : cause - Please enter exchange #478

Closed fritol closed 2 years ago

fritol commented 2 years ago

Hey Ewald, @erdewit , there is a TRIN-NYSE, TICK-NYSE problem with reqRealTimeBars(contract, 30, 'MIDPOINT', False). Other indices work just fine.

The error returned by IB:

Error 321, reqId 69: Error validating request.-'bT' : cause - Please enter exchange, contract: Index(symbol='TRIN-NYSE') Error 10225, reqId 29: Bust event occurred, current subscription is deactivated. Please resubscribe real-time bars immediately., contract: Index(conId=26718743, symbol='TRIN-NYSE', exchange='NYSE', currency='USD', localSymbol='TRIN-NYSE')

p.s.: thx for ur work!

fritol commented 2 years ago

the problems is not in the IB API according to their support

m12t commented 2 years ago

Can you give a minimal reproducible example? It's had to know without seeing the code. What does your Contract object look like?

fritol commented 2 years ago

contract=Index('TRIN-NYSE') ib.qualifyContracts(contract) # optional ib.reqHistoricalData( contract, endDateTime='', durationStr='1 D', barSizeSetting='1 min', whatToShow='TRADES', useRTH=True, formatDate=1 )

ib.reqRealTimeBars(contract, 5, 'TRADES', False) # optional

m12t commented 2 years ago

So your code appears to work, though I'm not subscribed to NYSE IND data to verify a valid output for TRIN-NYSE in particular. In your output above, there are two distinct error codes: 321 (server error when validating request) and 10225 (bust event).

Are you able to get any output at all from reqRealTimeBars() that is then followed by a bust event some time later, or are you not able to receive any data back? Are those two errors always coupled?

If you can get some valid data followed by an Error 10225 bust some time later, see this thread: https://groups.io/g/twsapi/topic/69943076?p=Created,,,20,2,0,0::,,,0,0,0,69943076. The solution is basically to call cancelRealTimeBars() and immediate call reqRealTimeBars() again.

If the two errors are coupled, then there is an error with the request. Double check that you are subscribed for the level of data you are requesting. Additionally, can you receive valid data from reqHistoricalData()? If so, it's not the issue and will only complicate the debugging. For example, I was able to replicate the Error 321 only with calling reqHistoricalData() without qualifying the contract, reqRealTimeBars() gave a different error under the same circumstance.

fritol commented 2 years ago

Are you able to get any output at all from reqRealTimeBars() that is then followed by a bust event some time later, or are you not able to receive any data back? Are those two errors always coupled?

I get these errors immediately not a single bar received. Works for me fine on any other Index ...

Yes I can get historical data with reqHistoricalData() for those symbols, but not realtime.

I have valid data sub for these.

IB support asked me for full error logs from their servers.

This code:

from ib_insync import * ib = IB() ib.connect('127.0.0.1', 7001, clientId=1)# contract=Index('TRIN-NYSE') ib.qualifyContracts(contract) # optional barsList=[]

barsList=ib.reqRealTimeBars(contract, 5, 'TRADES', False) # optional ib.sleep(5) print(barsList) ib.disconnect()

results in:

Error 10225, reqId 4: Bust event occurred, current subscription is deactivated. Please resubscribe real-time bars immediately., contract: Index(conId=26718743, symbol='TRIN-NYSE', exchange='NYSE', currency='USD', localSymbol='TRIN-NYSE')

does it work for you @mrwillett ?

fritol commented 2 years ago

@mrwillett I reinstalled ib_insync in my conda env and now for the above code after hours I get no errors but also no data.

I will test again after NYSE reopens and will report back.

fritol commented 2 years ago

same thing Error 10225, reqId 4: Bust event occurred, current subscription is deactivated. Please resubscribe real-time bars immediately., contract: Index(conId=26718738, symbol='TICK-NYSE', exchange='NYSE', currency='USD', localSymbol='TICK-NYSE')

m12t commented 2 years ago

This is quite perplexing. Unfortunately, I'm not subscribed to NYSE indexes so I'm not able to test this on my machine any more than I did to verify that the code does work for other contracts. This definitely seems to be an error with IB and I'm afraid I've hit the limits of what I can do to diagnose this issue.

It might be worthwhile to post something in the discussion tab asking for anybody with a market data subscription for NYSE indexes to test just the following (during market hours, of course):

contract=Index('TRIN-NYSE')
ib.qualifyContracts(contract)
ib.reqRealTimeBars(contract, 5, 'TRADES', False)

Lastly, I just realized you were able to request histoical data successfully, but are you able to receive valid live data from good old reqMktData()? That's definitely worth noting, imo.

fritol commented 2 years ago

@mrwillett I am able to get live data for those indices in TWS. The subscription for these is in either 'US Securities Snapshot and Futures Value Bundle' or 'US Equity and Options Add-On Streaming Bundle'

Ill test the reqMktData()with tickers when mkt opens.

I'll also post in the discussion as u suggest.

fritol commented 2 years ago

ok i've posted to discussion: https://github.com/erdewit/ib_insync/discussions/485

erdewit commented 2 years ago

I can reproduce the "Bust event occurred" error for this contract. This is on IB's side and there's not really anything that can be done about it on the API side.

Note that reqMktData does work, so perhaps use that instead.

fritol commented 2 years ago

ok thx, ill send the full log to the geniuses at IB