5. Configuration and Customization

5.1. Configuration File

clib relies heavily on a configuration file to tell it how to behave. The configuration file contains many defaults and other options. For example, the default_security_type is set to stk so you won’t have to type it every time.

5.2. Where is the configuration file located

Normally, clib will look to find its initialization file clib.ini in the same directory where it is executing. So, if you put clib.exe in your path c:/bin, then clib will expect to find it’s configuration file as c:/bin/clib.ini If you’d like to store your configuration file elsewhere, you can specify the –config option.

5.3. Creating the Configuration File

Run clib with the config command to create a default configuration file in the current directory.

5.4. Global Options

The [Global[ section is the first section of the configuration file. Here you can set options like default-security-type and host which will affect all clib commands.

5.4.1. host

The machine on which you are running TWS or IB Gateway, such as for your local machine. port 7496 for TWS or 4001 for IB Gateway

5.4.2. default_security_type

Set to stk, opt, fut, or your preferred security type. This eliminates having to type it as part of the symbol every time.

5.4.3. default_exchange

Generally set to smart so that you will not need to specify it as part of symbols.

5.5. Defining Aliases

Aliases provide a shorthand way of referring to a full symbol. For example, we might define an alias like this:


Aliases can also be defined for values which change at runtime. These are called runtime aliases and include a python expression inside tick marks.

For example, we define an alias @today like this:


Then, we can run a command using the alias @today like this:

$ clib history nflx trades @today 1d 1d

Currently, runtime aliases are only supported in the date-end of the history command.

See the default configuration file for numerous alias examples.

5.6. Command Specific Settings

Following the Global options in the configuration file is a section for each clib command. So for example, we’ll have sections for:

  • [account]
  • [bulletins]
  • [buy]
  • And all the other commands

The following options are available for each command:

  • headers
  • timeout

Future: describe each option

5.7. Message Specific Settings

Since each command can respond to several different Interactive Brokers message types, we can further customize each message type.

So for example, under [account], we see these message types:

  • [[accountDownloadEnd]]
  • [[updateAccountValue]]
  • [[error]]

Each message type can be further customized with these options:

  • columns
  • filter
  • format
  • terminate

Future: describe each option

5.8. Customizing Output Formatting

The default output of clib is comma separated value (CSV). But we can change what is displayed for each command by opening the clib.ini file in a text editor.

So for example, if we wanted to switch from CSV to tab delimited, we might change clib.ini to include this definition:

headers=Tick Type,Price,Size
format="%s \t%.2f"