6. Batch Processing

clib includes a number of features that make it ideal for batch processing, including:

  • Default CSV file output format
  • Setting the exit code based on the results of the run
  • Default and command-specific timeouts

Each of these features will be discussed in the examples below.

6.1. Example 1 - Nightly log of Trades and Commissions

It is often helpful to have a log of trade executions and commissions. However, because clib does not always see orders being executed (as in the case of a limit or extended hours order), it’s a good idea to run a log of trade executions and commissions each night.

Under Linux, this might look like a crontab with the following entries 55 23 * * 1-5 root /usr/local/bin/clib e > /var/clib/executions.log 56 23 * * 1-5 root /usr/local/bin/clib c > /var/clib/commissions.log

6.2. Example 2 - Simple Strategies

clib can be used to execute simple strategies.

Let’s consider a strategy designed to capitalize on the fact that markets rise most at night. We’ll buy 1 S&P mini future at 4:00 pm local time and sell it again at market open the next day.

Buyint and selling is as simple as executing this command in the morning: :: $ clib buy 1 es-fut-globex-20190315

And this command the next morning: :: $ clib sell 1 es-fut-globex-20181221

We can ensure that the trade executed properly in several ways:

# By checking the exit code # By parsing the CSV output

6.2.1. Checking the Exit Code

First, we can check the exit code of clib using our shell

echo $?

Or on Windows

echo %errorlevel%

For example, one simple strategy is to buy 1 S&P mini future at close and sell again the next morning at market open.

One might accomplish this in Linux with the following crontab entry: 01 16 * * 1-5 root clib buy 1 es-fut-nymex-20181221