开云体育

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

Re: OptContract Lookup

 

开云体育

There is no strike 119 for that expiry. 115 or 120 are the nearest strikes.

?

It took me about a minute to find this out using my Contract Inspector program, which you can get from Github at:

?

?

See attached screenshot.

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of Crow
Sent: 03 March 2021 05:53
To: [email protected]
Subject: [TWS API] OptContract Lookup

?

I am trying to lookup contract details (socket.reqContractDetails()) of the following option contract (com.ib.client.Contract.OptContract):

?

conid 0

symbol XLY

secType OPT

lastTradeDateOrContractMonth 20210416

strike 119.0

right C

exchange SMART

currency USD

?

I get error code 200:?No security definition has been found for the request

?

Anyone know what is wrong with my request?

?

?


Re: OptContract Lookup

 

开云体育

Strike 119.0 does not exist, try a multiple of 5. You do not need you specify the exchange.

downloaden


Re: SLOW connection times

 

Then you have your troubleshoot mapped already. It's not your program.

1- Change TWS version on remote side (less likely to be the issue)

2- Check your network (connect directly to modem and disconnect ALL other wired and wireless devices.

3- Check remote side network and servers (like step 2)

4- Check IP Transit (ping, traceroute, etc / most likely not your problem)

On Tue, Mar 2, 2021, 9:11 PM ExStock <exstock@...> wrote:
Already done, and it connects no problem to that, although it's a more updated version--978, whereas I think the server's version is 976.


Re: OptContract Lookup

 

I'm not sure, probably SMART as exchange not working for options lookup.
Try to pass 'CBOE' as exchange name


Re: reqScannerSubscription() Documentation

 

Thanks Dmitry.

It looks like what I am doing already is still the best approach. I will stick to what is not broken!


OptContract Lookup

 

开云体育

I am trying to lookup contract details (socket.reqContractDetails()) of the following option contract (com.ib.client.Contract.OptContract):

conid 0
symbol XLY
secType OPT
lastTradeDateOrContractMonth 20210416
strike 119.0
right C
exchange SMART
currency USD

I get error code 200:?No security definition has been found for the request

Anyone know what is wrong with my request?



Re: SLOW connection times

 

Already done, and it connects no problem to that, although it's a more updated version--978, whereas I think the server's version is 976.


reqTickers on paper account - bid/ask stay still for long times

 

When I request current ticker with reqTickers in succession, bid/ask stay unchanged for long time like minutes order of magnitude while “last” is updated consistently every time. This is on paper account. I use reqMarketDataType(3).

Anyone saw this anomaly?
I observed with both Stock and Forex contracts and both outside and within RTH.
Yesterday and today, for example.

Is my understanding of the delayed data wrong or I shouldn’t expect consistent data in paper trading?

Thanks in advance,
Alex


Re: SLOW connection times

 

Download TWS on same PC as you have your program and connect locally to 127.0.0.1 to rule out any network and IP Transit issues.

- Bruce

On Tue, Mar 2, 2021, 4:55 PM ExStock <exstock@...> wrote:
I always connect to IB through the TWS python API. We run TWS itself on a server; the python code runs locally on my PC.? Until recently, establishing a connection to IB this way took <2 seconds, and was usually almost instantaneous.? For the past couple of weeks, though, the time required to establish a connection has ranged between ~30 seconds and a whopping ~4 minutes.? The TWS running on the server has also started using about twice as many resources as it used to.?

Nothing has changed on our end, apart from the recent dramatic cold snap, which hit extra hard here in TX.?We've checked and rechecked our system and code, and found nothing. We've also scaled back the amount of data we're requesting from IB, with no improvement resulting.? (I already had several measures in place to make sure I wasn't hitting IB with too many requests at a time.)

Is anyone else suffering slow connection times?? Is my crazy idea that some parts of IB's infrastructure (or key employees) were affected by the cold snap as crazy as it sounds to me?? Or is it something simple like needing to update my TWS?? (I can't easily check my version right now, but it's ~6 months old.? We like finding a nice stable version and sticking with it for a while, which is why we haven't tried that yet as part of our troubleshooting.)


Re: avgFillPrice returning zero

 

开云体育

If you're using ib_insync, you should ask this question at /g/insync

?

This group is for the APIs provided by IBKR only.

?

Thanks

?

Richard King

TWSAPI Group Owner and Moderator

?

?

?

From: [email protected] <[email protected]> On Behalf Of sunyc45@...
Sent: 02 March 2021 21:39
To: [email protected]
Subject: Re: [TWS API] 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)
?


Can't modify bracket order - ONLY stop loss quantity won't update

 

Hello,

When I try to modify a placed bracket order by resubmitting it with different parameters, all of my changes go through (as verified in TWS), EXCEPT for the "quantity" for the stop loss order, which remains unchanged. At first I passed the new share amount to totalQuantity of the parent order only, but since it didn't work, I tried as well passing it to all of them.

# placing original bracket order
shares = 26
limit_price_buy = 25
limit_price_take_profit = 28
aux_price = 20
order = ib.bracketOrder('BUY', 
                             shares, 
                             limit_price_buy, 
                             limit_price_take_profit, 
                             aux_price, 
                             outsideRth=True, 
                             tif='GTC', 
                             usePriceMgmtAlgo=True)

contract = Stock('CCIV', 'SMART', 'USD')
order_results = []
for o in order:
    order_results.append(ib.placeOrder(contract, o))


# modifying and placing previous bracket order
contract = Stock('CCIV', 'SMART', 'USD')
order.parent.update(totalQuantity=20, lmtPrice=25, transmit = False)
order.takeProfit.update(totalQuantity=20, lmtPrice=27, transmit = False)
order.stopLoss.update(totalQuantity=20, auxPrice=19, transmit = True)

order_results = []
for o in order:
    order_results.append(ib.placeOrder(contract, o))


Any ideas on what could be happening?


SLOW connection times

 

I always connect to IB through the TWS python API. We run TWS itself on a server; the python code runs locally on my PC.? Until recently, establishing a connection to IB this way took <2 seconds, and was usually almost instantaneous.? For the past couple of weeks, though, the time required to establish a connection has ranged between ~30 seconds and a whopping ~4 minutes.? The TWS running on the server has also started using about twice as many resources as it used to.?

Nothing has changed on our end, apart from the recent dramatic cold snap, which hit extra hard here in TX.?We've checked and rechecked our system and code, and found nothing. We've also scaled back the amount of data we're requesting from IB, with no improvement resulting.? (I already had several measures in place to make sure I wasn't hitting IB with too many requests at a time.)

Is anyone else suffering slow connection times?? Is my crazy idea that some parts of IB's infrastructure (or key employees) were affected by the cold snap as crazy as it sounds to me?? Or is it something simple like needing to update my TWS?? (I can't easily check my version right now, but it's ~6 months old.? We like finding a nice stable version and sticking with it for a while, which is why we haven't tried that yet as part of our troubleshooting.)


Re: FXCONV support in API?

 

yes 'FXCONV' is only for placing orders, just like in TWS. There is a setting in TWS at Global Configuration -> API -> Settings -> 'Include Virtual FX positions when sending portfolio' that can be unchecked to prevent virtual positions from being returned.?


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 – 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.