开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育
Date

TWS multiple connections question

 

I have multiple programs that are each looking at different things, so, the each independently will need to place an order. My question is, is there anything wrong with that or a reason it won't work. From what I?can tell, there isn't an active ongoing connection between TWS and anything that would place an API call, the call is placed and the resulting processes take place, and that's that.?

So in this regard, what concerns should I have? Has anyone else done this and experienced any issues?if two calls are placed at the same time for example? Or, am I?missing something and this is not something that is going to work and I need to figure out some alternatives?

Thanks in advance for all the help!

-Rob


Re: Confirming order executions

 

Over thousands of API entered orders I've only had a problem once and I'm not even sure what caused that.? So it's not clear what the technical answer is, but the practical answer is that order updates arrive just fine.

But even with that I don't depend too much on the quality of information coming back from IB.? There are limits on the orders my software will enter to provide a margin of safety.


Confirming order executions

 

The IB TWS API documentation suggests that some of the orderStatus
states may not be transmitted, using the example of a market order in
a fast-moving market.

I am left unsure if I can depend on the "Filled" order status being
returned as a message. Given that I am only placing Limit and Trail
Limit orders, never Market orders, should I worry about checking up on
orders with execDetails via reqExecutions? Or am I at least safe in
expecting a "Filled" status update for these orders?

TIA.


Linking a sub-user to a specific managed account

 

Let's say my account has two users. First one is the main user. And the second one is a sub-user, added under "Account settings" > "Users & Access Rights".
And I have two accounts, first one is the main trading account, and the second one is another account defined under "Account settings" > "Open an Additional Account".

Can I define the second sub-user to have access only to the second additional account? So he can't see any data or make any trades on the main account, only on the second account?
And on the second additional account, he will be able to view all data and make trades (by using the portal and by using TWS API)?


Re: How to “ Split the Spread to Capture Better Prices” ?

 

Here is the IB statement on a "split-spread" order: "Split spread orders include any order that is priced within the spread between the bid price and ask price. When they fill, these orders yield significant price improvement."
?
IB should provide a detailed study explaining this statement because my own statistical study on this shows otherwise.? Once again, I realize how counterintuitive that is.? Markets tend to be that way.

By the way, it's not a bad strategy.? My own data shows it hasn't been harmful.? But significant price improvement?? No way.



Re: How to “ Split the Spread to Capture Better Prices” ?

 

The short answer is that this does not work well.? I realize that is counterintuitive but I've captured data on thousands of trades using my own algorithm for getting in between the bid-ask.? Your first thought is something like this:? If I can sit at NBBO until getting filled then OF COURSE I'm coming out ahead on average.? But then you'd have to ask why market makers don't do this if it were such a good idea.? The vast majority of liquidity from market makers is further into the order book.? So I won't review all the statistical data and explanations here but I can tell you that there is a deep rabbit hole you'll go down.?

If anyone is willing to share their own experiences and data about this I'd love to get more into it more.


Re: How to “ Split the Spread to Capture Better Prices” ?

Gilbert
 

As an alternative to programming it yourself you can use IB’s Adaptive Algo market/limit orders which, in the case of a long, start at the bid and slowly raise the order’s price until you are filled/hit the limit price:

Using API:


Re: How to “ Split the Spread to Capture Better Prices” ?

 

On Fri, Dec 24, 2021 at 10:52 PM, Erez Kaplan wrote:
“Split the Spread to Capture Better Prices”
I didn't get the email (so to speak), but this page sounds like the same thing:?

What they're talking about is quickly changing your order price to buy slightly above the highest bid price or sell below the lowest ask. You can easily do that with the API, but you have to program it for yourself. My experience has been that it is hard to beat institutional traders at that game. If you want to have a long or short position, you also risk having the price move against you until the trade becomes unprofitable.
[rwk]


How to “ Split the Spread to Capture Better Prices” ?

Erez Kaplan
 

IBKR sent this attractive email to users “?Split the Spread to Capture Better Prices

The article explains usage via TWS only

how can this be achieved with API?
(sample code much appreciated)

cheers, Erez


Re: Install TWS or IB gateway on Ubuntu and ARM64 bit processor

 

Wow, 闯ü谤驳别苍 this is outstanding work. The internet is a beautiful place thank you so much for taking the time to reply and explain the steps you took.

I don't use 2fa or tws so your experience gives me motivation for the gateway. I had seen a similar suggestion on stack overflow regarding adding the openfx paths to the Java exec. I had some hunches where to trial and error in the shell script so your results are time-saving.

I also saw another suggestion to do something like a symbolic link between the default-jre (/usr/bin) Java and openjfk ( /lib something I forget).

Can't wait to get back to the office and try these ideas out. Cheers and happy holidays.


Re: Forced upgrade logout

 

Thank you for the insight. Best of luck to everyone.

Best wishes,


M

On Fri, 24 Dec 2021, 12:48 Richard L King, <rlking@...> wrote:

Actually that's been there since Gateway 975, so quite a long time now, and no, there's no way to switch it off.

?

However it also has the alternative Auto-relogin mechanism introduced in TWS 974, so if you're not using IBC, you can just use that mechanism. Then you only have to login once a week and it will automatically restart the Gateway and log you back in again every day at the time you specify.

?

If you ARE using IBC, you need to understand that IBC does not work with this auto-relogin (even though the setting for it is visible with the latest version of IBC). So you either have to just restart IBC every day, or stop using IBC and just use the Auto-relogin. Your choice will be influenced by how much you depend on IBC.

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of mark collins
Sent: 24 December 2021 11:25
To: [email protected]
Subject: [TWS API] Forced upgrade logout

?

Hi all,

?

Following the forced upgrade, I ended up with gateway 10.12.2d.

This brings with it the same time based logout behaviour that tws had. The point of using gateway is to avoid this kind of thing, so I'm guessing there's a setting somewhere to switch this off?

?

Anyone know where it can be disabled?

?

Best wishes (and merry Xmas)

?

?

M


Re: Install TWS or IB gateway on Ubuntu and ARM64 bit processor

 

My apologies for the confusion, Todd. As I said in my post, I only have an old 32bit Raspberry Pi 2 and was unable to make TWS/IBGW work on it. My next step would have been to grab a modern Pi 4, install a 64bit Debian distribution (instead of Raspbian) and try again with a 64bit JVM. It looked like 64bit ARM Java offerings were much more rich than 32bit ones. But you are correct, a 64bit JVM will not work on a 32bit OS.

Having said that, I went back to the drawing board and did some experiments on the Pi2 with 32bit OS and and 32bit JVMs. I installed the 32bit Linux versions of TWS and IBGW 981.3g and got pretty far, but not all the way. Here some thoughts that may help you:

  • IBKR installation packages contain a Java JVM 1.8.0_152 with embedded JavaFX libraries. So the IBKR code relies upon pre-Java 9 rules related to access between classes from different origins and jars.
  • Java 8 versions of JavaFX do exist for ARM 32bit, but they are missing some of the SWING related classes IBKR uses (such as JFXPanel).
  • After Java 8, JavaFX became a separate set of modules and more stringent module access rules apply
With that background I did these steps:
  • Download the stable Linux 32bit versions of IBGW and TWS. That is 981.3g right now
  • Install the IBKR package with an ARM 32bit Java8 JVM:
    • app_java_home="path-to-arm-java-jre" sh ibgateway-stable-standaline-linux-x86.sh
    • The installation uses your ARM JRE (instead of the packaged x86 JRE) and JavaFX is not required at this stage
  • Install a full featured JavaFX version that includes all SWING classes plus the corresponding JVM. After some experimenting I went with
    • openjfx-17.0.1_linux-arm32_bin-sdk.zip
    • OpenJDK17U-jdk_arm_linux_hotspot_17.0.1_12.tar.gz
  • Small modification to the ibgateway script (in my case located in ~/Jts/ibgateway/981)
    • At the bottom at the two exec java statements insert right after ...bin/java"
    • --module-path path-to-your-javafx-installation/lib --add-modules=ALL-MODULE-PATH
    • They have to be located at the front of the command line options and adding them to the vmoptions file will not work
  • Start IBGW with
    • app_java_home="path-to-your-java-JVM"? sh "~/Jts/ibgateway/981/ibgateway"
    • I had to do that as the root user since JavaFX tried to access all kinds of restricted devices related to mice, video, audio. But that could be an issue with my old Pi 2 and OS installation.
  • The login dialogue comes up but I cannot get past the 2FA challenge (long story, but the only account I can use for the test needs this). All input works fine but IBGW claims that I had entered an incorrect security code (which I did not)
  • launcher.log and the start script show a few exceptions related to module access restrictions to certain JavaFX classes. Most likely because of the more stringent module security enforced by the JVM. That can probably be worked around with proper module-info files, but will need some work and probably requires repackaging of IBKR JARs.
  • Starting TWS 981.3g works with the same recipe. Logging into a demo account eventually hangs in "Processing startup parameters ..."
Hope this helps,
闯ü谤驳别苍

PS. Contact me directly if you want to work on this some more, since this the nitty gritty is probably too far out of scope for the group.









Re: Forced upgrade logout

 

开云体育

Actually that's been there since Gateway 975, so quite a long time now, and no, there's no way to switch it off.

?

However it also has the alternative Auto-relogin mechanism introduced in TWS 974, so if you're not using IBC, you can just use that mechanism. Then you only have to login once a week and it will automatically restart the Gateway and log you back in again every day at the time you specify.

?

If you ARE using IBC, you need to understand that IBC does not work with this auto-relogin (even though the setting for it is visible with the latest version of IBC). So you either have to just restart IBC every day, or stop using IBC and just use the Auto-relogin. Your choice will be influenced by how much you depend on IBC.

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of mark collins
Sent: 24 December 2021 11:25
To: [email protected]
Subject: [TWS API] Forced upgrade logout

?

Hi all,

?

Following the forced upgrade, I ended up with gateway 10.12.2d.

This brings with it the same time based logout behaviour that tws had. The point of using gateway is to avoid this kind of thing, so I'm guessing there's a setting somewhere to switch this off?

?

Anyone know where it can be disabled?

?

Best wishes (and merry Xmas)

?

?

M


Forced upgrade logout

 

Hi all,

Following the forced upgrade, I ended up with gateway 10.12.2d.
This brings with it the same time based logout behaviour that tws had. The point of using gateway is to avoid this kind of thing, so I'm guessing there's a setting somewhere to switch this off?

Anyone know where it can be disabled?

Best wishes (and merry Xmas)


M


Re: Working with the TWS Socket port without using IBs classes

 

开云体育

Not sure what his problem is but I think you are doing an excellent job 闯ü谤驳别苍, thank you for taking up the reins on this on. We have all been handed a steaming pile of opportunity and the only way we get this sorted out is by shared experiences and POLITE discourse.

?That said I have some code I'd like the group to write, it's christmas and I feel like having a snooze. I'll send out the pseudocode later. Shall we say Dec 29th 2021 :-)

have an excellent christmas and a safe new year chaps.

Dent

On 12/24/21 4:16 AM, 闯ü谤驳别苍 Reinold via groups.io wrote:

We are absolutely here to help each other, and I think Nick did a great job giving you all the information, tools and hints you need to do what you have asked for. One of Nicks suggestions was

I think we all used IB's libraries as a reference. Pick whatever language you like best and look IB's code.

You probably want to use the newer "V100" protocol since it includes a length header for each message.

But apparently you did not do that.

We are not here to do the work for you and the 6,000 members in this group can expect that you read the documentation, make an attempt to understand the architecture, follow the advice you are given, and "use the IB code as a reference" before you ask more, frankly, trivial questions.

Let me know what you don't understand and I am happy to help you.

闯ü谤驳别苍


Re: Working with the TWS Socket port without using IBs classes

 
Edited

We are absolutely here to help each other, and I think Nick did a great job giving you all the information, tools and hints you need to do what you have asked for. One of Nicks suggestions was

I think we all used IB's libraries as a reference. Pick whatever language you like best and look IB's code.

You probably want to use the newer "V100" protocol since it includes a length header for each message.

But apparently you did not do that.

We are not here to do the work for you and the 6,000 members in this group can expect that you read the documentation, make an attempt to understand the architecture, follow the advice you are given, and "use the IB code as a reference" before you ask more, frankly, trivial questions.

Let me know what you don't understand and I am happy to help you.

闯ü谤驳别苍


On Fri, Dec 24, 2021 at 03:53 AM, YSS wrote:

Thanks for the help Jurgen, we can close this forum guys, Jurgen descided we can find everything in the code!!? No need to help each other!! Great spirit for the time of the year, keep it up mate! Thanks for your awesome contributions here. You're such a godsent!


?


Re: Working with the TWS Socket port without using IBs classes

YSS
 

Thanks for the help Jurgen, we can close this forum guys, Jurgen descided we can find everything in the code!!? No need to help each other!! Great spirit for the time of the year, keep it up mate! Thanks for your awesome contributions here. You're such a godsent!


Re: Forced upgrade before December 29

 

Likely depends on the API version, I've had issues like:

File "/usr/local/lib/python3.9/dist-packages/ibapi/decoder.py", line 1343, in interpret
???theBadMsg = ",".join(fields)
TypeError: sequence item 0: expected str instance, bytes found


Re: Forced upgrade before December 29

 

I've upgraded, haven't changed my api in several years and haven't noticed any problems.? There was no mention of this in the email I received.? What am I missing?


Re: Forced upgrade before December 29

 

For those who upgrade and have a issues on the API level, an upgrade of the API is also required. I had yet to see issues like this any time before today (I was using 10.05).