Keyboard Shortcuts
Likes
- Ib-Async
- Messages
Search
Re: ib.reqTickers() conflicts with ib.reqTickByTickData()
thank you for replying, I have identified the problem: the reqTickers was nested in the reqTickByTickData, so I changed the App structure. BTW do you know the function to use for nested call (even though I remember that nested asyncio and blocking was not recommended)? best |
|
Re: Live and paper data mixed
What seems to be happening is the instance of IB() is keeping data and not actually sending a request to TWS. The API logs only show one request being sent per connection, not the two I was expecting from the code above. If I have two instances of IB(), and switch between those, I get correct data. Just disconnecting, changing port, and reconnecting within the same instance of IB() seems to be causing the confusion. Any delay between disconnect and reconnect, makes no difference as long as it's still the same instance of IB(). Could someone who maintains the library investigate? |
|
Re: Live and paper data mixed
开云体育Hi Glen, ? I have a similar setup but do not switch programmatically between the 2 gateways. However, how about adding a delay between the switching? This would ensure connection closure. ? Pranav |
|
Live and paper data mixed
I have a program that will place trades in either the paper or live account. I run both platforms simultaneously on the same machine. It crashes when I try get my account value after switching from one to the other because I get the first result over again. I have a support ticket in with IB, but they keep suggesting it's my code. Can anyone here create the problem to help me sort this out? With two instances of TWS open, one paper and one live, here's the simplest code I've run to show the problem: from ib_async import * def ensure_connection(ib: IB, host: str, desired_port: int, client_id: int): """Ensure IB is connected to the desired port. Reconnect if necessary."""
ib = IB() IBPort = 7496 ensure_connection(ib, "127.0.0.1", IBPort, 33) print(ib.isConnected()) print(ib.client.port) SummaryAccountValue = ib.accountSummary() print(SummaryAccountValue) IBPort = 7497 ensure_connection(ib, "127.0.0.1", IBPort, 33) print(ib.isConnected()) print(ib.client.port) SummaryAccountValue = ib.accountSummary() print(SummaryAccountValue) ib.disconnect() print(ib.isConnected()) print(ib.client.port) IBPort = 7497 ensure_connection(ib, "127.0.0.1", IBPort, 33) print(ib.isConnected()) print(ib.client.port) SummaryAccountValue = ib.accountSummary() print(SummaryAccountValue) IBPort = 7496 ensure_connection(ib, "127.0.0.1", IBPort, 33) print(ib.isConnected()) print(ib.client.port) SummaryAccountValue = ib.accountSummary() print(SummaryAccountValue) ib.disconnect() ''' ib.fills also seems to have problems. For the first connection, it will show correct information, but on the second connection, it will show the first plus the second. Is there a problem somewhere in the ib_async library or is this an IB issue? Can anyone reproduce this or suggest how I can fix it? Glenn |
|
Re: Clicking an override button
Hi all,
toggle quoted message
Show quoted text
I am answering my own question. I suspect I need to specify order conditions and allow the advancedErrorOverride flag. How do I do this? Pranav -----Original Message-----
From: Pranav Lal <pranav@...> Sent: Monday, March 24, 2025 1:36 PM To: '[email protected]' <[email protected]> Subject: Clicking an override button Hi all, I have recently begun getting messages that a security is under surveillance. The exact entry in my program's log is below. 2025-03-24 06:59:15,321 ib_async.wrapper ERROR Error 201, reqId 7: Order rejected - reason:Security is under Surveillance Measure - The scrip PE is greater than 50 for the previous 4 trailing quarters.<br><br><br>Would you like to continue?. How do I click yes programmatically? Pranav |
|
Clicking an override button
Hi all,
I have recently begun getting messages that a security is under surveillance. The exact entry in my program's log is below. 2025-03-24 06:59:15,321 ib_async.wrapper ERROR Error 201, reqId 7: Order rejected - reason:Security is under Surveillance Measure - The scrip PE is greater than 50 for the previous 4 trailing quarters.<br><br><br>Would you like to continue?. How do I click yes programmatically? Pranav |
|
Re: ib.reqTickers() conflicts with ib.reqTickByTickData()
These two methods are very different:
?
|
|
Re: Unable to determine when an order is submitted
开云体育Hi Elat, <snip Moreover the status gets fired once and not for each status. PL] Ouch, that is one reason why my code is not executing the way I expect. I’ll do some tweaking. ? Thanks for your input. Pranav |
|
ib.reqTickers() conflicts with ib.reqTickByTickData()
Hello Everyone, when building the APP (not in a notebook Jupyter), if call the ib.reqTickers() after having called ib.reqTickByTickData() it goes in overflow and crashes. But, if I call reqTickers() before reqTickByTickData works perfectly! I have tried with ib.sleep(30) but nothing. Any help? Thank you. |
|
Re: Unable to determine when an order is submitted
Might work in simulation, but remember in real trade there will be delay after placing order:
?
? ? stop_loss_trade = ib.placeOrder(contract, stop_loss_order) # BELOW might not be true always so quickly! ? ? if stop_loss_trade.isActive(): ? You should stick to event driven for robustness as you had before. |
|
Re: Unable to determine when an order is submitted
开云体育Hi biney59, Thanks for your suggestion. ? I got rid of the event logic and the program is working as I want it to at least in the simulator. ? Here is a snippet of the modified code. ? ? # Create the limit order (parent order) ? ? limit_order = LimitOrder(order_type, order_quantity, limit_price, outsideRth=True, transmit=False) ? ? ? ? # Place the limit order ? ? print("Placing limit order") ? ? parent_trade = ib.placeOrder(contract, limit_order) ? ? ? ? # Create the stop loss order (child order) ? ? stop_loss_order = Order() ? ? stop_loss_order.action = stop_loss_action ? ? stop_loss_order.orderType = "STP" ? ? stop_loss_order.totalQuantity = order_quantity ? ? stop_loss_order.auxPrice = stop_loss_price ? ? stop_loss_order.parentId = parent_trade.order.orderId ? ? stop_loss_order.transmit = True ? ? ? ? # Place the stop loss order (this transmits both orders) ? ? print("Placing stop loss order") ? ? stop_loss_trade = ib.placeOrder(contract, stop_loss_order) ? ? if stop_loss_trade.isActive(): ? ? ? ? ib.disconnect() ? ? ? ? print("Exiting") ? ? ? ? sys.exit(0) ? ? # Run the event loop to process order status updates ? ? ib.run() ? ? Pranav |
|
Re: Unable to determine when an order is submitted
PreSubmitted is not the status you want, as that still does not mean active. What you want is Submitted. You can look at for different possible statuses.
?
But for your case, even simpler, trade object already has method which will verify if Submitted. Use that. |
|
Unable to determine when an order is submitted
Hi all,
I am unable to determine when an order is submitted. See the below code of my on_order_status event. What am I doing wrong? The on_order_status event does fire. I suspect I have the if condition wrong but am not certain. # Event handler for order status updates def on_order_status(trade): print("order status event fired") if trade == stop_loss_trade and trade.orderStatus.status == "PreSubmitted": print("Stop loss order submitted, disconnecting.") ib.disconnect() sys.exit(0) Pranav |
|
Re: groups of events into one event
开云体育Hi, You are referring to the ib_async.IB() events, which will emit updates for any ticker that is active. But there is a ticker event too, which will only emit when that particular ticker has updates. Which is what I think you are asking for |
On 17 Mar 2025, at 05:51, in_woolloomooloo via groups.io <brendan.t.sands@...> wrote:Hi,When using TickerUpdateEvent, or pendingTickersEvent, is there a way to collect individual stock events into a grouped event......for example if I have 10 stocks in a portfolio that is streaming ticks but i want an event to occur only over a set of say 5 of those stocks. I seem to remember seeing something from Ewald where he collected several events into 1....maybe Im not remembering correct as i cant find it now!!!?Asking the question an alternate way, what would be the most efficient/fastest way for say 2 sets of 5 stock portfolios to respond to events over their respective holdings, and not have to also filter through the events of the other 5 also??ThanksB.