¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: avgFillPrice returning zero

 

Some more details:

I'm using ib_insync to get a list of all trades from the current session, then getting the data for each trade. Not tracking orderID or anything since I'm relatively new and haven't gotten that to work for me yet. It seems like all the other trade data pulls up fine, so I'm not sure why avgFillPrice doesn't.

Relevant code:

ib = IB()
ib.connect('127.0.0.1', 7496, clientId=10)
tradesList = ib.trades()

for trade in tradesList:
     ticker = trade.contract.symbol
     buyOrSell = trade.order.action
     qty = trade.order.filledQuantity
     price = trade.orderStatus.avgFillPrice
     print("Trade: ", buyOrSell, ticker, '  qty: ', qty, 'price: ', price)


avgFillPrice returning zero

 

Hi,

When I call orderStatus.avgFillPrice for a completed trade, it keeps returning zero (even several hours after the trade).

I've had to sum up the quantities in each fill to get the average price, but it's often a bit off (not sure why).

Anyone have any ideas why AvgFillPrice would be zero?


Re: reqScannerSubscription() Documentation

 

Hi David,

Simpy try not to cancel your scanner subscription after getting scannerDataEnd and you'll see what's going on.
Basically it will send you periodic updates in the form of a whole list (no one will calculate the delta for you).
If I recall?correctly the time between those updates was too sporadic and different for different scanner types.
Also there is a limit of max 10 concurrently running scanner subscriptions, so if you want to run more (for example you exploring different scanner types and/or you decided that 50 rows isn't enough and you also want to split one particular?scanner type into multiple price ranges to get more granular picture on different price levels, etc.) - in this case "max 10 scanners" with only 50 rows maximum in the result is quite harsh limit. So instead of sitting and waiting for the next update from IB I implemented the scanner logic exactly the way you described?it (cancel right after getting the end of results). This?way I was able to run 32 different scanners once per minute (it takes about 35-40 seconds to loop them all). Just make some sort of a container for your 10 "currently active" ones and maintain?the queue of those other scanners waiting in line, and rotate them accordingly.

Cheers,
Dmitry Shevkoplyas


On Tue, Mar 2, 2021 at 6:47 AM David Armour <dave.armour@...> wrote:
I have been re-writing some scanner code recently and I thought of changing my code which currently does this:

1) Call reqScannerSubscription
2) Read all scannerData() callbacks
3) Cancel subscription after receiving the scannerDataEnd() callback.

I have steps 1 to 3 run on a timer every few minutes but I thought of changing this to just let the scanner automatically update me. According to the poor documentation:

?? "Since the request keeps a subscription open you will keep receiving periodic updates until the request is cancelled via :"

but there is no details on how this works. On the periodic update does it just give you those changes or does it give you the whole list again? If it gives only changes, how does it reflect symbols that have dropped off the list?

Does anyone actually know how this works, or am I going to have to write some code to find it out?

Perhaps I am better off sticking to my existing flow. Thoughts?


Purchase Date for Tax Purposes

Joel Gross
 

Has anyone built any code to get the purchase date of positions in your account so that you can take into account short term vs long term capital gains tax??

If so, would you mind sharing your approach?


reqScannerSubscription() Documentation

 

I have been re-writing some scanner code recently and I thought of changing my code which currently does this:

1) Call reqScannerSubscription
2) Read all scannerData() callbacks
3) Cancel subscription after receiving the scannerDataEnd() callback.

I have steps 1 to 3 run on a timer every few minutes but I thought of changing this to just let the scanner automatically update me. According to the poor documentation:

?? "Since the request keeps a subscription open you will keep receiving periodic updates until the request is cancelled via :"

but there is no details on how this works. On the periodic update does it just give you those changes or does it give you the whole list again? If it gives only changes, how does it reflect symbols that have dropped off the list?

Does anyone actually know how this works, or am I going to have to write some code to find it out?

Perhaps I am better off sticking to my existing flow. Thoughts?


Re: Connectivity between IB and Trader Workstation has been lost

 

¿ªÔÆÌåÓý

IBC is irrelevant in this, and cannot do anything about it. TWS keeps running through the reset period, so as far as IBC is concerned everything is fine.

?

Even if your API program decides to somehow shut down TWS when this happens (for example by sending a STOP command to IBC via its command server), and then you restart TWS, it wouldn't make the lightest difference if the reset period is still in progress. During the reset period, which is usually actually pretty short, all bets are off. IB make this perfectly clear ¨C the suggestion that it is or should be illegal is simply bizarre. It would be nice if it were not so, but it is and there is nothing we can do about it. If it prevents you making important trades and causes missed opportunities, then find another broker¡­

?

For what it's worth, I actually configure my TWS to auto-shutdown just before the UK reset period and then restart a few minutes later. I still get 1100s and the other related 'error' messages, but I just deal with them, resubscribing to market data if need be.

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of Bruce B
Sent: 01 March 2021 16:46
To: [email protected]
Subject: Re: [TWS API] Connectivity between IB and Trader Workstation has been lost

?

It is a total mess between 12am to 1am EST which corresponds to your GMT timezone.

?

All sorts of wired behaviour happens at this hour. It is definitely not a clean maintenance window. You are not alone. I know exactly what you mean with missed opportunities around those hours. I think this should be or is illegal. But that's just my opinion.

?

Maybe IBC has a flag to restart multiple times with this error or at this hour. That still may not give you connectivity but may connect you faster if there is a delay in connection attempt by TWS.

?

- Bruce

?

On Mon, Mar 1, 2021, 4:34 AM <jmgwalker@...> wrote:

Hi all,

I was hoping someone here might have seen this error message before and know what to do. I've been in contact with the IB API team, but they don't know what's causing it.

At about 5.30am GMT every day my TWS loses connection to the IB servers. The TWS displays a message that it is trying to reconnect to the IB servers, which takes several minutes and attempts. My TWS restart is scheduled for 9.45pm so it's not that.

While this is happening I get the following error repeatedly from the API:

Error 1100, reqId -1: Connectivity between IB and Trader Workstation has been lost.

Until connection is restored and I get this message:

Error 1102, reqId -1: Connectivity between IB and Trader Workstation has been restored - data maintained. All data farms are connected: cashfarm; euhmds; cashhmds; secdefeu.

The IB API team suggested that it could be my local network, or internet service provider. I confirmed this wasn't the case by running from a different machine on a different network.

They also suggested that it could be a server-side issue on their end and that I should monitor their servers (). I was able to ping their European server continuous through this issue.

I'm using stable release 978 of TWS.

It's a bit annoying because I have a trade that tries to execute at this time which can lead to either a lengthy delay in it being filled, or not being filled at all.

Any advice would be gratefully received. Thanks.


Re: Connectivity between IB and Trader Workstation has been lost

 

It is a total mess between 12am to 1am EST which corresponds to your GMT timezone.

All sorts of wired behaviour happens at this hour. It is definitely not a clean maintenance window. You are not alone. I know exactly what you mean with missed opportunities around those hours. I think this should be or is illegal. But that's just my opinion.

Maybe IBC has a flag to restart multiple times with this error or at this hour. That still may not give you connectivity but may connect you faster if there is a delay in connection attempt by TWS.

- Bruce

On Mon, Mar 1, 2021, 4:34 AM <jmgwalker@...> wrote:
Hi all,

I was hoping someone here might have seen this error message before and know what to do. I've been in contact with the IB API team, but they don't know what's causing it.

At about 5.30am GMT every day my TWS loses connection to the IB servers. The TWS displays a message that it is trying to reconnect to the IB servers, which takes several minutes and attempts. My TWS restart is scheduled for 9.45pm so it's not that.

While this is happening I get the following error repeatedly from the API:
Error 1100, reqId -1: Connectivity between IB and Trader Workstation has been lost.

Until connection is restored and I get this message:
Error 1102, reqId -1: Connectivity between IB and Trader Workstation has been restored - data maintained. All data farms are connected: cashfarm; euhmds; cashhmds; secdefeu.

The IB API team suggested that it could be my local network, or internet service provider. I confirmed this wasn't the case by running from a different machine on a different network.

They also suggested that it could be a server-side issue on their end and that I should monitor their servers (). I was able to ping their European server continuous through this issue.

I'm using stable release 978 of TWS.

It's a bit annoying because I have a trade that tries to execute at this time which can lead to either a lengthy delay in it being filled, or not being filled at all.

Any advice would be gratefully received. Thanks.


Re: Connectivity between IB and Trader Workstation has been lost

Nick
 

This is the daily IB server restart, there is nothing you can do about it.

The messages tell you when it happens. There is also a message (1101) that tells you that subscriptions were lost and you have to resubscribe.

It's unbelievable that they told you they don't know what this is. The server restart has been there since the beginning.

On 3/1/2021 4:13 AM, jmgwalker@... wrote:
At about 5.30am GMT every day my TWS loses connection to the IB servers. The TWS displays a message that it is trying to reconnect to the IB servers, which takes several minutes and attempts. My TWS restart is scheduled for 9.45pm so it's not that.


Re: Connectivity between IB and Trader Workstation has been lost

Stuart Cracraft
 

Bummer. Wish it had auto-restart past those or through those. Seems odd.

On Mar 1, 2021, at 3:01 AM, Mikhail Ershov <misha-ershov@...> wrote:

Probably you're catching an every-day hour of server maintenance
05:45 - 06:45 CET in Europe


Re: Connectivity between IB and Trader Workstation has been lost

 

Thanks Mikhail, that's very helpful to know about.


Re: Connectivity between IB and Trader Workstation has been lost

 

Probably you're catching an every-day hour of server maintenance
05:45 - 06:45 CET in Europe


Connectivity between IB and Trader Workstation has been lost

 

Hi all,

I was hoping someone here might have seen this error message before and know what to do. I've been in contact with the IB API team, but they don't know what's causing it.

At about 5.30am GMT every day my TWS loses connection to the IB servers. The TWS displays a message that it is trying to reconnect to the IB servers, which takes several minutes and attempts. My TWS restart is scheduled for 9.45pm so it's not that.

While this is happening I get the following error repeatedly from the API:
Error 1100, reqId -1: Connectivity between IB and Trader Workstation has been lost.

Until connection is restored and I get this message:
Error 1102, reqId -1: Connectivity between IB and Trader Workstation has been restored - data maintained. All data farms are connected: cashfarm; euhmds; cashhmds; secdefeu.

The IB API team suggested that it could be my local network, or internet service provider. I confirmed this wasn't the case by running from a different machine on a different network.

They also suggested that it could be a server-side issue on their end and that I should monitor their servers (). I was able to ping their European server continuous through this issue.

I'm using stable release 978 of TWS.

It's a bit annoying because I have a trade that tries to execute at this time which can lead to either a lengthy delay in it being filled, or not being filled at all.

Any advice would be gratefully received. Thanks.


I don't understand historical 5-second bar volume

Charles
 

Hey,
I'm new to this group, so please have mercy on me.

I trying to use "reqHistoricalData" to get 5-second bar data.? I don't understand what the "bar.Volume" means.

For example, I have IQFeed.net and I downloaded all the trades for symbol "A" on Friday, February 26, 2021.
The IQFeed showed a total volume of?1,319,476.

I looked at finance.yahoo.com and they show a total volume for A to be?1,909,665.

To get the total volume for "A" from TWS, I added all the "bar.Volume" data. This gave me a total volume for the day of?8,992.

Does a "bar.Volume" of 3 mean 300 shares traded during that 5-second interval?

When I sum all the "bar.Volume" data for stock "A", why is the amount so low?

Charles


Re: Expiring Limit order

 

I believe this should work in C# for a start:
order.Tif = "GTD";
order.GoodTillDate = "20210228 12:00:00";
Note that this will refer to TWS default timezone. Another timezone can be specified with the date-time, though I'm not sure which format to use. I rarely code raw api objects from scratch nowadays since I use a higher level of abstraction, so I can forget some details. See the api documentation for more information.


Excel VBA Code for downloading Interactive Brokers price history and Option Chains

 

Does anyone have excel VBA code that downloads interactive brokers price history and current option chains?


Re: Expiring Limit order

 

ds-avatar, can you please put an example with order expiring at noon? Thanks a lot!


Re: Expiring Limit order

 

Setting order's expiry time using the field GoodTillDate with Tif="GTD"?will usually be much less cumbersome and limiting in many ways than attaching the condition.

Despite the name, this option allows setting a precise time of day beside the date.



§ã§Ò, 27 §æ§Ö§Ó§â. 2021 §Ô., 07:52 Alex Gorbachev <ag@...>:

I'd like to place a limit order that expires in 60 seconds.

I'm using the ib-insync Python module.
After reading docs, googling and some experiments I figured that this works:
? ? order = ibi.LimitOrder('BUY', 100, 42)
? ? until_time = ibi.util.formatIBDatetime(datetime.datetime.utcnow() + timedelta(seconds=60))
? ? order.conditions = [ibi.TimeCondition(isMore=False, time=until_time)]
? ? order.conditionsCancelOrder = True
? ? trade = ib.placeOrder(contract, order)

I wanted to confirm if this is the correct way of doing it or there are better ways.

Also, I wanted to place a stop limit order where limit order would expire 60 seconds after it becomes active (i.e.?once it's activated by price touching the stop level). Is that even possible or I just need to subscribe to ticks/market data and place my expiring stop limit order manually?

Thanks in advance,
Alex


Expiring Limit order

 

I'd like to place a limit order that expires in 60 seconds.

I'm using the ib-insync Python module.
After reading docs, googling and some experiments I figured that this works:
? ? order = ibi.LimitOrder('BUY', 100, 42)
? ? until_time = ibi.util.formatIBDatetime(datetime.datetime.utcnow() + timedelta(seconds=60))
? ? order.conditions = [ibi.TimeCondition(isMore=False, time=until_time)]
? ? order.conditionsCancelOrder = True
? ? trade = ib.placeOrder(contract, order)

I wanted to confirm if this is the correct way of doing it or there are better ways.

Also, I wanted to place a stop limit order where limit order would expire 60 seconds after it becomes active (i.e.?once it's activated by price touching the stop level). Is that even possible or I just need to subscribe to ticks/market data and place my expiring stop limit order manually?

Thanks in advance,
Alex


Re: FXCONV support in API?

 

Hi Josh,

Where is supported? in market data streaming or in orders? I don't see any mention of it in API. Is it spelled as fxconv?

For virtual positions reporting you mean settings of TWS or settings of account from Web Portal?

Thanks,


Re: Getting full list of Exchange Listings via API.

 

There are 253 now on IBKR. You can request this from API using?reqMktDepthExchanges().



- Bruce


On Thu, Feb 18, 2021 at 06:28 PM, Aquiles P¨¢ez wrote:
Hello,?

Is it possible to request the complete list of Exchanges permitted? by IB using the API??

Also, are the contents of the all there is available for trading inside TWS??

I appreciate in advance any help you might provide.?