¿ªÔÆÌåÓý

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

How to connect to TWS from server side

 

I'm looking to set up a connection from my database server to TWS running on my local machine, however I'm not sure what kinds of configuration is correct:
I have had success with using revers
e SSH tunnel using these instructions:




However I'm getting this error on the second step when trying to use the same method but modifying for connecting to port 7496 instead of the standard 22:




A couple of questions:
1. Am I on the right track? Is this the right approach to use to set up this kind of connection?
2. Are we supposed to connect to port 7496 as I assumed here?
3. Is there a way to connect using Python? There is the sshtunnel library and it would be nice that I could leverage it to connect in the same script that I use to pull data

Any help is very much appreciated, TIA!


Re: Placing a crypto order

Ewald de Wit
 

Ah yes, it's for US residents only. The crypto market data is available though, complete with fractional sizing and volume as made possible in the latest API.

-- Ewald


Re: Placing a crypto order

 

I'm not positive, but pretty sure that I read that IB crypto was, at this stage, only open to US residents.

Not sure where you are, but I am in Australia, I don't get any crypto when I search IB, and Crypto is not in Account Management when I try to request trading permission. The only crypto I see is CME futures, plus a couple of stocks with crypto related names.

KH


Re: Placing a crypto order

Ewald de Wit
 

Thanks for the link Kevin. Using this order:

order = Order(orderType='MKT', action='BUY', cashQty=5000, tif='IOC')

does get one step further, which in my case is a 'No trading permissions' error. Not sure how to add the permissions either as there seems to be no Crypto products listed in account management.

-- Ewald


Re: Placing a crypto order

 

I'm not sure as I don't have permissions to even test this, can't even see the symbol BTC, but this IB web page may help.
Apparently IB is looking for a time option as part of the order, try replacing MKT with IOC.

KH


Placing a crypto order

Ewald de Wit
 

Hi all,

Has anyone figured out how to place a CRYPTO order yet? When I try with

contract = Contract(secType='CRYPTO', symbol='BTC', exchange='SMART', currency='USD')
order = Order(orderType='MKT', action='BUY', cashQty=5000)

it gives the error Invalid time in force:???. Setting order.tif to DAY or GTC is not accepted either.

-- Ewald


Re: Version 10.10 of Gateway.

 

Craig,

I'm having some of these issues myself. How have you resolved them?

Thanks for any insights.
Tyler


TWS vs Gateway 981 - TickTypeEnum

 

Is anyone else seeing a difference in the TickTypeEnum between TWS & Gateway (981).? I would expect them to be identical...?


Re: Group Ownership updated

 

Richard, thanks again for all your contributions. I'm sure I speak for many others when saying without your thoughtful inputs in this group, I would never have been able to understand and use the API. Best of luck in your future endeavours!

Alex


Re: Version 10.10 of Gateway.

Craig Carr
 

The last forced upgrade broke F&F accounts pretty good:
- Different P/Ls in different TWS windows.
- Complete garbage in account update values.
- SMART no longer routing to lowest cost.
- Leftover shares after trade close due to errors in allocation.
981.3c and the next version still have all these problems, I had to prove to them 10 still had these problems.
IB's QA is garbage.


Re: Version 10.10 of Gateway.

Nick
 

¿ªÔÆÌåÓý

I don't know if this question is directed at me, but it's not a technical issue but a matter of what you need for your particular trading strategy.

For example the TickByTick data is a relatively recent addition. If you were using an older version but TickByTick data would have a significant benefit to you then looking into a TWS update would make sense.

If you currently have everything you need then no reason to update unless a new feature would be worth the effort.

On 10/3/2021 4:44 PM, Traveler wrote:

The "offline stable" version of TWS is 981.3c. What missing features would preclude using that version?



Re: Version 10.10 of Gateway.

 

Release notes for TWS are at For most users, 981.3c should work just fine.

´³¨¹°ù²µ±ð²Ô


Re: Version 10.10 of Gateway.

 

The "offline stable" version of TWS is 981.3c. What missing features would preclude using that version?


Re: Parent order missing

 

There may be nothing wrong with your approach and the issue may very well be with the 985 line of TWS versions. We are running TWS 985.1k as well but with API 9.85.2 "latest" and have no issues. But our order structure is quite simple so we would not trigger the issues you are seeing.

The curious thing for me is that the 985 series of TWS and API have "disappeared" in the sense that:

  • The stable API still is 9.76 from May 8, 2019
  • The latest API is now 10.10 from September 22, 2021

And on the TWS side:

  • Stable TWS is 981.3c
  • Latest TWS is 10.10.2p

The size fields in some of the callbacks in 985 changed from "int" to "long" just to change to "Decimal" in 10.10. That probably goes along with significant and possibly destabilizing changes inside TWS-IBGW.

Maybe it is time to reach out to IB unless you can do a quick trial with TWS 981.3c or 10.10.2p.

´³¨¹°ù²µ±ð²Ô


On Fri, Oct 1, 2021 at 09:10 AM, <sede@...> wrote:
Yes, I use nextValidId(), and then increment values myself, for example like this:
? long 3641 short 3721 tp 3722 sl 3723 tp long 3742 sl long 3743

I use tws Build 985.1k and api 9.85.1

I noticed there is another, possibly unrelated, problem which happens randomly. After placing all 6 orders, the first one is rejected with error:

Error, reqId:? 3641? errorCode: 201 Order rejected - reason:Cannot have open orders on both sides of the same US Option contract.

All child orders then also are rejected, since parent is missing. The instruments are options, and I didn't place any orders before for these specific contracts before. Does IB not understand the relationship between parent - child orders, and thinks that stop loss or take profit sell order would be an opposite side to initial buy order, and that is why it rejects initial buy order? There seems to be a lot of randomness involved, since the same contract combination works just fine after few retries.


Re: Parent order missing

 

I wish it was that simple, but no.


Re: Parent order missing

 

do you have other open positions at the time of placing the order?? You cannot be long & short on the same contract at the same time.?

On Fri, Oct 1, 2021 at 7:10 AM <sede@...> wrote:
Yes, I use nextValidId(), and then increment values myself, for example like this:
? long 3641 short 3721 tp 3722 sl 3723 tp long 3742 sl long 3743

I use tws Build 985.1k and api 9.85.1

I noticed there is another, possibly unrelated, problem which happens randomly. After placing all 6 orders, the first one is rejected with error:

Error, reqId:? 3641? errorCode: 201 Order rejected - reason:Cannot have open orders on both sides of the same US Option contract.

All child orders then also are rejected, since parent is missing. The instruments are options, and I didn't place any orders before for these specific contracts before. Does IB not understand the relationship between parent - child orders, and thinks that stop loss or take profit sell order would be an opposite side to initial buy order, and that is why it rejects initial buy order? There seems to be a lot of randomness involved, since the same contract combination works just fine after few retries.


Re: Parent order missing

 

Yes, I use nextValidId(), and then increment values myself, for example like this:
? long 3641 short 3721 tp 3722 sl 3723 tp long 3742 sl long 3743

I use tws Build 985.1k and api 9.85.1

I noticed there is another, possibly unrelated, problem which happens randomly. After placing all 6 orders, the first one is rejected with error:

Error, reqId:? 3641? errorCode: 201 Order rejected - reason:Cannot have open orders on both sides of the same US Option contract.

All child orders then also are rejected, since parent is missing. The instruments are options, and I didn't place any orders before for these specific contracts before. Does IB not understand the relationship between parent - child orders, and thinks that stop loss or take profit sell order would be an opposite side to initial buy order, and that is why it rejects initial buy order? There seems to be a lot of randomness involved, since the same contract combination works just fine after few retries.


Re: Version 10.10 of Gateway.

Nick
 

IB occasionally breaks things. From your's and Jurgen's findings it appears this is one of those times.

The best defense is when you find a TWS/Gateway version that works just keep using that, even if it's for a year or two. Only upgrade to a new version when you are forced or if you need a new feature.

On 10/1/2021 5:07 AM, Kevin wrote:
I don't have enough experience with this aspect of TWS or Gateway, so I'm going back to stable for tonight, then I'll do new installs for both TWS and IBG over the weekend.


Re: Version 10.10 of Gateway.

 

A further update to this: I've just started TWS for the US Friday session, no change in my Python code, the computer hasn't been used since being turned off after the Thursday session. Now I'm getting Java errors in here too.
Error 322, reqId 3: Error processing request.-'cc' : cause - jextend.cc.n(cc.java:310)
I re-signed in using stable (TWS 981.3c), and the Python script runs without any problems. I am yet to start IBG.

I don't have enough experience with this aspect of TWS or Gateway, so I'm going back to stable for tonight, then I'll do new installs for both TWS and IBG over the weekend.

KH


Re: Version 10.10 of Gateway.

 

On Fri, Oct 1, 2021 at 01:14 AM, ´³¨¹°ù²µ±ð²Ô Reinold wrote:
The "Quote Details" window would suddenly not update any longer,
The chart would still update the trades properly, but the A/B indicator on the Y axis would be stuck at the same price that the "Quote Details" window showed
Hello,

I solve this problem in TWS 10.10.2p by changing to the Classic TAB, then back to the Mosaic TAB. The other solution is to Reconnect all Farms. Saves having to restart.

KH