1. Introduction

1.1. What is clib

clib is a command-line program that you can use with Interactive Brokers. With it, you can get account and position information, buy and sell securities, retrieve current market data and historical data, and much more.

Because clib is a command-line program, it can be used:

  • For fast and efficient access to your broker’s features from a text console
  • For automating simple strategies
  • For automating retrieval of large amounts of data
  • For automating nightly reports related to one or many Interactive Brokers accounts

clib’s default output format is text/CSV, so results can be easily loaded into a spreadsheet or evaluated using other command line tools.

1.2. Quick Start

clib is available as a stand-alone binary for Windows and Linux. You can download the latest version from the Downloads page.

  1. Download the binary file for your platform (see above)

  2. Move the file somewhere in your search path, such as /usr/local/bin and change to this directory

  3. Execute “clib config” to create a clib.ini file

  4. Edit clib.ini, specifically setting the host and port values for your TWS or IB Gateway instance

  5. Run “clib status”; you should see output like this:
    $ clib status
    Host = 192.168.0.103
    Port = 4001
    Client = 272
    Next ID = 1
    
  6. Try out a command, such as:
    $ clib quote spy
    Last Price
    240.36
    

1.3. A Quick Note on Symbology

Throughout this guide, we’ll refer to symbols when describing specific securities. A symbol will always include a ticker but may be supplamented by a security type (like fut for futures or opt for options), an exchange, and other identifying information.

By default clib will always assume a security type of stk and an exchange of smart. Thus, we can shorten spy-stk-smart to just spy.

See Symbology for more information and examples.