¿ªÔÆÌåÓý

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

check if running in Paper or Live trading mode programatically


 

Hi Is there any way to determine via IBKR APIs - whether the program is running in Paper Trading more or Live Trading Mode.? ?


 

Check the connecting port number


 

When your client connects to TWS/IBGW it receives callback with a list of the accounts the client application can trade through that connection. That list, obviously, depends on the active login TWS/IBGW has with IBKR at the time of client connection. So you can tell your client application which accounts are paper accounts and which ones are live accounts.

I could swear I have seen an IBKR Knowledge Base article in the past where they described how account numbers for various account types are structured but could not find it right now (maybe someone has a link handy?) If I remember correctly, paper accounts can be identified by their account number as well.

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


 

That's very simple.?? Papertrading-Accounts start with a "D" , DFxxx are advisor accounts, DUxxx user accounts

(in Ruby):?

?? ?def test_environment?
?? ???? ??? !!(account =~ /^[D]{1}/)
?? ???? end

Accounts are available through ReqManagedAccounts, which returns a comma separated string of connected accounts.

Don't rely on the port. this can be set by the user.


 

thanks alot . worked :)?


 

...or in python:

def is_demo(account_number: str) -> bool:
? ? return account_number.startswith('D')