IB API Connection Help

Discussion in 'Automated Trading' started by robl, Oct 21, 2021.

  1. robl

    robl

    Looking to build a system that can trade signals across multiple IB accounts. I have used the TWS Gateway before but thought that perhaps there was a different way to connect to the API without the gateway. Is that true?

    What is the best approach to trading in multiple accounts? Do I need to have them link to my IB account login for access or can they provide credentials for me to use? I saw the SSO APi section for the client API but the docs are a bit confusing. A

    Any directional help is appreciated.
     
  2. xandman

    xandman

    I went thru TWS API v9.72+: Using Third Party API Platforms (interactivebrokers.github.io) .
    It doesn't look promising. Per IBKR, The gateway will always require the manual entry of your credentials. There is no headless version.

    Hard to believe because I thought I read schemes on ET to auto-restart systems running on a VPS. My memory fails me.

    You will probably have to link accounts. That is easy, but I wonder how it supports automatic allocations. A Friends and Family account might be necessary.
     
  3. d08

    d08

    You can have an account (without banking for obvious reasons) that only requires username and password, can use IBCAlpha to manage the login credentials. It's a headless solution that works. I still force quit/restart once a day to clear any unforeseen Gateway problems but that's also automated.
     
    xandman likes this.
  4. I trade 2 accounts with IB at the same time. Both individual accounts on my name. I tried two methods:

    - One, using the rest API with different browser sessions. The rest API needs authentication through a browser, so I needed to provide different users. There are add-ons on the Google Chrome store that can enable independent sessions, so you don't need to deal with incognito sessions. They essentially create independent folders on your drive and act like two users where logged in. Web developers and testers use this trick often to simulate account privileges.

    - Another method was to run multiple user accounts on Linux, I guess you can do the same with Windows. Just login into multiple user desktops and run the gateway on each account. They will be independent.

    I stick with the second option, just because the IB Gateway API is more reliable than the Rest API for me.

    Essentially as soon as you can provide a way to handle multiple sessions, either web or OS sessions, you will be fine.
     
  5. KevinBB

    KevinBB

    @robl Are these multiple accounts in your name, or someone else? I think IB would have a hissy fit if they knew someone had given you their details to trade for them.

    If the accounts are yours, or connected to your account, then you can log in to a single session of Gateway API (or TWS API if you prefer) multiple times and with multiple accounts. This is one method of logging in using insync library. The Client Id is a unique number that you assign for that particular login.
    ib.connect('127.0.0.1', 7496, clientId=2, account='U4xxxxxx')

    Check with IB and discuss your situation with them. As @xandman said, a F & F account might be one option, depending on the exact situation.
    KH
     
    guest_trader_1 likes this.
  6. For each IB account, set a different port number. Then run your api application for each account on its own port number. IB connection is based on the port number. I manage multiple accounts simultaneously from my desktop pc.
     
    rb7 likes this.
  7. robl

    robl

    I want to replicate https://www.global-autotrading.com/autotrading-service/brokers-in-use.html

    I use them today and they trade in my IB account for multiple newsletter where I subscribe. I followed this process a few years ago but am unclear how this relates to the API usage. I think I created a linked account. When I login I see my old account and the new account dedicated to Global under one login. I am trying to replicate their capabilities for myself and a few friends who use them.



    You have indicated that you would like Global AutoTrading to autotrade in your existing Interactive Brokers account. To do so, please link your account to Global AutoTrading’s account, by first logging in to IB's Client Portal, and then by following IB's instructions to move your entire account, create a linked account, or partition your account (or these instructions if you are still using IB's 'classic' account management site). Please copy and paste the following information to fill out the form, as everything must match exactly (including capitalization, spacing, and the period after 'Inc'):

    Advisor/Broker-managed Account ID: xxxxxxx

    Advisor/Broker-managed Account Title: Global AutoTrading Inc.

    Please keep in mind that if you chose 'Move my entire account to an account managed by the Advisor / Broker identified below', you will not have trading access to this account after it is linked (you should still have access until the market close on Friday -- just do not logout of TWS/WebTrader after 12pm).

    If you would prefer to continue trading on your own as well as benefit from autotrading, please choose one of the other two options 'Create a new linked account' or 'Divide my account into two partitions'. IB said that the partitioning of an account in two will eventually allow for cross-margining (but that is not yet available). Until cross-margining becomes available, when choosing between a partition and a new account, we recommend choosing 'Create a new linked account', as it allows multiple accounts to be created (there can only be one partition per account per advisor). However, please note that if you choose to create a partition or account (as opposed to link your entire account), we will not be able to grant you read-only access to the trading account. Once your existing account is partitioned or the new account is opened you can transfer funds instantaneously and for free between your existing account and this new account, thus it’s a good way to segregate your self-directed trades from Global AutoTrading’s trades.


    Rob
     
  8. The confusing part about IB's nomenclature is the double usage of the word "account". On the one hand they use it to identify your username and password. On the other hand they use it to identify the account number (e.g. Uxxxx, DExxxx) of your portfolio.
    From the opening post of this thread I get the impression that in this case we are talking about multiple username/password accounts. In that case does your suggestion not work, because you have to provide username/password when starting TWS or Gateway.
    If you have one username/password, followed by multiple Uxxx account numbers, then your suggestion works indeed fine. I am using this on a daily basis.
     
    d08 likes this.
  9. robl

    robl

    Sorry I was banned for a few days as they said my post was SPAM. People in charge fixed it.

    Perhaps I am being confusing. I need to trade multiple accounts. I cannot run a gateway where they all have to be logged in. That would require multiple computers unless there is something I don't understand. The email I posted explains the setup but it is unclear to me how to do this on the code side.
     
  10. d08

    d08

    Why can't you run multiple gateway instances, use a different port for each gateway. Then run multiple instances of your API connection for each gateway. You must run them on different ports however, that's critical.
     
    #10     Oct 25, 2021
    trend2009 likes this.