Auto-trade multiple Interactive Brokers (IB) accounts - which account type?

I'd like to have the option, while auto trading, to hold both long and short positions in the same stock. Thus, auto-trading with my 'individual' IB account alone is not an option.

After speaking with Interactive Brokers compliance and API folks, they suggested two options:

  1. Create a second 'individual' account and 'link' it to my current account.

  2. Create a Family & Friends Advisory account and configure my current account as a second account within the Family & Friend Advisory plan.

The IB folks indicated that option #1 above would be the easiest path (open a 2nd 'individual' account and link it to my current 'individual' account). They also mentioned a few benefits of this approach:

a. Multiple computers or virtual machines are not necessary. Can log into one account, on one computer and have API access to both linked accounts.

b. Only one instance of IBController is needed and it can send trade commands to both accounts.

I haven't spent much time with IBController yet, and via my searches I have only found references to folks using IB Advisory accounts for multi-account auto-trading. I'd appreciate comments from folks on this forum regarding the use of 2 linked 'individual' accounts for auto-trading. Sound reasonable?

Thanks in advance.

Mike

1 Like

i worked with F&F accounts years ago. So am not doing this actively right now but you just use the functions setaccount and setaccountinfo, see http://www.amibroker.com/at/

just use your paper trading account to make the code, something like (see example below). It is all pretty straightforward

// list of accounts
StaticVarSetText( "AccountList_0", "U735058" );
StaticVarSetText( "AccountList_1", "U176532" );

ibc = GetTradingInterface( "IB" );

// loop through the accounts
for( i = 0; ( accountNumber = StaticVarGetText( "AccountList_" + i ) ) != ""; i++ )
{
    if( ibc.IsConnected() )
    {
        ibc.SetAccount( accountNumber );
        
        // etc etc

Hi Mike,

I'm going to run into this problem shortly and have been thinking about it. I have a F&F structure, and it looks like Linking works effectively the same way. I use custom software for placing orders (I don't use AB).

Regarding a). That would seem to be the same for both options. Did they indicate the F&F would not allow API access to both accounts??

Regarding b). I'd also have thought this would function just as well for both?

In this case, I'd go with F&F and have the option of linking any number of sub accounts (whether in exactly the same name or not) as opposed to linking (where name / tax ID etc all has to be exactly the same)?

I'm curious to know what you find out. It's a real shame IB don't allow a way to do this in a single account.

From what I gathered from the IB folks, items a and b are true for the F&F accounts and for a scenario with 2 linked 'individual' accounts. So it seems that either option will work for me. If somebody wants to trade 3 or more accounts, then the F&F plan would be the way to go. Also, in both cases, it seems that I'll only need to pay for market data for one account. Market data from account IB X flows to Amibroker, trade commands go from Amibroker to IB accounts X and Y. It appears that this would be the case for F&F accounts and also for two linked individual accounts as long as the accounts are accessed by one person / one login.

@mcescher When auto-trading the F&F master account, should the client accounts be setup as IBKR Pro or IBKR Lite?

Lite doesn’t offer API access don’t believe.

@Metamega You're right, IBKR Lite does not offer API access, but I was wondering if having a Lite client account under the umbrella of a Pro master account would somehow enable the API. There are other differences: tiered commissions, smart routing, margin rates, etc.

You can only have one controller running per Windows account, so you would need your real account on another machine or in another account.

You also would need separate data feeds.

The code that you quoted was for looping through multiple accounts in one formula, which is why StaticVarSetText() was used. VarSet() would have worked also. But if you have separate formulas for each account, you can just hard code the account number.

Also, make sure you read the autotrading posts from the old KB.
http://www.amibroker.org/userkb/

That looks good to me. It's for using the "other" IBController managed by Richard King, which is unrelated to ibc 1.3.8 that comes with Amibroker. You still would have to test this with Amibroker's ibc (because you would be using both IBController and ibc). Sadly these two programs have the same name and are easily confused.

The software you refer to is not the IBController program written by Tomasz and has been renamed IBC (GitHub - IbcAlpha/IBC: Automation of Interactive Brokers TWS. You can download the latest release here: https://github.com/ibcalpha/ibc/releases/latest) years ago. It can be used to automate TWS (start, connect, close, run forever...) but is not related to Amibroker nor its trading interface IBController. There's no need for IBC to run two TWS instances, btw.

PeterD has answered your previous question last week. Simply test your system on your paper account, then if satisfied, run it later on your real trading account. You only need a single formula with a parameter for your account.

More precisely:

  1. It's not possible to connect to the same IB account from 2 simultaneous TWS instances, but it's possible to connect simultaneously to your paper account using one instance and to your regular trading account using the second TWS instance. In that case, you must use one port for each session, and you can keep the default ports 7496 and 7497 (different ports) as one is for paper account and the other for your real trading account. It's best to use different directories so you won't be confused in diagnostics.

  2. Although you can use two IBKR accounts, you cannot access to both of them simultaneously using a single instance of IBController as you can only run a single instance of IBController at the same time. There are two options. First, if you have another trading interface you can use from Amibroker (a 2nd one different from IBController), then you could access both accounts and trade them simultaneously. Second, you could use 2 different Windows accounts, each one running its own Amibroker+IBController+TWS instances.

PS: I started to write my reply before @PeterD answered just above. My comment: IBC doesn't solve the access problem to trade from Amibroker...

@alligator, great insights.

You could use ib_insync as a second interface in parallel with IBController, assuming you know Python and want to the development work.

1 Like

If you don’t already, I thoroughly recommend spending a little bit of time learning some basic Python. The ‘coding with mosh’ tutorials on YouTube are good, and once you have done those, learning how to use the pandas library will be pretty much all you need to trade any broker.

Amibroker is excellent with identifying trade signals, charting etc and Python is fairly universal so you’ll be able to find a library on GitHub for vast majority of brokers.

If you’re willing to put in the time to learn how to use it, you could use the Client Portal API https://www.interactivebrokers.com.au/en/trading/ib-api.php

Work through the tutorials at What is IBKR’s Client Portal API? | Trading Lesson | Traders' Academy | IBKR Campus
You can run a separate instance of the gateway on different ports, so the default in the tutorial is :5000, but you can run other instances on 5001,5002 etc. You just copy the beta.gw folder (I can’t remember the exact folder off hand) and change the port in one of the configuration files (again, I can’t remember off the top
Then in AmiBroker you can run explorations, export CSVs files using batch, and then read those parameters from the CSVs using the Python pandas library, and trigger your orders via ‘shellexecute’ (again, as a step in batch). Or you can use fopen(), fputs(), fgets() in AmiBroker for parsing of your signals back and forth between AmiBroker and Python. Eg you might use fgets() a read value of your equity from a file, or entry price, which was written to by a Python script, or you might use fputs() to write the parameters to a file to be picked up by a Python function which you later trigger using the batch editor, or shellexecute.