API Reference

Tip: get help directly from the CLI/Python client

The API documentation shown below for the command line interface (CLI) and Python client is auto-generated and can be referenced at any time from the clients themselves. To view the API documentation for the CLI, use the -h/--help option with any command or subcommand:

$ quantrocket history create-db -h

To view Python documentation in an iPython shell, use the question mark syntax:

In [1]: from quantrocket.history import create_db
In [2]: create_db?

account

account and portfolio service

QuantRocket account CLI

usage: quantrocket account [-h]
                           {balance,history,portfolio,default,fx,fxhistory}
                           ...
Sub-commands:
balance

get a snapshot of current account balance info

usage: quantrocket account balance [-h] [-n | -c | -f [FIELD [FIELD ...]]]
                                   [-a [ACCOUNT [ACCOUNT ...]]]
                                   [-b CUSHION | -s]
Options:
-n=False, --nlv=False
 only show NLV
-c=False, --cushion=False
 only show margin cushion
-f, --fields

only display these fields

Possible choices: AccountType, NetLiquidation, TotalCashValue, SettledCash, AccruedCash, BuyingPower, EquityWithLoanValue, PreviousEquityWithLoanValue, GrossPositionValue, RegTEquity, RegTMargin, SMA, InitMarginReq, MaintMarginReq, AvailableFunds, ExcessLiquidity, Cushion, FullInitMarginReq, FullMaintMarginReq, FullAvailableFunds, FullExcessLiquidity, LookAheadNextChange, LookAheadInitMarginReq, LookAheadMaintMarginReq, LookAheadAvailableFunds, LookAheadExcessLiquidity, HighestSeverity, DayTradesRemaining, Leverage

-a, --accountsonly show these accounts
-b, --below-cushion
 only show accounts where the cushion is below this level (e.g. 0.05)
-s=False, --save=False
 save a snapshot of account balance info to the account database
history

get historical account balance snapshots from the account database

usage: quantrocket account history [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                   [-n | -f [FIELD [FIELD ...]]]
                                   [-a [ACCOUNT [ACCOUNT ...]]] [-l]
Options:
-s, --start-date
 limit to history on or after this date
-e, --end-datelimit to history on or before this date
-n=False, --nlv=False
 only show NLV
-f, --fields

only display these fields

Possible choices: AccountType, NetLiquidation, TotalCashValue, SettledCash, AccruedCash, BuyingPower, EquityWithLoanValue, PreviousEquityWithLoanValue, GrossPositionValue, RegTEquity, RegTMargin, SMA, InitMarginReq, MaintMarginReq, AvailableFunds, ExcessLiquidity, Cushion, FullInitMarginReq, FullMaintMarginReq, FullAvailableFunds, FullExcessLiquidity, LookAheadNextChange, LookAheadInitMarginReq, LookAheadMaintMarginReq, LookAheadAvailableFunds, LookAheadExcessLiquidity, HighestSeverity, DayTradesRemaining, Leverage

-a, --accountsonly show these accounts
-l=False, --latest=False
 only show the latest historical snapshot in the date range
portfolio

get current account portfolio

usage: quantrocket account portfolio [-h] [-a [ACCOUNT [ACCOUNT ...]]]
Options:
-a, --accountslimit to these accounts
default

view or set the default account

usage: quantrocket account default [-h] [ACCOUNT]
Positional arguments:
accountset this account as the default (omit to view current default account)
fx

fetch base currency exchange rates from Google and optionally save to account database

usage: quantrocket account fx [-h] [-c [CURRENCY [CURRENCY ...]]] [-s]
Options:
-c, --currencies
 limit to these currencies (default all IB-tradeable currencies)
-s=False, --save=False
 save exhange rates to the account database
fxhistory

return historical exchange rates from the account database

usage: quantrocket account fxhistory [-h] [-c [CURRENCY [CURRENCY ...]]]
                                     [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-l]
Options:
-c, --currencies
 limit to these currencies (default all IB-tradeable currencies)
-s, --start-date
 limit to history on or after this date
-e, --end-datelimit to history on or before this date
-l=False, --latest=False
 only show the latest exchange rate in the date range
quantrocket.account.get_balance(nlv=None, cushion=None, fields=None, accounts=None, below_cushion=None, save=False)

Returns a snapshot of current account balance info.

Parameters:

nlv : bool

only return NLV (equivalent to fields=[‘NetLiquidation’])

cushion : bool

only return margin cushion (equivalent to fields=[‘Cushion’])

fields : list, optional

only return the specified fields (default all fields). Possible choices: AccountType, NetLiquidation, TotalCashValue, SettledCash, AccruedCash, BuyingPower, EquityWithLoanValue, PreviousEquityWithLoanValue, GrossPositionValue, RegTEquity, RegTMargin, SMA, InitMarginReq, MaintMarginReq, AvailableFunds, ExcessLiquidity, Cushion, FullInitMarginReq, FullMaintMarginReq, FullAvailableFunds, FullExcessLiquidity, LookAheadNextChange, LookAheadInitMarginReq, LookAheadMaintMarginReq, LookAheadAvailableFunds, LookAheadExcessLiquidity, HighestSeverity, DayTradesRemaining, Leverage

accounts : list, optional

only return info for the specified accounts (default all connected accounts); account IDs or nicknames can be provided

below_cushion : float, optional

only return accounts where the cushion is below this level (e.g. 0.05)

save : bool

save a snapshot of account balance info to the account database

Returns:

DataFrame

quantrocket.account.get_balance_history(start_date=None, end_date=None, nlv=None, fields=None, accounts=None, latest=False)

Returns historical account balance snapshots from the account database.

Parameters:

start_date : date or str

limit to history on or after this date

end_date : date or str

limit to history on or before this date

nlv : bool

only return NLV (equivalent to fields=[‘NetLiquidation’])

fields : list, optional

only return the specified fields (default all fields). Possible choices: AccountType, NetLiquidation, TotalCashValue, SettledCash, AccruedCash, BuyingPower, EquityWithLoanValue, PreviousEquityWithLoanValue, GrossPositionValue, RegTEquity, RegTMargin, SMA, InitMarginReq, MaintMarginReq, AvailableFunds, ExcessLiquidity, Cushion, FullInitMarginReq, FullMaintMarginReq, FullAvailableFunds, FullExcessLiquidity, LookAheadNextChange, LookAheadInitMarginReq, LookAheadMaintMarginReq, LookAheadAvailableFunds, LookAheadExcessLiquidity, HighestSeverity, DayTradesRemaining, Leverage

accounts : list, optional

only return info for the specified accounts (default all accounts); account IDs or nicknames can be provided

latest : bool

only return the latest historical snapshot in the date range

Returns:

DataFrame

quantrocket.account.get_portfolio(accounts=None)

Returns current portfolio.

Parameters:

accounts : list, optional

limit to these accounts (default all connected accounts); account IDs or nicknames can be provided

Returns:

DataFrame

 

Account API

Account

Account Balance

Get Account Balance
GET/account/balance{?fields,accounts,below_cushion}

Return a snapshot of current account balance info for all connected accounts.

Example URI

GET http://houston:1969/account/balance?fields=NetLiquidation&accounts=U123456&below_cushion=0.05
URI Parameters
fields
str (optional) Example: NetLiquidation

only return these fields (pass multiple times for multiple fields)

accounts
str (optional) Example: U123456

only return these accounts (pass multiple times for multiple accounts)

below_cushion
float (optional) Example: 0.05

only return accounts where the cushion is below this level

Response  200

The JSON response contains a top-level key for each connected account.

Headers
Content-Type: application/json
Body
{
  "DU123456": {
    "Currency": "USD",
    "AccountType": "INDIVIDUAL",
    "Cushion": 1,
    "DayTradesRemaining": -1,
    "LookAheadNextChange": 0,
    "AccruedCash": 64.36,
    "AvailableFunds": 1000133.12,
    "BuyingPower": 4000532.48,
    "EquityWithLoanValue": 1000133.12,
    "ExcessLiquidity": 1000133.12,
    "FullAvailableFunds": 1000133.12,
    "FullExcessLiquidity": 1000133.12,
    "FullInitMarginReq": 0,
    "FullMaintMarginReq": 0,
    "GrossPositionValue": 0,
    "InitMarginReq": 0,
    "LookAheadAvailableFunds": 1000133.12,
    "LookAheadExcessLiquidity": 1000133.12,
    "LookAheadInitMarginReq": 0,
    "LookAheadMaintMarginReq": 0,
    "MaintMarginReq": 0,
    "NetLiquidation": 1000133.12,
    "RegTEquity": 1000133.12,
    "RegTMargin": 0,
    "SMA": 1000133.12
  }
}

Save Account Balance
POST/account/balance

Saves a snapshot of account balance info to the account database. Also returns the account balance info that was saved.

Example URI

POST http://houston:1969/account/balance
Response  200

The JSON response contains a top-level key for each connected account.

Headers
Content-Type: application/json
Body
{
  "DU123456": {
    "Currency": "USD",
    "AccountType": "INDIVIDUAL",
    "Cushion": 1,
    "DayTradesRemaining": -1,
    "LookAheadNextChange": 0,
    "AccruedCash": 64.36,
    "AvailableFunds": 1000133.12,
    "BuyingPower": 4000532.48,
    "EquityWithLoanValue": 1000133.12,
    "ExcessLiquidity": 1000133.12,
    "FullAvailableFunds": 1000133.12,
    "FullExcessLiquidity": 1000133.12,
    "FullInitMarginReq": 0,
    "FullMaintMarginReq": 0,
    "GrossPositionValue": 0,
    "InitMarginReq": 0,
    "LookAheadAvailableFunds": 1000133.12,
    "LookAheadExcessLiquidity": 1000133.12,
    "LookAheadInitMarginReq": 0,
    "LookAheadMaintMarginReq": 0,
    "MaintMarginReq": 0,
    "NetLiquidation": 1000133.12,
    "RegTEquity": 1000133.12,
    "RegTMargin": 0,
    "SMA": 1000133.12
  }
}

Account balance history

Get Account Balance History
GET/account/balance/history{?start_date,end_date,fields,accounts,latest}

Return historical account balance snapshots from the account database.

Example URI

GET http://houston:1969/account/balance/history?start_date=2017-04-01&end_date=2017-06-30&fields=NetLiquidation&accounts=U123456&latest=false
URI Parameters
start_date
date (optional) Example: 2017-04-01

limit to history on or after this date

end_date
date (optional) Example: 2017-06-30

limit to history on or before this date

fields
str (optional) Example: NetLiquidation

only return these fields (pass multiple times for multiple fields)

accounts
str (optional) Example: U123456

only return these accounts (pass multiple times for multiple accounts)

latest
bool (optional) Example: false

only return the latest historical snapshot in the date range

Response  200
Headers
Content-Type: application/json
Body
[
  {
    "Account": "DU123456",
    "AsOfDatetime": "2017-03-01 15:02:24 UTC",
    "NetLiquidation": 1000133.12
  },
  {
    "Account": "DU123456",
    "AsOfDatetime": "2017-03-01 17:06:19 UTC",
    "NetLiquidation": 1000256.98
  }
]

Account Portfolio

Get Account Portfolio
GET/account/portfolio{?accounts}

Return current portfolio.

Example URI

GET http://houston:1969/account/portfolio?accounts=U123456
URI Parameters
accounts
str (optional) Example: U123456

only return these accounts (pass multiple times for multiple accounts)

Response  200

The JSON response contains a top-level key for each connected account.

Headers
Content-Type: application/json
Body
{
  "DU123456": {
    "AAPL": 400
  }
}

blotter

order management and trade ledger service

QuantRocket blotter CLI

usage: quantrocket blotter [-h]
                           {order,ordermany,cancel,status,active,monitor,unmonitor,download,match,positions,rollover,close,pnl}
                           ...
Sub-commands:
order

place an order and return an order ID

usage: quantrocket blotter order [-h] CONID FIELD:VALUE [FIELD:VALUE ...]
Positional arguments:
conidthe contract ID
orderorder details as JSON or as multiple key-value pairs (e.g. orderType:MKT tif:DAY)
ordermany

place a batch of orders from file or stdin

usage: quantrocket blotter ordermany [-h] [-c TIMEDELTA]
                                     [--completed-statuses [STATUS [STATUS ...]]]
                                     FILE
Positional arguments:
filenameCSV file of orders (can also be passed on stdin)
Options:
-c, --hold-child-orders-for
 hold child orders for up to this long (use Pandas timedelta string, e.g. 30m) and submit them as parent orders are filled (default is to submit parent and child orders together and let IB handle it)
--completed-statuses
 

override which order statuses to treat as completed statuses. Possible choices: %(choices)s

Possible choices: PendingCancel, Cancelled, Filled

cancel

cancel an order by order ID, conid, or strategy

usage: quantrocket blotter cancel [-h] [-o ORDERID] [-s [CODE [CODE ...]]]
                                  [-c [CONID [CONID ...]]]
Options:
-o, --order-idcancel this order ID
-s, --strategies
 limit to these strategies
-c, --conidslimit to these conids
status

check an order status

usage: quantrocket blotter status [-h] ORDER_ID
Positional arguments:
order_idthe order ID
active

list active orders

usage: quantrocket blotter active [-h] [-s [CODE [CODE ...]]]
                                  [-a [ACCOUNT [ACCOUNT ...]]]
                                  [--diff-positions]
Options:
-s, --strategies
 limit to these strategies (= order refs)
-a, --accountslimit to these accounts
--diff-positions=False
 only show orders which don’t match up to an existing position
monitor

start monitoring order statuses and executions in real time

usage: quantrocket blotter monitor [-h]
unmonitor

stop monitoring order statuses and executions

usage: quantrocket blotter unmonitor [-h]
download

download execution details for the current day

usage: quantrocket blotter download [-h]
match

generate round-trip trades by matching executions

usage: quantrocket blotter match [-h]
positions

get current positions from the blotter database

usage: quantrocket blotter positions [-h] [-s [CODE [CODE ...]]]
                                     [-a [ACCOUNT [ACCOUNT ...]]]
                                     [--diff-orders]
Options:
-s, --strategies
 limit to these strategies
-a, --accountslimit to these accounts
--diff-orders=False
 only show positions which don’t match up to one or more existing orders
rollover

generate orders to rollover futures contracts based on rollover rules

usage: quantrocket blotter rollover [-h] [-s [CODE [CODE ...]]]
                                    [-a [ACCOUNT [ACCOUNT ...]]]
                                    [-r [KEY:VALUE [KEY:VALUE ...]]]
Options:
-s, --strategies
 limit to these strategies
-a, --accountslimit to these accounts
-r, --rulesrollover rules as multiple key-value pairs in relativedelta format (e.g. days=-8) (omit to use rollover rules defined in master service)
close

generate orders to close positions

usage: quantrocket blotter close [-h] [-s [CODE [CODE ...]]]
                                 [-c [CONID [CONID ...]]]
                                 [-a [ACCOUNT [ACCOUNT ...]]]
                                 [-o FIELD:VALUE [FIELD:VALUE ...]]
                                 [--oca SUFFIX]
Options:
-s, --strategies
 limit to these strategies
-c, --conidslimit to these conids
-a, --accountslimit to these accounts
-o, --orderorder details as JSON or as multiple key-value pairs (e.g. orderType:MKT tif:DAY)
--ocacreate OCA group containing client ID, order ID, and this suffix (run this command multiple times with this option to create OCA orders)
pnl

query live trading results from the blotter database

usage: quantrocket blotter pnl [-h] [-s CODE [CODE ...]] [-a ACCOUNT] [-w]
                               YYYY-MM-DD [YYYY-MM-DD]
Positional arguments:
start_datestart date
end_dateend date (optional)
Options:
-s, --strategies
 one or more strategies to show performance for
-a, --accountthe account to show performance for (if not provided, the default account registered with the account service will be used)
-w=False, --raw=False
 return raw performance data instead of a performance tearsheet
 

Blotter API

Blotter

Order

Save Order
POST/blotter/orders/{account}/{client_id}/{order_num}

Saves an order to the blotter database. The account, client ID, and order num are required, as these uniquely identify the order. The request should contain a contract key with conId to identify the security. Providing an orderRef to identify the trading strategy is highly recommended, as it allows tracking performance by strategy.

Example URI

POST http://houston:1969/blotter/orders/U123456/5/28400
URI Parameters
account
str (required) Example: U123456

the account associated with this order

client_id
int (required) Example: 5

the IB Gateway client ID associated with this order

order_num
int (required) Example: 28400

the order num

Request
Headers
Content-Type: application/json
Body
{
  "contract": {
    "conId": 1111134
  },
  "order": {
    "action": "BUY",
    "lmtPrice": 51.1,
    "orderType": "LMT",
    "totalQuantity": 500,
    "tif": "DAY",
    "orderRef": "secretstrategy"
  }
}
Response  200

Executions

Save Executions
POST/blotter/executions

Downloads executions from IB and saves them to the blotter database.

Response 200

Example URI

POST http://houston:1969/blotter/executions

Get Historical Executions
GET/blotter/executions{?accounts,strategies,start_date,end_date,convert_currency,use_exchange_tz,include_unfilled}

Returns orders and executions from the blotter database.

Example URI

GET http://houston:1969/blotter/executions?accounts=U123456&strategies=secretstrategy&start_date=2017-04-01&end_date=2017-06-30&convert_currency=false&use_exchange_tz=false&include_unfilled=true
URI Parameters
accounts
str (optional) Example: U123456

limit to these accounts (pass multiple times for multiple accounts)

strategies
str (optional) Example: secretstrategy

limit to these strategies/order refs (pass multiple times for multiple strategies)

start_date
date (optional) Example: 2017-04-01

limit to executions on or after this date

end_date
date (optional) Example: 2017-06-30

limit to executions on or before this date

convert_currency
bool (optional) Default: false Example: false

convert foreign currency prices to base concurrency

use_exchange_tz
bool (optional) Default: false Example: false

convert execution times to exchange timezone

include_unfilled
bool (optional) Default: true Example: true

include orders with no executions

Response  200
Headers
Content-Type: application/json
Body
[
    {
        TO: DO
    }
]

Trades

Get Historical Trades
GET/blotter/accounts/{account}/trades{?strategies,start_date,end_date,include_unfilled}

Returns trades from the blotter database.

Example URI

GET http://houston:1969/blotter/accounts/U123456/trades?strategies=secretstrategy&start_date=2017-04-01&end_date=2017-06-30&include_unfilled=true
URI Parameters
account
str (required) Example: U123456

the account for which trades should be returned

strategies
str (optional) Example: secretstrategy

limit to these strategies/order refs (pass multiple times for multiple strategies)

start_date
date (optional) Example: 2017-04-01

limit to executions on or after this date

end_date
date (optional) Example: 2017-06-30

limit to executions on or before this date

include_unfilled
bool (optional) Default: true Example: true

include orders with no executions

strategy_merge: `secretstrategy_a:secretstrategy_b` (str, optional) - given a string of the form `a
pass multiple times to merge multiple strategies (required) Example: b` (which must be percent-encoded), include `a`'s trades under `b`'s'
Response  200
Headers
Content-Type: application/json
Body
[
    {
        TO: DO
    }
]

calendar

exchange calendar service

QuantRocket calendar CLI

usage: quantrocket calendar [-h] {isopen,isclosed,closings,load} ...
Sub-commands:
isopen

assert that one or more exchanges is open and return a non-zero exit code if closed

usage: quantrocket calendar isopen [-h] [-i TIMEDELTA] [-a TIMEDELTA]
                                   EXCHANGE [EXCHANGE ...]
Positional arguments:
exchangesthe exchange(s) to check
Options:
-i, --inassert that the exchange(s) will be open in the future (use Pandas timedelta string, e.g. 2h)
-a, --agoassert that the exchange(s) was open in the past (use Pandas timedelta string, e.g. 2h)
isclosed

assert that one or more exchanges is closed and return a non-zero exit code if open

usage: quantrocket calendar isclosed [-h] [-i TIMEDELTA] [-a TIMEDELTA]
                                     EXCHANGE [EXCHANGE ...]
Positional arguments:
exchangesthe exchange(s) to check
Options:
-i, --inassert that the exchange(s) will be closed in the future (use Pandas timedelta string)
-a, --agoassert that the exchange(s) was closed in the past (use Pandas timedelta string)
closings

get exchange closings

usage: quantrocket calendar closings [-h] [-x EXCHANGE] [-s YYYY-MM-DD]
                                     [-e YYYY-MM-DD] [-a TIMEDELTA]
                                     [-b TIMEDELTA] [-t TYPE]
Options:
-x, --exchanges
 limit to these exchanges
-s, --start-date
 limit to closings on or after this date
-e, --end-datelimit to closings on or before this date
-a, --afterlimit to closings on or after this many days/hours/etc in the past (use Pandas timedelta string, e.g. 7d)
-b, --beforelimit to closings on or before this many days/hours/etc in the future (use Pandas timedelta string, e.g. 7d)
-t, --types

limit to these closing types. Possible choices: %(choices)s

Possible choices: full, half

load

load exchange closings from file

usage: quantrocket calendar load [-h] filename
Positional arguments:
filenameCSV containing with columns ‘date’, ‘exchange’, and optionally ‘type’ (‘full’ or ‘half’)
 

Calendar API

Calendar

Timezones

Get All Exchange Timezones
GET/calendar/timezone/

Returns the timezone for all exchanges.

Example URI

GET http://houston:1969/calendar/timezone/
Response  200
Headers
Content-Type: application/json
Body
{
  "ASX": "Australia/Sydney",
  "NYSE": "America/New_York",
  "LSE": "Europe/London",
  "SGX": "Asia/Singapore",
  "TSE": "America/Toronto",
  "TSEJ": "Japan"
}

Get Exchange Timezone
GET/calendar/timezone/{exchange}

Returns the timezone for the exchange.

Example URI

GET http://houston:1969/calendar/timezone/NYSE
URI Parameters
exchange
str (required) Example: NYSE

the exchange code

Response  200
Headers
Content-Type: application/json
Body
{
  "NYSE": "America/New_York"
}

countdown

cron service

QuantRocket cron service CLI

usage: quantrocket countdown [-h] {crontab,timezone} ...
Sub-commands:
crontab

upload a new crontab, or return the current crontab

usage: quantrocket countdown crontab [-h] SERVICE_NAME [FILENAME]
Positional arguments:
servicethe name of the countdown service, e.g. countdown-usa
filenamethe crontab file to upload (if omitted, return the current crontab)
timezone

show the countdown service timezone

usage: quantrocket countdown timezone [-h] SERVICE_NAME
Positional arguments:
serviceThe name of the countdown service, e.g. countdown-usa
quantrocket.countdown.get_crontab(service)

Return the current crontab.

Parameters:

service : str, required

the name of the service, e.g. countdown-usa

Returns:

str

string representation of crontab

quantrocket.countdown.get_timezone(service)

Return the service timezone.

Parameters:

service : str, required

the name of the service, e.g. countdown-usa

Returns:

dict

dict with key timezone

quantrocket.countdown.load_crontab(service, filename)

Upload a new crontab.

Parameters:

service : str, required

the name of the service, e.g. countdown-usa

filename : str, required

the crontab file to upload to the countdown service

Returns:

dict

status message

 

Countdown API

Countdown

Crontab

Get Crontab
GET/{service}/crontab

Returns the service crontab.

Example URI

GET http://houston:1969/countdown-usa/crontab
URI Parameters
service
str (required) Example: countdown-usa

The name of the countdown-service, e.g. countdown-usa

Response  200
Headers
Content-Type: text/plain
Body
30 9 1-31 1-12 1-5 curl -X POST https://houston/api/endpoint1
30 17 1-31 1-12 1-5 curl -X POST https://houston/api/endpoint2

Load Crontab
PUT/{service}/crontab

Uploads a new crontab.

Example URI

PUT http://houston:1969/countdown-usa/crontab
URI Parameters
service
str (required) Example: countdown-usa

The name of the countdown-service, e.g. countdown-usa

Request
Headers
Content-Type: text/plain
Body
30 9 1-31 1-12 1-5 curl -X POST https://houston/api/endpoint1
30 17 1-31 1-12 1-5 curl -X POST https://houston/api/endpoint2
0 12 1-31 1-12 1-7 curl -X POST https://houston/api/endpoint3
Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the crontab will be loaded asynchronously"
}

Timezone

Get Timezone
GET/{service}/timezone

Returns the service timezone.

Example URI

GET http://houston:1969/countdown-usa/timezone
URI Parameters
service
str (required) Example: countdown-usa

The name of the countdown-service, e.g. countdown-usa

Response  200
Headers
Content-Type: application/json
Body
{
  "timezone": "America/New_York"
}

db

database backup and download service

QuantRocket database service CLI

usage: quantrocket db [-h] {list,get,s3push,s3pull,optimize} ...
Sub-commands:
list

list databases

usage: quantrocket db list [-h] [SERVICE]
Positional arguments:
serviceonly list databases for this service
get

download a database from the db service and write to a local file

usage: quantrocket db get [-h] DATABASE OUTFILE
Positional arguments:
databasethe filename of the database (as returned by the list command)
outfilefilename to write the database to
s3push

push database(s) to Amazon S3

usage: quantrocket db s3push [-h] SERVICE [DATABASE_CODE [DATABASE_CODE ...]]
Positional arguments:
serviceonly push databases for this service (specify ‘all’ to push all services)
codesonly push databases identified by these codes (omit to push all databases for service)
s3pull

pull database(s) from Amazon S3 to the db service

usage: quantrocket db s3pull [-h] [-f]
                             SERVICE [DATABASE_CODE [DATABASE_CODE ...]]
Positional arguments:
serviceonly pull databases for this service (specify ‘all’ to pull all services)
codesonly pull databases identified by these codes (omit to pull all databases for service)
Options:
-f=False, --force=False
 overwrite existing database if one exists (default is to fail if one exists)
optimize

optimize database file(s) to improve performance

usage: quantrocket db optimize [-h]
                               SERVICE [DATABASE_CODE [DATABASE_CODE ...]]
Positional arguments:
serviceonly optimize databases for this service (specify ‘all’ to optimize all services)
codesonly optimize databases identified by these codes (omit to optimize all databases for service)
quantrocket.db.download_database(database, outfile)

Download a database from the db service and write to a local file.

Parameters:

database : str, required

the filename of the database (as returned by the list_databases)

outfile: str, required

filename to write the database to

Returns:

None

quantrocket.db.list_databases(service=None)

List databases.

Parameters:

service : str, optional

only list databases for this service

Returns:

list

list of databases

quantrocket.db.optimize_databases(service, codes=None)

Optimize database file(s) to improve performance.

Parameters:

serivce : str, required

only optimize databases for this service (specify ‘all’ to optimize all services)

codes: list of str, optional

only optimize databases identified by these codes (omit to optimize all databases for service)

Returns:

json

status message

quantrocket.db.s3_pull_databases(service, codes=None, force=False)

Pull database(s) from Amazon S3 to the db service.

Parameters:

serivce : str, required

only pull databases for this service (specify ‘all’ to pull all services)

codes: list of str, optional

only pull databases identified by these codes (omit to pull all databases for service)

force: bool

overwrite existing database if one exists (default is to fail if one exists)

Returns:

json

status message

quantrocket.db.s3_push_databases(service, codes=None)

Push database(s) to Amazon S3.

Parameters:

serivce : str, required

only push databases for this service (specify ‘all’ to push all services)

codes: list of str, optional

only push databases identified by these codes (omit to push all databases for service)

Returns:

json

status message

 

DB API

DB

Database List

List Databases
GET/db/databases{?service}

List databases.

Example URI

GET http://houston:1969/db/databases?service=history
URI Parameters
service
str (optional) Example: history

only list databases for this service

Response  200
Headers
Content-Type: application/json
Body
[
    "quantrocket.history.canada.sqlite",
    "quantrocket.history.australia_eod.sqlite",
]

Database Downloads

Download Database
GET/db/databases/{database}

Download a database from the db service.

Example URI

GET http://houston:1969/db/databases/quantrocket.history.canada.sqlite
URI Parameters
database
str (required) Example: quantrocket.history.canada.sqlite

the filename of the database (as returned by the list endpoint)

Response  200
Headers
Content-Type: application/x-sqlite3
Body
(binary file)

S3

S3 Pull
GET/db/s3/{service}{?codes,force}

Pull database(s) from Amazon S3 to the db service.

Example URI

GET http://houston:1969/db/s3/history?codes=canada&force=true
URI Parameters
service
str (required) Example: history

only pull databases for this service (specify all to pull all services)

codes
str (optional) Example: canada

only pull databases identified by these codes (omit to pull all databases for service)

force
bool (optional) Example: true

overwrite existing database if one exists (default is to fail if one exists)

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the databases will be pulled from S3 asynchronously"
}

S3 Push
PUT/db/s3/{service}{?codes}

Push database(s) to Amazon S3.

Example URI

PUT http://houston:1969/db/s3/history?codes=canada
URI Parameters
service
str (required) Example: history

only push databases for this service (specify all to push all services)

codes
str (optional) Example: canada

only push databases identified by these codes (omit to push all databases for service)

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the databases will be pushed to S3 asynchronously"
}

Optimizations

Optimize Database
POST/db/optimizations/{service}{?codes}

Optimize database file(s) to improve performance.

Example URI

POST http://houston:1969/db/optimizations/history?codes=canada
URI Parameters
service
str (required) Example: history

only optimize databases for this service (specify all to optimize all services)

codes
str (optional) Example: canada

only optimize databases identified by these codes (omit to optimize all databases for service)

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the databases will be optimized asynchronously"
}

flightlog

logging service

QuantRocket logging service CLI

usage: quantrocket flightlog [-h] {stream,get,log} ...
Sub-commands:
stream

stream application logs, `tail -f` style

usage: quantrocket flightlog stream [-h] [-d] [--hist NUM_LINES] [--nocolor]
Options:
-d=False, --detail=False
 show detailed logs from logspout, otherwise show log messages from flightlog only
--histnumber of log lines to show right away (ignored if showing detailed logs)
--nocolor=Truedon’t colorize the logs
get

download the logfile

usage: quantrocket flightlog get [-h] [-d] OUTFILE
Positional arguments:
outfilefilename to write the logfile to
Options:
-d=False, --detail=False
 download detailed logs from logspout, otherwise download log messages from flightlog only
log

log a message

usage: quantrocket flightlog log [-h] [-l LEVEL] [-n LOGGER_NAME] [msg]
Positional arguments:
msgthe message to be logged
Options:
-l=INFO, --level=INFO
 

the log level for the message. Possible choices: %(choices)s

Possible choices: DEBUG, INFO, WARNING, ERROR, CRITICAL

-n=quantrocket.cli, --name=quantrocket.cli
 the logger name
quantrocket.flightlog.FlightlogHandler(background=None)

Returns a log handler that logs to flightlog.

Parameters:

background : bool

If True, causes logging to happen in a background thread so that logging doesn’t block. Background logging requires Python 3.2 or higher, and defaults to True for supported versions and False otherwise.

Returns:

logging.handlers.QueueHandler or quantrocket.flightlog._ImpatientHttpHandler

Examples

Log a message using the FlightlogHandler:

>>> import logging
>>> from quantrocket.flightlog import FlightlogHandler
>>> logger = logging.getLogger('myapp')
>>> logger.setLevel(logging.DEBUG)
>>> handler = FlightlogHandler()
>>> logger.addHandler(handler)
>>> logger.info('my app just opened a position')
quantrocket.flightlog.download_logfile(outfile, detail=False)

Download the logfile.

Parameters:

outfile: str, required

filename to write the logfile to

detail : bool

if True, show detailed logs from logspout, otherwise show log messages from flightlog only (default False)

Returns:

None

quantrocket.flightlog.stream_logs(detail=False, hist=None, color=True)

Stream application logs, tail -f style.

Parameters:

detail : bool

if True, show detailed logs from logspout, otherwise show log messages from flightlog only (default False)

hist : int, optional

number of log lines to show right away (ignored if showing detailed logs)

color : bool

colorize the logs

Yields:

str

each log line as it arrives

 

Flightlog API

Flightlog

Logfiles

Download log files
GET/flightlog/logfile/{logtype}

Download the logfile.

Example URI

GET http://houston:1969/flightlog/logfile/app
URI Parameters
logtype
str (required) Example: app

the type of logfile to download

Choices: app system

Response  200
Headers
Content-Type: text/plain
Body
2017-01-18 10:19:31 quantrocket.flightlog: INFO Detected a change in flightlog configs directory, reloading configs...
2017-01-18 10:19:31 quantrocket.flightlog: INFO Successfully loaded config
2017-01-18 14:25:57 quantrocket.master: INFO Requesting contract details for error 200 symbols

Log Stream

Stream logs
GET/flightlog/stream/logs{?hist,nocolor}

Stream application logs, tail -f style.

Example URI

GET http://houston:1969/flightlog/stream/logs?hist=5&nocolor=
URI Parameters
hist
int (optional) Example: 5

number of log lines to show right away

nocolor
str (optional) 

don’t colorize the logs if nocolor parameter is passed (parameter value doesn’t matter)

Response  200
Headers
Content-Type: text/plain
Transfer-Encoding: chunked
Body
2017-01-18 10:19:31 quantrocket.flightlog: INFO Detected a change in flightlog configs directory, reloading configs...
2017-01-18 10:19:31 quantrocket.flightlog: INFO Successfully loaded config
2017-01-18 14:25:57 quantrocket.master: INFO Requesting contract details for error 200 symbols

Logspout Stream

Stream logspout
GET/logspout/logs{?colors}

Stream detailed logs from logspout, tail -f style.

Example URI

GET http://houston:1969/logspout/logs?colors=off
URI Parameters
colors
str (optional) Example: off

don’t colorize the logs if colors=off (colorized by default)

Response  200
Headers
Content-Type: text/plain
Transfer-Encoding: chunked
Body
quantrocket_houston_1|172.21.0.1 - - [18/Jan/2017:10:14:48 +0000] "POST /flightlog/handler HTTP/1.1" 200 5 "-" "-"
2017-01-18 10:19:31 quantrocket.flightlog: INFO Detected a change in flightlog configs directory, reloading configs...
2017-01-18 10:19:31 quantrocket.flightlog: INFO Successfully loaded config
2017-01-18 14:25:57 quantrocket.master: INFO Requesting contract details for error 200 symbols
test_houston_1|2017/01/18 20:59:01 [error] 5#5: *17137 open() "/usr/local/openresty/nginx/html/invalidpath" failed (2: No such file or directory), client: 172.20.0.8, server: localhost, request: "GET /invalidpath HTTP/1.1", host: "houston"

fundamental

fundamental data service

QuantRocket fundamental data CLI

usage: quantrocket fundamental [-h]
                               {fetch-financials,fetch-estimates,codes,financials,estimates}
                               ...
Sub-commands:
fetch-financials

fetch Reuters financial statements from IB and save to database

usage: quantrocket fundamental fetch-financials [-h]
                                                [-u [UNIVERSE [UNIVERSE ...]]]
                                                [-i [CONID [CONID ...]]]
Options:
-u, --universes
 limit to these universes (must provide universes, conids, or both)
-i, --conids limit to these conids (must provide universes, conids, or both)
fetch-estimates

fetch Reuters estimates and actuals from IB and save to database

usage: quantrocket fundamental fetch-estimates [-h]
                                               [-u [UNIVERSE [UNIVERSE ...]]]
                                               [-i [CONID [CONID ...]]]
Options:
-u, --universes
 limit to these universes (must provide universes, conids, or both)
-i, --conids limit to these conids (must provide universes, conids, or both)
codes

list available Chart of Account (COA) codes from the Reuters financials database and/or indicator codes from the Reuters estimates/actuals database

usage: quantrocket fundamental codes [-h] [-c [CODE [CODE ...]]]
                                     [-r [REPORT_TYPE [REPORT_TYPE ...]]]
                                     [-s [STATEMENT_TYPE [STATEMENT_TYPE ...]]]
Options:
-c, --codes limit to these Chart of Account (COA) or indicator codes
-r, --report-types
 

limit to these report types. Possible choices: %(choices)s

Possible choices: financials, estimates

-s, --statement-types
 

limit to these statement types. Only applies to financials, not estimates. Possible choices: %(choices)s

Possible choices: INC, BAL, CAS

financials

query financial statements from the Reuters financials database and download to file

usage: quantrocket fundamental financials [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                          [-u [UNIVERSE [UNIVERSE ...]]]
                                          [-i [CONID [CONID ...]]]
                                          [--exclude-universes [UNIVERSE [UNIVERSE ...]]]
                                          [--exclude-conids [CONID [CONID ...]]]
                                          [-q] [-r] [-o OUTFILE] [-j | -p]
                                          [-f [FIELD [FIELD ...]]]
                                          CODE [CODE ...]
Positional arguments:
codes the Chart of Account (COA) code(s) to query
Options:
-s, --start-date
 limit to statements on or after this date (based on the fiscal period end date if including restatements, otherwise the filing date)
-e, --end-date limit to statements on or before this date (based on the fiscal period end date if including restatements, otherwise the filing date)
-u, --universes
 limit to these universes
-i, --conids limit to these conids
--exclude-universes
 exclude these universes
--exclude-conids
 exclude these conids
-q=False, --interim=False
 return interim/quarterly reports (default is to return annual reports, which provide deeper history)
-r=False, --restatements=False
 include restatements (default is to exclude them)
-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
-p, --pretty format output in human-readable format (default is CSV)
-f, --fields only return these fields
estimates

query estimates and actuals from the Reuters estimates database and download to file

usage: quantrocket fundamental estimates [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                         [-u [UNIVERSE [UNIVERSE ...]]]
                                         [-i [CONID [CONID ...]]]
                                         [--exclude-universes [UNIVERSE [UNIVERSE ...]]]
                                         [--exclude-conids [CONID [CONID ...]]]
                                         [-t [PERIOD_TYPE [PERIOD_TYPE ...]]]
                                         [-o OUTFILE] [-j | -p]
                                         [-f [FIELD [FIELD ...]]]
                                         CODE [CODE ...]
Positional arguments:
codes the indicator code(s) to query
Options:
-s, --start-date
 limit to estimates and actuals on or after this fiscal period end date
-e, --end-date limit to estimates and actuals on or before this fiscal period end date
-u, --universes
 limit to these universes
-i, --conids limit to these conids
--exclude-universes
 exclude these universes
--exclude-conids
 exclude these conids
-t, --period-types
 

limit to these fiscal period types. Possible choices: %(choices)s, where A=Annual, Q=Quarterly, S=Semi-Annual

Possible choices: A, Q, S

-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
-p, --pretty format output in human-readable format (default is CSV)
-f, --fields only return these fields
quantrocket.fundamental.download_reuters_estimates(codes, filepath_or_buffer=None, output='csv', start_date=None, end_date=None, universes=None, conids=None, exclude_universes=None, exclude_conids=None, period_types=None, fields=None)

Query estimates and actuals from the Reuters estimates database and download to file.

You can query one or more indicator codes. Use the list_reuters_codes function to see available codes.

Parameters:

codes : list of str, required

the indicator code(s) to query

filepath_or_buffer : str or file-like object

filepath to write the data to, or file-like object (defaults to stdout)

output : str

output format (json, csv, txt, default is csv)

start_date : str (YYYY-MM-DD), optional

limit to estimates and actuals on or after this fiscal period end date

end_date : str (YYYY-MM-DD), optional

limit to estimates and actuals on or before this fiscal period end date

universes : list of str, optional

limit to these universes

conids : list of int, optional

limit to these conids

exclude_universes : list of str, optional

exclude these universes

exclude_conids : list of int, optional

exclude these conids

period_types : list of str, optional

limit to these fiscal period types. Possible choices: A, Q, S, where A=Annual, Q=Quarterly, S=Semi-Annual

fields : list of str, optional

only return these fields

Returns:

None

Examples

Query EPS estimates and actuals for a universe of Australian stocks. You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_reuters_estimates(["EPS"], f, universes=["asx-stk"],
                                start_date="2014-01-01"
                                end_date="2017-01-01")
>>> estimates = pd.read_csv(f, parse_dates=["FiscalPeriodEndDate", "AnnounceDate"])
quantrocket.fundamental.download_reuters_financials(codes, filepath_or_buffer=None, output='csv', start_date=None, end_date=None, universes=None, conids=None, exclude_universes=None, exclude_conids=None, interim=False, restatements=False, fields=None)

Query financial statements from the Reuters financials database and download to file.

You can query one or more COA codes. Use the list_reuters_codes function to see available codes.

Annual or interim/quarterly reports are available. Annual is the default and provides deeper history.

By default restatements are excluded, but they can optionally be included.

Parameters:

codes : list of str, required

the Chart of Account (COA) code(s) to query

filepath_or_buffer : str or file-like object

filepath to write the data to, or file-like object (defaults to stdout)

output : str

output format (json, csv, txt, default is csv)

start_date : str (YYYY-MM-DD), optional

limit to statements on or after this date (based on the fiscal period end date if including restatements, otherwise the filing date)

end_date : str (YYYY-MM-DD), optional

limit to statements on or before this date (based on the fiscal period end date if including restatements, otherwise the filing date)

universes : list of str, optional

limit to these universes

conids : list of int, optional

limit to these conids

exclude_universes : list of str, optional

exclude these universes

exclude_conids : list of int, optional

exclude these conids

interim : bool, optional

return interim/quarterly reports (default is to return annual reports, which provide deeper history)

restatements : bool, optional

include restatements (default is to exclude them)

fields : list of str, optional

only return these fields

Returns:

None

Examples

Query total revenue (COA code RTLR) for a universe of Australian stocks. You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_reuters_financials(["RTLR"], f, universes=["asx-stk"],
                                start_date="2014-01-01"
                                end_date="2017-01-01")
>>> financials = pd.read_csv(f, parse_dates=["StatementDate", "SourceDate", "FiscalPeriodEndDate"])

Query net income (COA code NINC) from interim/quarterly reports for two securities (identified by conid) and include restatements:

>>> download_reuters_financials(["NINC"], f, conids=[123456, 234567],
                                interim=True, restatements=True)

Query common and preferred shares outstanding (COA codes QTCO and QTPO) and return a minimal set of fields (several required fields will always be returned):

>>> download_reuters_financials(["QTCO", "QTPO"], f, universes=["nyse-stk"],
                                fields=["Amount"])
quantrocket.fundamental.fetch_reuters_estimates(universes=None, conids=None)

Fetch Reuters estimates and actuals from IB and save to database.

This data provides analyst estimates and actuals for a variety of indicators.

Parameters:

universes : list of str, optional

limit to these universes (must provide universes, conids, or both)

conids : list of int, optional

limit to these conids (must provide universes, conids, or both)

Returns:

dict

status message

quantrocket.fundamental.fetch_reuters_financials(universes=None, conids=None)

Fetch Reuters financial statements from IB and save to database.

This data provides cash flow, balance sheet, and income metrics.

Parameters:

universes : list of str, optional

limit to these universes (must provide universes, conids, or both)

conids : list of int, optional

limit to these conids (must provide universes, conids, or both)

Returns:

dict

status message

quantrocket.fundamental.list_reuters_codes(codes=None, report_types=None, statement_types=None)

List available Chart of Account (COA) codes from the Reuters financials database and/or indicator codes from the Reuters estimates/actuals database

Note: you must fetch Reuters financials into the database before you can list COA codes.

Parameters:

codes : list of str, optional

limit to these Chart of Account (COA) or indicator codes

report_types : list of str, optional

limit to these report types. Possible choices: financials, estimates

statement_types : list of str, optional

limit to these statement types. Only applies to financials, not estimates. Possible choices: INC, BAL, CAS

Returns:

dict

codes and descriptions

 

Fundamental Data API

Fundamental Data

Reuters Financials

Fetch Reuters Financials
POST/fundamental/reuters/financials{?universes,conids}

Fetch Reuters financial statements from IB and save to database.

This data provides cash flow, balance sheet, and income metrics.

Example URI

POST http://houston:1969/fundamental/reuters/financials?universes=japan-banks&conids=12345
URI Parameters
universes
str (optional) Example: japan-banks

limit to these universes (must provide universes, conids, or both) (pass multiple times for multiple universes)

conids
int (optional) Example: 12345

limit to these conids (must provide universes, conids, or both) (pass multiple times for multiple conids)

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the fundamental data will be fetched asynchronously"
}

Download Reuters Financials
GET/fundamental/reuters/financials{filetype}{?codes,start_date,end_date,universes,conids,exclude_universes,exclude_conids,interim,restatements,fields}

Query financial statements from the Reuters financials database and download to file.

You can query one or more COA codes.

Annual or interim/quarterly reports are available. Annual is the default and provides deeper history.

By default restatements are excluded, but they can optionally be included.

Example URI

GET http://houston:1969/fundamental/reuters/financials.csv?codes=QTCO&start_date=2014-01-01&end_date=2018-01-01&universes=japan-banks&conids=12345&exclude_universes=&exclude_conids=&interim=true&restatements=false&fields=Amount
URI Parameters
codes
str (required) Example: QTCO

the Chart of Account (COA) code(s) to query (pass multiple times for multiple codes)

filetype
str (required) Example: .csv

output format

Choices: .csv .json .txt

start_date
str (optional) Example: 2014-01-01

limit to statements on or after this date (based on the fiscal period end date if including restatements, otherwise the filing date)

end_date
str (optional) Example: 2018-01-01

limit to statements on or before this date (based on the fiscal period end date if including restatements, otherwise the filing date)

universes
str (optional) Example: japan-banks

limit to these universes (pass multiple times for multiple universes)

conids
int (optional) Example: 12345

limit to these conids (pass multiple times for multiple conids)

exclude_universes
str (optional) 

exclude these universes (pass multiple times for multiple universes)

exclude_conids
int (optional) 

exclude these conids (pass multiple times for multiple conids)

interim
bool (optional) Example: true

return interim/quarterly reports (default is to return annual reports, which provide deeper history)

restatements
bool (optional) Example: false

include restatements (default is to exclude them)

fields
str (optional) Example: Amount

only return these fields (pass multiple times for multiple fields)

Response  200
Headers
Content-Type: text/csv
Body
CoaCode,ConId,Amount,FiscalYear,FiscalPeriodEndDate,FiscalPeriodType,FiscalPeriodNumber,StatementType,StatementPeriodLength,StatementPeriodUnit,UpdateTypeCode,UpdateTypeDescription,StatementDate,AuditorNameCode,AuditorName,AuditorOpinionCode,AuditorOpinion,Source,SourceDate
EIBT,9029,13.53,2014,2014-12-31,Annual,,INC,12,M,UPD,"Updated Normal",2014-12-31,EY,"Ernst & Young LLP",UNQ,Unqualified,10-K,2015-03-13
EIBT,9029,28.117,2015,2015-12-31,Annual,,INC,12,M,UPD,"Updated Normal",2015-12-31,EY,"Ernst & Young LLP",UNQ,Unqualified,10-K,2016-02-29

Reuters Estimates

Fetch Reuters Estimates
POST/fundamental/reuters/estimates{?universes,conids}

Fetch Reuters estimates and actuals from IB and save to database.

This data provides analyst estimates and actuals for a variety of indicators.

Example URI

POST http://houston:1969/fundamental/reuters/estimates?universes=japan-banks&conids=12345
URI Parameters
universes
str (optional) Example: japan-banks

limit to these universes (must provide universes, conids, or both) (pass multiple times for multiple universes)

conids
int (optional) Example: 12345

limit to these conids (must provide universes, conids, or both) (pass multiple times for multiple conids)

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the fundamental data will be fetched asynchronously"
}

Download Reuters Estimates
GET/fundamental/reuters/estimates{filetype}{?codes,start_date,end_date,universes,conids,exclude_universes,exclude_conids,period_types,fields}

Query estimates and actuals from the Reuters estimates database and download to file.

You can query one or more indicator codes.

Example URI

GET http://houston:1969/fundamental/reuters/estimates.csv?codes=EPS&start_date=2014-01-01&end_date=2018-01-01&universes=japan-banks&conids=12345&exclude_universes=&exclude_conids=&period_types=A&fields=Actual
URI Parameters
codes
str (required) Example: EPS

the indicator code(s) to query (pass multiple times for multiple codes)

filetype
str (required) Example: .csv

output format

Choices: .csv .json .txt

start_date
str (optional) Example: 2014-01-01

limit to estimates and actuals on or after this fiscal period end date

end_date
str (optional) Example: 2018-01-01

limit to estimates and actuals on or before this fiscal period end date

universes
str (optional) Example: japan-banks

limit to these universes (pass multiple times for multiple universes)

conids
int (optional) Example: 12345

limit to these conids (pass multiple times for multiple conids)

exclude_universes
str (optional) 

exclude these universes (pass multiple times for multiple universes)

exclude_conids
int (optional) 

exclude these conids (pass multiple times for multiple conids)

period_types
str (optional) Example: A

limit to these fiscal period types (A=Annual, Q=Quarterly, S=Semi-Annual)

Choices: A Q S

fields
str (optional) Example: Actual

only return these fields (pass multiple times for multiple fields)

Response  200
Headers
Content-Type: text/csv
Body
ConId,Indicator,Unit,FiscalYear,FiscalPeriodEndDate,FiscalPeriodType,FiscalPeriodNumber,High,Low,Mean,Median,StdDev,NumOfEst,AnnounceDate,UpdatedDate,Actual
9029,EPS,U,2014,2014-03-31,Q,1,0.31,0.2,0.255,0.255,0.055,2,2014-05-01T11:45:00,2014-05-01T12:06:31,0.12
9029,EPS,U,2014,2014-06-30,Q,2,0.77,0.73,0.7467,0.74,0.017,3,2014-07-31T11:45:00,2014-07-31T13:47:24,1.02

Reuters Codes

List Reuters Codes
GET/fundamental/reuters/codes{?codes,report_types,statement_types}

List available Chart of Account (COA) codes from the Reuters financials database and/or indicator codes from the Reuters estimates/actuals database

Note: you must fetch Reuters financials into the database before you can list COA codes.

Example URI

GET http://houston:1969/fundamental/reuters/codes?codes=&report_types=financials&statement_types=INC
URI Parameters
codes
str (optional) 

limit to these Chart of Account (COA) or indicator codes (pass multiple times for multiple codes)

report_types
str (optional) Example: financials

limit to these report types (pass multiple times for multiple report types)

Choices: financials estimates

statement_types
str (optional) Example: INC

limit to these statement types. Only applies to financials, not estimates (pass multiple times for multiple statement types)

Choices: INC BAL CAS

Response  200
Headers
Content-Type: application/json
Body
{
  "financials": {
    "FCDP": "Total Cash Dividends Paid",
    "FPRD": "Issuance (Retirement) of Debt, Net",
    "FPSS": "Issuance (Retirement) of Stock, Net",
    "FTLF": "Cash from Financing Activities",
    "ITLI": "Cash from Investing Activities",
    "OBDT": "Deferred Taxes",
    "OCPD": "Cash Payments",
    "OCRC": "Cash Receipts"
  }
}

history

historical market data service

QuantRocket historical market data CLI

usage: quantrocket history [-h]
                           {create-db,fetch,queue,cancel,load,get,config,drop-db}
                           ...
Sub-commands:
create-db

create a new history database

usage: quantrocket history create-db [-h] [-u [UNIVERSE [UNIVERSE ...]]]
                                     [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                     [-v VENDOR] [-z BAR_SIZE] [-t BAR_TYPE]
                                     [-o] [-p]
                                     [--times [HH:MM:SS [HH:MM:SS ...]]] [-n]
                                     [-f CONFIG_FILE]
                                     CODE
Positional arguments:
code the code to assign to the database (lowercase alphanumerics and hyphens only)
Options:
-u, --universes
 include these universes
-s, --start-date
 fetch history back to this start date (default is to fetch as far back as data is available)
-e, --end-date fetch history up to this end date (default is to fetch up to the present)
-v, --vendor

the vendor to fetch data from (defaults to ‘ib’ which is currently the only supported vendor)

Possible choices: ib

-z, --bar-size

the bar size to fetch. Possible choices: %(choices)s

Possible choices: 1 secs, 5 secs, 10 secs, 15 secs, 30 secs, 1 min, 2 mins, 3 mins, 5 mins, 10 mins, 15 mins, 20 mins, 30 mins, 1 hour, 2 hours, 3 hours, 4 hours, 8 hours, 1 day, 1 week, 1 month

-t, --bar-type

the bar type to fetch (if not specified, defaults to MIDPOINT for forex and TRADES for everything else). Possible choices: %(choices)s

Possible choices: TRADES, ADJUSTED_LAST, MIDPOINT, BID, ASK, BID_ASK, HISTORICAL_VOLATILITY, OPTION_IMPLIED_VOLATILITY

-o=False, --outside-rth=False
 include data from outside regular trading hours (default is to limit to regular trading hours)
-p=False, --primary-exchange=False
 limit to data from the primary exchange
--times limit to these times
-n=False, --no-config=False
 create a database with no config (data can be loaded manually instead of fetched from a vendor)
-f, --config-file
 the path to a YAML config file defining the historical data requirements
fetch

fetch historical market data from IB and save it to a history database

usage: quantrocket history fetch [-h] [-p] [-i [CONID [CONID ...]]]
                                 [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                 CODE [CODE ...]
Positional arguments:
codes the database code(s) to fetch data for
Options:
-p=False, --priority=False
 use the priority queue (default is to use the standard queue)
-i, --conids fetch history for these conids (overrides config)
-s, --start-date
 fetch history back to this start date (overrides config)
-e, --end-date fetch history up to this end date (overrides config)
queue

get the current queue of historical data requests

usage: quantrocket history queue [-h]
cancel

cancel running or pending historical data requests

usage: quantrocket history cancel [-h] [-q QUEUE] CODE [CODE ...]
Positional arguments:
codes the database code(s) to cancel requests for
Options:
-q, --queues

only cancel requests in these queues. Possible choices: %(choices)s

Possible choices: standard, priority

load

load market data from a CSV file into a history database

usage: quantrocket history load [-h] code [infile]
Positional arguments:
code the database code to load into
infilepath_or_buffer
 CSV file containing market data (omit to read file from stdin)
get

query historical market data from a history database and download to file

usage: quantrocket history get [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                               [-u [UNIVERSE [UNIVERSE ...]]]
                               [-i [CONID [CONID ...]]]
                               [--exclude-universes [UNIVERSE [UNIVERSE ...]]]
                               [--exclude-conids [CONID [CONID ...]]]
                               [-t [HH:MM:SS [HH:MM:SS ...]]] [-o OUTFILE]
                               [-j | -p] [-f [FIELD [FIELD ...]]] [--tz-naive]
                               [-c HOW]
                               CODE
Positional arguments:
code the code of the database to query
Options:
-s, --start-date
 limit to history on or after this date
-e, --end-date limit to history on or before this date
-u, --universes
 limit to these universes
-i, --conids limit to these conids
--exclude-universes
 exclude these universes
--exclude-conids
 exclude these conids
-t, --times limit to these times
-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
-p, --pretty format output in human-readable format (default is CSV)
-f, --fields only return these fields
--tz-naive=False
 return timestamps without UTC offsets: 2018-02-01T10:00:00 (default is to include UTC offsets: 2018-02-01T10:00:00-4000)
-c, --cont-fut

stitch futures into continuous contracts using this method (default is not to stitch together). Possible choices: %(choices)s

Possible choices: concat

config

return the configuration for a history database

usage: quantrocket history config [-h] code
Positional arguments:
code the database code
drop-db

delete a history database

usage: quantrocket history drop-db [-h] --confirm-by-typing-db-code-again CODE
                                   code
Positional arguments:
code the database code
Options:
--confirm-by-typing-db-code-again
 enter the db code again to confirm you want to drop the database, its config, and all its data
quantrocket.history.cancel_history_requests(codes, queues=None)

Cancel running or pending historical data requests.

Parameters:

codes : list of str, required

the database code(s) to cancel requests for

queues : list of str, optional

only cancel requests in these queues. Possible choices: standard, priority

Returns:

dict

standard and priority queues

quantrocket.history.create_db(code, universes=None, start_date=None, end_date=None, vendor=None, bar_size=None, bar_type=None, outside_rth=False, primary_exchange=False, times=None, no_config=False, config_filepath_or_buffer=None)

Create a new history database.

Parameters:

code : str, required

the code to assign to the database (lowercase alphanumerics and hyphens only)

universes : list of str

include these universes

start_date : str (YYYY-MM-DD), optional

fetch history back to this start date (default is to fetch as far back as data is available)

end_date : str (YYYY-MM-DD), optional

fetch history up to this end date (default is to fetch up to the present)

vendor : str, optional

the vendor to fetch data from (defaults to ‘ib’ which is currently the only supported vendor)

bar_size : str, required for vendor ib

the bar size to fetch. Possible choices: “1 secs”, “5 secs”, “10 secs”, “15 secs”, “30 secs”, “1 min”, “2 mins”, “3 mins”, “5 mins”, “10 mins”, “15 mins”, “20 mins”, “30 mins”, “1 hour”, “2 hours”, “3 hours”, “4 hours”, “8 hours”, “1 day”, “1 week”, “1 month”

bar_type : str, optional

the bar type to fetch (if not specified, defaults to MIDPOINT for forex and TRADES for everything else). Possible choices: “TRADES”, “ADJUSTED_LAST”, “MIDPOINT”, “BID”, “ASK”, “BID_ASK”, “HISTORICAL_VOLATILITY”, “OPTION_IMPLIED_VOLATILITY”

outside_rth : bool

include data from outside regular trading hours (default is to limit to regular trading hours)

primary_exchange : bool

limit to data from the primary exchange (default False)

times : list of str (HH:MM:SS), optional

limit to these times

no_config : bool

create a database with no config (data can be loaded manually instead of fetched from a vendor)

config_filepath_or_buffer : str or file-like object, optional

a YAML config file defining the historical data requirements (specify ‘-‘ to read file from stdin)

Returns:

dict

status message

quantrocket.history.download_history_file(code, filepath_or_buffer=None, output='csv', start_date=None, end_date=None, universes=None, conids=None, exclude_universes=None, exclude_conids=None, times=None, cont_fut=None, fields=None, tz_naive=False)

Query historical market data from a history database and download to file.

Parameters:

code : str, required

the code of the database to query

filepath_or_buffer : str or file-like object

filepath to write the data to, or file-like object (defaults to stdout)

output : str

output format (json, csv, txt, default is csv)

start_date : str (YYYY-MM-DD), optional

limit to history on or after this date

end_date : str (YYYY-MM-DD), optional

limit to history on or before this date

universes : list of str, optional

limit to these universes (default is to return all securities in database)

conids : list of int, optional

limit to these conids

exclude_universes : list of str, optional

exclude these universes

exclude_conids : list of int, optional

exclude these conids

times: list of str (HH:MM:SS), optional

limit to these times

cont_fut : str

stitch futures into continuous contracts using this method (default is not to stitch together). Possible choices: concat

fields : list of str, optional

only return these fields

tz_naive : bool

return timestamps without UTC offsets: 2018-02-01T10:00:00 (default is to include UTC offsets: 2018-02-01T10:00:00-4000)

Returns:

None

Examples

You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_history_file("my-db", f)
>>> history = pd.read_csv(f, parse_dates=["Date"])
quantrocket.history.drop_db(code, confirm_by_typing_db_code_again=None)

Delete a history database.

Parameters:

code : str, required

the database code

confirm_by_typing_db_code_again : str, required

enter the db code again to confirm you want to drop the database, its config, and all its data

Returns:

dict

status message

quantrocket.history.fetch_history(codes, priority=False, conids=None, start_date=None, end_date=None)

Fetch historical market data from IB and save it to a history database. The request is queued and the data is fetched asynchronously.

Parameters:

codes : list of str, required

the database code(s) to fetch data for

priority : bool

use the priority queue (default is to use the standard queue)

conids : list of int, optional

fetch history for these conids (overrides config)

start_date : str (YYYY-MM-DD), optional

fetch history back to this start date (overrides config)

end_date : str (YYYY-MM-DD), optional

fetch history up to this end date (overrides config)

Returns:

dict

status message

quantrocket.history.get_db_config(code)

Return the configuration for a history database.

Parameters:

code : str, required

the database code

Returns:

dict

config

quantrocket.history.get_history_queue()

Get the current queue of historical data requests.

Returns:

dict

standard and priority queues

quantrocket.history.load_history_from_file(code, infilepath_or_buffer)

Load market data from a CSV file into a history database.

Parameters:

code : str, required

the database code to load into

infilepath_or_buffer : str or file-like object

CSV file containing market data (specify ‘-‘ to read file from stdin)

Returns:

dict

status message

 

Historical Data API

Historical Data

Databases

Create History Database
PUT/history/databases/{code}{?universes,start_date,end_date,vendor,bar_size,bar_type,outside_rth,primary_exchange,times,no_config}

Create a new history database.

Example URI

PUT http://houston:1969/history/databases/japan-bank-eod?universes=japan-bank&start_date=2010-06-01&end_date=&vendor=ib&bar_size=1 day&bar_type=TRADES&outside_rth=false&primary_exchange=true&times=09:29:50&no_config=false
URI Parameters
code
str (required) Example: japan-bank-eod

the code to assign to the database (lowercase alphanumerics and hyphens only)

universes
str (optional) Example: japan-bank

include these universes (pass multiple times for multiple universes)

start_date
str (optional) Example: 2010-06-01

fetch history back to this start date (default is to fetch as far back as data is available)

end_date
str (optional) 

fetch history up to this end date (default is to fetch up to the present)

vendor
str (optional) Example: ib

the vendor to fetch data from (defaults to ‘ib’ which is currently the only supported vendor)

bar_size
string (required) Example: 1 day

the bar size to fetch

Choices: 1 secs 5 secs 10 secs 15 secs 30 secs 1 min 2 mins 3 mins 5 mins 10 mins 15 mins 20 mins 30 mins 1 hour 2 hours 3 hours 4 hours 8 hours 1 day 1 week 1 month

bar_type
str (optional) Example: TRADES

the bar type to fetch (if not specified, defaults to MIDPOINT for forex and TRADES for everything else)

Choices: TRADES ADJUSTED_LAST MIDPOINT BID ASK BID_ASK HISTORICAL_VOLATILITY OPTION_IMPLIED_VOLATILITY

outside_rth
bool (required) Example: false

include data from outside regular trading hours (default is to limit to regular trading hours)

primary_exchange
bool (required) Example: true

limit to data from the primary exchange (default False)

times
str (optional) Example: 09:29:50

limit to these times (pass multiple times for multiple times)

no_config
bool (required) Example: false

create a database with no config (data can be loaded manually instead of fetched from a vendor)

Response  200
Headers
Content-Type: application/json
Body
{
  "status": "successfully created quantrocket.history.japan-bank-eod.sqlite"
}

Get History Database Config
GET/history/databases/{code}

Return the configuration for a history database.

Example URI

GET http://houston:1969/history/databases/japan-bank-eod
URI Parameters
code
str (required) Example: japan-bank-eod

the database code

Response  200
Headers
Content-Type: application/json
Body
{
  "universes": [
    "japan-bank"
  ],
  "start_date": "2010-06-01",
  "vendor": "ib",
  "bar_size": "1 day",
  "bar_type": "TRADES",
  "primary_exchange": true,
  "times": [
    "09:29:50"
  ]
}

Delete History Database
DELETE/history/databases/{code}{?confirm_by_typing_db_code_again}

Delete a history database.

Example URI

DELETE http://houston:1969/history/databases/japan-bank-eod?confirm_by_typing_db_code_again=japan-bank-eod
URI Parameters
code
str (required) Example: japan-bank-eod

the database code

confirm_by_typing_db_code_again
str (required) Example: japan-bank-eod

enter the db code again to confirm you want to drop the database, its config, and all its data

Response  200
Headers
Content-Type: application/json
Body
{
  "status": "deleted quantrocket.history.japan-bank-eod.sqlite"
}

Historical Data Queue

Fetch Historical Data
POST/history/queue{?codes,priority,conids,start_date,end_date}

Fetch historical market data from IB and save it to a history database. The request is queued and the data is fetched asynchronously.

Example URI

POST http://houston:1969/history/queue?codes=japan-bank-eod&priority=false&conids=12345&start_date=2016-06-01&end_date=
URI Parameters
codes
str (required) Example: japan-bank-eod

the database code(s) to fetch data for (pass multiple times for multiple codes)

priority
bool (optional) Example: false

use the priority queue (default is to use the standard queue)

conids
int (optional) Example: 12345

fetch history for these conids, overriding config (pass multiple times for multiple conids)

start_date
str (optional) Example: 2016-06-01

fetch history back to this start date, overriding config

end_date
str (optional) 

fetch history up to this end date, overriding config

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the historical data will be fetched asynchronously"
}

Get History Data Queue
GET/history/queue

Get the current queue of historical data requests.

Example URI

GET http://houston:1969/history/queue
Response  200
Headers
Content-Type: application/json
Body
{
  "priority": [
    "japan-bank"
  ],
  "standard": []
}

Cancel Historical Data Request
DELETE/history/queue{?codes,queues}

Cancel running or pending historical data requests.

Example URI

DELETE http://houston:1969/history/queue?codes=japan-bank-eod&queues=priority
URI Parameters
codes
str (required) Example: japan-bank-eod

the database code(s) to cancel requests for (pass multiple times for multiple codes)

queues
str (optional) Example: priority

only cancel requests in these queues

Choices: priority standard

Response  200
Headers
Content-Type: application/json
Body
{
  "priority": [],
  "standard": []
}

Historical Market Data

Query Historical Data
GET/history/{code}.{filetype}{?start_date,end_date,universes,conids,exclude_universes,exclude_conids,times,cont_fut,fields,tz_naive}

Query historical market data from a history database and download to file.

Example URI

GET http://houston:1969/history/japan-bank-eod.csv?start_date=2016-06-01&end_date=2017-06-01&universes=&conids=&exclude_universes=&exclude_conids=&times=09:29:50&cont_fut=&fields=Close&tz_naive=
URI Parameters
code
str (required) Example: japan-bank-eod

the code of the database to query

filetype
str (required) Example: csv

output format

Choices: csv json txt

start_date
str (optional) Example: 2016-06-01

limit to history on or after this date

end_date
str (optional) Example: 2017-06-01

limit to history on or before this date

universes
str (optional) 

limit to these universes (default is to return all securities in database) (pass multiple times for multiple universes)

conids
int (optional) 

limit to these conids (pass multiple times for multiple conids)

exclude_universes
str (optional) 

exclude these universes (pass multiple times for multiple universes)

exclude_conids
int (optional) 

exclude these conids (pass multiple times for multiple conids)

times
str (optional) Example: 09:29:50

limit to these times (pass multiple times for multiple times)

cont_fut
str (optional) 

stitch futures into continuous contracts using this method (default is not to stitch together)

Choices: concat adjust

fields
str (optional) Example: Close

only return these fields

tz_naive
bool (optional) 

return timestamps without UTC offsets: 2018-02-01T10:00:00 (default is to include UTC offsets: 2018-02-01T10:00:00-4000)

Response  200
Headers
Content-Type: text/csv
Body
ConId,Date,Close
1715006,2017-01-27,48.65
1715006,2017-01-30,47.67
1715006,2017-01-31,48.97
1715006,2017-02-01,49.26

Load Historical Data
PATCH/history/{code}.{filetype}

Load market data from a CSV file into a history database.

Example URI

PATCH http://houston:1969/history/japan-bank-eod.csv
URI Parameters
code
str (required) Example: japan-bank-eod

the database code to load into

filetype
str (required) Example: csv

input format

Choices: csv

Request
Headers
Content-Type: text/csv
Body
ConId,Date,Close
1715006,2017-01-27,48.65
1715006,2017-01-30,47.67
1715006,2017-01-31,48.97
1715006,2017-02-01,49.26
Response  200
Headers
Content-Type: application/json
Body
{
  "db": "japan-bank",
  "loaded": 456
}

houston

API gateway

QuantRocket Houston API Gateway CLI

usage: quantrocket houston [-h] {ping} ...
Sub-commands:
ping

ping houston

usage: quantrocket houston ping [-h]
class quantrocket.houston.Houston

Subclass of requests.Session that provides an interface to the houston API gateway. Reads HOUSTON_URL (and Basic Auth credentials if applicable) from environment variables and applies them to each request. Simply provide the path, starting with /, for example:

>>> response = houston.get("/countdown/crontab")

Since each instance of Houston is a session, you can improve performance by using a single session for all requests. The module provides an instance of Houston, named houston.

Use the same session as other requests:

>>> from quantrocket.houston import houston

Use a new session:

>>> from quantrocket.houston import Houston
>>> houston = Houston()
quantrocket.houston.ping()

Pings houston.

Returns:

json

reply from houston

 

Houston API

Houston

Only the ping endpoint and generic proxy endpoints are documented below. For service-specific endpoints, see the respective service documentation.

Ping

Ping
GET/ping

Ping houston to test connectivity.

Example URI

GET http://houston:1969/ping
Response  200
Headers
Content-Type: application/json
Body
{
  "msg": "hello from houston"
}

HTTP Proxy

HTTP Proxy
GET/proxy/http/{service_name}/{port}/{path}

Use houston as a reverse proxy to a destination service speaking HTTP. Only GET is shown but the same signature applies for any HTTP method.

Example URI

GET http://houston:1969/proxy/http/myservice/80/my/endpoint
URI Parameters
service_name
str (required) Example: myservice

the destination service name/host name

port
int (required) Example: 80

the destination port

path
str (required) Example: my/endpoint

the request path on the destination host

uWSGI Proxy

uWSGI Proxy
GET/proxy/uwsgi/{service_name}/{port}/{path}

Use houston as a reverse proxy to a destination service speaking the uWSGI protocol. Only GET is shown but the same signature applies for any HTTP method.

Example URI

GET http://houston:1969/proxy/uwsgi/myservice/80/my/endpoint
URI Parameters
service_name
str (required) Example: myservice

the destination service name/host name

port
int (required) Example: 80

the destination port

path
str (required) Example: my/endpoint

the request path on the destination host

launchpad

IB Gateway service

QuantRocket IB Gateway service CLI

usage: quantrocket launchpad [-h] {status,start,stop,config} ...
Sub-commands:
status

query statuses of IB Gateway services

usage: quantrocket launchpad status [-h] [-e [EXCHANGE [EXCHANGE ...]]]
                                    [-t SEC_TYPE] [-r [VENDOR [VENDOR ...]]]
                                    [-s {running,stopped,error}]
                                    [-g [SERVICE_NAME [SERVICE_NAME ...]]]
Options:
-e, --exchanges
 limit to IB Gateway services with market data permission for these exchanges
-t, --sec-type

limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: %(choices)s

Possible choices: STK, FUT, CASH, OPT, IND

-r, --research

limit to IB Gateway services with permission for these research vendors. Possible choices: %(choices)s

Possible choices: reuters, wsh

-s, --status

limit to IB Gateway services in this status. Possible choices: %(choices)s

Possible choices: running, stopped, error

-g, --gateways limit to these IB Gateway services
start

start one or more IB Gateway services

usage: quantrocket launchpad start [-h] [-e [EXCHANGE [EXCHANGE ...]]]
                                   [-t SEC_TYPE] [-r [VENDOR [VENDOR ...]]]
                                   [-g [SERVICE_NAME [SERVICE_NAME ...]]] [-w]
Options:
-e, --exchanges
 limit to IB Gateway services with market data permission for these exchanges
-t, --sec-type

limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: %(choices)s

Possible choices: STK, FUT, CASH, OPT, IND

-r, --research

limit to IB Gateway services with permission for these research vendors. Possible choices: %(choices)s

Possible choices: reuters, wsh

-g, --gateways limit to these IB Gateway services
-w=False, --wait=False
 wait for the IB Gateway services to start before returning (default is to start the gateways asynchronously)
stop

stop one or more IB Gateway service

usage: quantrocket launchpad stop [-h] [-e [EXCHANGE [EXCHANGE ...]]]
                                  [-t SEC_TYPE] [-r [VENDOR [VENDOR ...]]]
                                  [-g [SERVICE_NAME [SERVICE_NAME ...]]] [-w]
Options:
-e, --exchanges
 limit to IB Gateway services with market data permission for these exchanges
-t, --sec-type

limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: %(choices)s

Possible choices: STK, FUT, CASH, OPT, IND

-r, --research

limit to IB Gateway services with permission for these research vendors. Possible choices: %(choices)s

Possible choices: reuters, wsh

-g, --gateways limit to these IB Gateway services
-w=False, --wait=False
 wait for the IB Gateway services to stop before returning (default is to stop the gateways asynchronously)
config

upload a new config, or return the current configuration

usage: quantrocket launchpad config [-h] [FILENAME]
Positional arguments:
filename the config file to upload (if omitted, return the current config)
quantrocket.launchpad.get_launchpad_config()

Returns the current config.

Returns:

dict

the config as a dict

quantrocket.launchpad.list_gateway_statuses(exchanges=None, sec_type=None, research_vendors=None, status=None, gateways=None)

Query statuses of IB Gateway services.

Parameters:

exchanges : list of str, optional

limit to IB Gateway services with market data permission for these exchanges

sec_type : str, optional

limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: STK, FUT, CASH, OPT

research_vendors : list of str, optional

limit to IB Gateway services with permission for these research vendors (choices: reuters, wsh)

status : str, optional

limit to IB Gateway services in this status. Possible choices: running, stopped, error

gateways : list of str, optional

limit to these IB Gateway services

Returns:

dict of gateway:status (if status arg not provided), or list of gateways (if status arg provided)

quantrocket.launchpad.load_launchpad_config(filename)

Uploads a new config.

Parameters:

filename : str, required

the config file to upload to the launchpad service

Returns:

dict

status message

quantrocket.launchpad.start_gateways(exchanges=None, sec_type=None, research_vendors=None, gateways=None, wait=False)

Start one or more IB Gateway services.

Parameters:

exchanges : list of str, optional

limit to IB Gateway services with market data permission for these exchanges

sec_type : str, optional

limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: STK, FUT, CASH, OPT

research_vendors : list of str, optional

limit to IB Gateway services with permission for these research vendors (choices: reuters, wsh)

gateways : list of str, optional

limit to these IB Gateway services

wait: bool

wait for the IB Gateway services to start before returning (default is to start the gateways asynchronously)

Returns:

dict

status message

quantrocket.launchpad.stop_gateways(exchanges=None, sec_type=None, research_vendors=None, gateways=None, wait=False)

Stop one or more IB Gateway services.

Parameters:

exchanges : list of str, optional

limit to IB Gateway services with market data permission for these exchanges

sec_type : str, optional

limit to IB Gateway services with market data permission for this securitiy type (useful for disambiguating permissions for exchanges that trade multiple asset classes). Possible choices: STK, FUT, CASH, OPT

research_vendors : list of str, optional

limit to IB Gateway services with permission for these research vendors (choices: reuters, wsh)

gateways : list of str, optional

limit to these IB Gateway services

wait: bool

wait for the IB Gateway services to stop before returning (default is to stop the gateways asynchronously)

Returns:

dict

status message

 

IBG Launchpad API

Launchpad

IBG Launchpad

List Gateways
GET/launchpad/gateways{?exchanges,sec_type,research_vendors,statuses,gateways}

List statuses and permissions of IB Gateway services

Example URI

GET http://houston:1969/launchpad/gateways?exchanges=NYSE&sec_type=STK&research_vendors=reuters&statuses=running&gateways=
URI Parameters
exchanges
str (optional) Example: NYSE

limit to IB Gateway services with market data permission for these exchanges (pass multiple times for multiple exchanges)

sec_type
str (optional) Example: STK

limit to IB Gateway services with market data permission for these securitiy types (useful for disambiguating permissions for exchanges that trade multiple asset classes)

research_vendors
str (optional) Example: reuters

limit to IB Gateway services with permission for these research vendors (pass multiple times for multiple vendors)

statuses
str (optional) Example: running

limit to IB Gateway services in this status (pass multiple times for multiple statuses)

Choices: running stopped error

gateways
str (optional) 

limit to these IB Gateway services (pass multiple times for multiple gateways)

Response  200
Headers
Content-Type: application/json
Body
{
  "ibg1": "running",
  "ibg2": "stopped"
}

Start Gateways
POST/launchpad/gateways{?exchanges,sec_type,research_vendors,gateways,wait}

Start IB Gateway services

Example URI

POST http://houston:1969/launchpad/gateways?exchanges=NYSE&sec_type=STK&research_vendors=reuters&gateways=&wait=true
URI Parameters
exchanges
str (optional) Example: NYSE

limit to IB Gateway services with market data permission for these exchanges (pass multiple times for multiple exchanges)

sec_type
str (optional) Example: STK

limit to IB Gateway services with market data permission for these securitiy types (useful for disambiguating permissions for exchanges that trade multiple asset classes)

research_vendors
str (optional) Example: reuters

limit to IB Gateway services with permission for these research vendors (pass multiple times for multiple vendors)

gateways
str (optional) 

limit to these IB Gateway services (pass multiple times for multiple gateways)

wait
bool (required) Example: true

wait for the IB Gateway services to start before returning (default is to start the gateways asynchronously)

Response  200
Headers
Content-Type: application/json
Body
{
  "ibg1": {
    "status": "running"
  },
  "ibg2": {
    "status": "running"
  }
}

Stop Gateways
DELETE/launchpad/gateways{?exchanges,sec_type,research_vendors,gateways,wait}

Stop IB Gateway services

Example URI

DELETE http://houston:1969/launchpad/gateways?exchanges=&sec_type=&research_vendors=reuters&gateways=ibg1&wait=true
URI Parameters
exchanges
str (optional) 

limit to IB Gateway services with market data permission for these exchanges (pass multiple times for multiple exchanges)

sec_type
str (optional) 

limit to IB Gateway services with market data permission for these securitiy types (useful for disambiguating permissions for exchanges that trade multiple asset classes)

research_vendors
str (optional) Example: reuters

limit to IB Gateway services with permission for these research vendors (pass multiple times for multiple vendors)

gateways
str (optional) Example: ibg1

limit to these IB Gateway services (pass multiple times for multiple gateways)

wait
bool (required) Example: true

wait for the IB Gateway services to stop before returning (default is to stop the gateways asynchronously)

Response  200
Headers
Content-Type: application/json
Body
{
  "ibg1": {
    "status": "stopped"
  },
  "ibg2": {
    "status": "stopped"
  }
}

IBG Launchpad Config

Get Config
GET/launchpad/config

Returns permission config of IB Gateway services

Example URI

GET http://houston:1969/launchpad/config
Response  200
Headers
Content-Type: application/json
Body
{
  "ibg1": {
    "marketdata": {
      "STK": [
        "ASX",
        "ISLAND",
        "NYSE",
        "TSE"
      ]
    },
    "research": [
      "reuters",
      "wsh"
    ],
    "max_tickers": 500
  },
  "ibg2": {
    "marketdata": {
      "STK": [
        "ISLAND",
        "NYSE"
      ],
      "FUT": [
        "GLOBEX"
      ]
    },
    "max_tickers": 100
  }
}

Load Config
PUT/launchpad/config

Uploads a new config.

Example URI

PUT http://houston:1969/launchpad/config
Request
Headers
Content-Type: application/x-yaml
Body
ibg1:
  marketdata:
    STK:
      \- ASX
      \- ISLAND
      \- NYSE
      \- TSE
  max_tickers: 300
ibg2:
  marketdata:
    STK:
      \- ISLAND
      \- TSEJ
  max_tickers: 200
Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the config will be loaded asynchronously"
}

VNC

Connect to IB Gateway GUI
GET/{gateway}/vnc

Open a VNC connection to view and control the IB Gateway GUI. Requires a modern browser with HTML5, JavaScript, and WebSockets support. (This is a convenience endpoint which redirects to another page which opens the VNC connection.)

Example URI

GET http://houston:1969/ibg1/vnc
URI Parameters
gateway
str (required) Example: ibg1

the name of the IB Gateway service to connect to

Response  301

master

securities master service

QuantRocket securities master CLI

usage: quantrocket master [-h]
                          {exchanges,listings,options,get,diff,list-universes,universe,delete-universe,rollrules,delist}
                          ...
Sub-commands:
exchanges

list exchanges by security type and country as found on the IB website

usage: quantrocket master exchanges [-h] [-r [REGION [REGION ...]]]
                                    [-t [SEC_TYPE [SEC_TYPE ...]]]
Options:
-r, --regions

limit to these regions. Possible choices: %(choices)s

Possible choices: north_america, europe, asia, global

-t, --sec-types
 

limit to these security types. Possible choices: %(choices)s

Possible choices: STK, ETF, FUT, CASH, IND

listings

fetch securities listings from IB into securities master database, either by exchange or by universes/conids

usage: quantrocket master listings [-h] [-e EXCHANGE]
                                   [-t [SEC_TYPE [SEC_TYPE ...]]]
                                   [-c [CURRENCY [CURRENCY ...]]]
                                   [-s [SYMBOL [SYMBOL ...]]]
                                   [-u [UNIVERSE [UNIVERSE ...]]]
                                   [-i [CONID [CONID ...]]]
Options:
-e, --exchange the exchange code to fetch listings for (required unless providing universes or conids)
-t, --sec-types
 

limit to these security types. Possible choices: %(choices)s

Possible choices: STK, ETF, FUT, CASH, IND

-c, --currencies
 limit to these currencies
-s, --symbols limit to these symbols
-u, --universes
 limit to these universes
-i, --conids limit to these conids
options

fetch option chains for underlying securities

usage: quantrocket master options [-h] [-u [UNIVERSE [UNIVERSE ...]]]
                                  [-i [CONID [CONID ...]]] [-f INFILE]
Options:
-u, --universes
 fetch options for these universes of underlying securities
-i, --conids fetch options for these underlying conids
-f, --infile fetch options for the conids in this file (specify ‘-‘ to read file from stdin)
get

query security details from the securities master database and download to file

usage: quantrocket master get [-h] [-e [EXCHANGE [EXCHANGE ...]]]
                              [-t [SEC_TYPE [SEC_TYPE ...]]]
                              [-c [CURRENCY [CURRENCY ...]]]
                              [-u [UNIVERSE [UNIVERSE ...]]]
                              [-s [SYMBOL [SYMBOL ...]]]
                              [-i [CONID [CONID ...]]]
                              [--exclude-universes [UNIVERSE [UNIVERSE ...]]]
                              [--exclude-conids [CONID [CONID ...]]]
                              [--sectors [SECTOR [SECTOR ...]]]
                              [--industries [INDUSTRY [INDUSTRY ...]]]
                              [--categories [CATEGORY [CATEGORY ...]]] [-d]
                              [-m] [-o OUTFILE] [-j | -p]
                              [-f [FIELD [FIELD ...]]]
Options:
-e, --exchanges
 limit to these exchanges
-t, --sec-types
 

limit to these security types. Possible choices: %(choices)s

Possible choices: STK, ETF, FUT, CASH, IND, OPT, FOP

-c, --currencies
 limit to these currencies
-u, --universes
 limit to these universes
-s, --symbols limit to these symbols
-i, --conids limit to these conids
--exclude-universes
 exclude these universes
--exclude-conids
 exclude these conids
--sectors limit to these sectors
--industries limit to these industries
--categories limit to these categories
-d=False, --delisted=False
 include delisted securities
-m=False, --frontmonth=False
 exclude backmonth and expired futures contracts
-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
-p, --pretty format output in human-readable format (default is CSV)
-f, --fields only return these fields
diff

flag security details that have changed in IB’s system since the time they were last loaded into the securities master database

usage: quantrocket master diff [-h] [-u [UNIVERSE [UNIVERSE ...]]]
                               [-i [CONID [CONID ...]]] [-n INFILE]
                               [-f [FIELD [FIELD ...]]] [--delist-missing]
                               [--delist-exchanges [EXCHANGE [EXCHANGE ...]]]
                               [-w]
Options:
-u, --universes
 limit to these universes
-i, --conids limit to these conids
-n, --infile limit to the conids in this file (specify ‘-‘ to read file from stdin)
-f, --fields only diff these fields
--delist-missing=False
 auto-delist securities that are no longer available from IB
--delist-exchanges
 auto-delist securities that are associated with these exchanges
-w=False, --wait=False
 run the diff synchronously and return the diff (otherwise run asynchronously and log the results, if any, to flightlog
list-universes

list universes and their size

usage: quantrocket master list-universes [-h]
universe

create a universe of securities

usage: quantrocket master universe [-h] [-f INFILE]
                                   [--from-universes [UNIVERSE [UNIVERSE ...]]]
                                   [--exclude-delisted] [-a | -r]
                                   CODE
Positional arguments:
code the code to assign to the universe (lowercase alphanumerics and hyphens only)
Options:
-f, --infile create the universe from the conids in this file (specify ‘-‘ to read file from stdin)
--from-universes
 create the universe from these existing universes
--exclude-delisted=False
 exclude delisted securities that would otherwise be included (default is to include them)
-a=False, --append=False
 append to universe if universe already exists
-r=False, --replace=False
 replace universe if universe already exists
delete-universe

delete a universe (the listings details of the member securities won’t be deleted, only their grouping as a universe)

usage: quantrocket master delete-universe [-h] code
Positional arguments:
code the universe code
rollrules

upload a new rollover rules config, or return the current rollover rules

usage: quantrocket master rollrules [-h] [FILENAME]
Positional arguments:
filename the rollover rules YAML config file to upload (if omitted, return the current config)
delist

mark a security as delisted

usage: quantrocket master delist [-h] [-i CONID] [-s SYMBOL] [-e EXCHANGE]
                                 [-c CURRENCY] [-t SEC_TYPE]
Options:
-i, --conid the conid of the security to be delisted
-s, --symbol the symbol to be delisted (if conid not provided)
-e, --exchange the exchange of the security to be delisted (if needed to disambiguate)
-c, --currency the currency of the security to be delisted (if needed to disambiguate)
-t, --sec-type

the security type of the security to be delisted (if needed to disambiguate). Possible choices: %(choices)s

Possible choices: STK, ETF, FUT, CASH, IND

quantrocket.master.create_universe(code, infilepath_or_buffer=None, from_universes=None, exclude_delisted=False, append=False, replace=False)

Create a universe of securities.

Parameters:

code : str, required

the code to assign to the universe (lowercase alphanumerics and hyphens only)

infilepath_or_buffer : str or file-like object, optional

create the universe from the conids in this file (specify ‘-‘ to read file from stdin)

from_universes : list of str, optional

create the universe from these existing universes

exclude_delisted : bool

exclude delisted securities that would otherwise be included (default is not to exclude them)

append : bool

append to universe if universe already exists (default False)

replace : bool

replace universe if universe already exists (default False)

Returns:

dict

status message

quantrocket.master.delete_universe(code)

Delete a universe. (The listings details of the member securities won’t be deleted, only their grouping as a universe).

Parameters:

code : str, required

the universe code

Returns:

dict

status message

quantrocket.master.delist_security(conid=None, symbol=None, exchange=None, currency=None, sec_type=None)

Mark a security as delisted.

The security can be specified by conid or a combination of other parameters (for example, symbol + exchange). As a precaution, the request will fail if the parameters match more than one security.

Parameters:

conid : int, optional

the conid of the security to be delisted

symbol : str, optional

the symbol to be delisted (if conid not provided)

exchange : str, optional

the exchange of the security to be delisted (if needed to disambiguate)

currency : str, optional

the currency of the security to be delisted (if needed to disambiguate)

sec_type : str, optional

the security type of the security to be delisted (if needed to disambiguate). Possible choices: STK, ETF, FUT, CASH, IND

Returns:

dict

status message

quantrocket.master.diff_securities(universes=None, conids=None, infilepath_or_buffer=None, fields=None, delist_missing=False, delist_exchanges=None, wait=False)

Flag security details that have changed in IB’s system since the time they were last loaded into the securities master database.

Diff can be run synchronously or asynchronously (asynchronous is the default and is recommended if diffing more than a handful of securities).

Parameters:

universes : list of str, optional

limit to these universes

conids : list of int, optional

limit to these conids

infilepath_or_buffer : str or file-like object, optional

limit to the conids in this file (specify ‘-‘ to read file from stdin)

fields : list of str, optional

only diff these fields

delist_missing : bool

auto-delist securities that are no longer available from IB

delist_exchanges : list of str, optional

auto-delist securities that are associated with these exchanges

wait : bool

run the diff synchronously and return the diff (otherwise run asynchronously and log the results, if any, to flightlog)

Returns:

dict

dict of conids and fields that have changed (if wait), or status message

quantrocket.master.download_master_file(filepath_or_buffer=None, output='csv', exchanges=None, sec_types=None, currencies=None, universes=None, symbols=None, conids=None, exclude_universes=None, exclude_conids=None, sectors=None, industries=None, categories=None, delisted=False, frontmonth=False, fields=None)

Query security details from the securities master database and download to file.

Parameters:

filepath_or_buffer : str or file-like object

filepath to write the data to, or file-like object (defaults to stdout)

output : str

output format (json, csv, txt, default is csv)

exchanges : list of str, optional

limit to these exchanges

sec_types : list of str, optional

limit to these security types. Possible choices: STK, ETF, FUT, CASH, IND, OPT, FOP

currencies : list of str, optional

limit to these currencies

universes : list of str, optional

limit to these universes

symbols : list of str, optional

limit to these symbols

conids : list of int, optional

limit to these conids

exclude_universes : list of str, optional

exclude these universes

exclude_conids : list of int, optional

exclude these conids

sectors : list of str, optional

limit to these sectors

industries : list of str, optional

limit to these industries

categories : list of str, optional

limit to these categories

delisted : bool

include delisted securities (default False)

frontmonth : bool

exclude backmonth and expired futures contracts (default False)

fields : list of str, optional

only return these fields

Returns:

None

Examples

You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_master_file(f, universes=["my-universe"])
>>> securities = pd.read_csv(f)
quantrocket.master.fetch_listings(exchange=None, sec_types=None, currencies=None, symbols=None, universes=None, conids=None)

Fetch securities listings from IB into securities master database, either by exchange or by universes/conids.

Specify an exchange (optionally filtering by security type, currency, and/or symbol) to fetch listings from the IB website and fetch associated contract details from the IB API. Or, specify universes or conids to fetch details from the IB API, bypassing the website.

Parameters:

exchange : str

the exchange code to fetch listings for (required unless providing universes or conids)

sec_types : list of str, optional

limit to these security types. Possible choices: STK, ETF, FUT, CASH, IND

currencies : list of str, optional

limit to these currencies

symbols : list of str, optional

limit to these symbols

universes : list of str, optional

limit to these universes

conids : list of int, optional

limit to these conids

Returns:

dict

status message

quantrocket.master.fetch_option_chains(universes=None, conids=None, infilepath_or_buffer=None)

Fetch option chains for underlying securities.

Note: option chains often consist of hundreds, sometimes thousands of options per underlying security. Be aware that requesting option chains for large universes of underlying securities, such as all stocks on the NYSE, can take numerous hours to complete, add hundreds of thousands of rows to the securities master database, increase the database file size by several hundred megabytes, and potentially add latency to database queries.

Parameters:

universes : list of str, optional

fetch options for these universes of underlying securities

conids : list of int, optional

fetch options for these underlying conids

infilepath_or_buffer : str or file-like object, optional

fetch options for the conids in this file (specify ‘-‘ to read file from stdin)

Returns:

dict

status message

quantrocket.master.get_rollrules_config()

Returns the current rollover rules config.

Returns:

dict

the config as a dict

quantrocket.master.list_exchanges(regions=None, sec_types=None)

List exchanges by security type and country as found on the IB website.

Parameters:

regions : list of str, optional

limit to these regions. Possible choices: north_america, europe, asia, global

sec_types : list of str, optional

limit to these securitiy types. Possible choices: STK, ETF, FUT, CASH, IND

Returns:

dict

quantrocket.master.list_universes()

List universes and their size.

Returns:

dict

dict of universe:size

quantrocket.master.load_rollrules_config(filename)

Upload a new rollover rules config.

Parameters:

filename : str, required

the rollover rules YAML config file to upload

Returns:

dict

status message

 

Securities Master API

Securities Master

Exchanges

List Exchanges
GET/master/exchanges{?regions,sec_types}

List exchanges by security type and country as found on the IB website

Example URI

GET http://houston:1969/master/exchanges?regions=asia&sec_types=STK
URI Parameters
regions
str (optional) Example: asia

limit to these regions (pass multiple times for multiple regions)

Choices: north_america europe asia global

sec_types
str (optional) Example: STK

limit to these security types (pass multiple times for multiple security types)

Choices: STK ETF FUT CASH IND

Response  200
Headers
Content-Type: application/json
Body
{
  "STK": {
    "Australia": [
      "ASX",
      "CHIXAU"
    ],
    "Hong Kong": [
      "SEHK",
      "SEHKNTL",
      "SEHKSZSE"
    ],
    "India": [
      "NSE"
    ],
    "Japan": [
      "CHIXJ",
      "JPNNEXT",
      "TSEJ"
    ],
    "Singapore": [
      "SGX"
    ]
  }
}

Listings

Fetch Listings
POST/master/listings{?exchange,sec_types,currencies,symbols,universes,conids}

Fetch securities listings from IB into securities master database, either by exchange or by universes/conids.

Specify an exchange (optionally filtering by security type, currency, and/or symbol) to fetch listings from the IB website and fetch associated contract details from the IB API. Or, specify universes or conids to fetch details from the IB API, bypassing the website.

Example URI

POST http://houston:1969/master/listings?exchange=NYSE&sec_types=STK&currencies=USD&symbols=LVS&universes=my-universe&conids=123456
URI Parameters
exchange
str (optional) Example: NYSE

the exchange code to fetch listings for (required unless providing universes or conids)

sec_types
str (optional) Example: STK

limit to these security types (pass multiple times for multiple security types)

Choices: STK ETF FUT CASH IND

currencies
str (optional) Example: USD

limit to these currencies (pass multiple times for multiple currencies)

symbols
str (optional) Example: LVS

limit to these symbols (pass multiple times for multiple symbols)

universes
str (optional) Example: my-universe

limit to these universes (pass multiple times for multiple universes)

conids
int (optional) Example: 123456

limit to these conids (pass multiple times for multiple conids)

Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the listing details will be fetched asynchronously"
}

Options

Fetch Option Chains
POST/master/options{?universes,conids}

Fetch option chains for underlying securities. Specify conids or universes or upload a CSV of conids as the request body.

Note: option chains often consist of hundreds, sometimes thousands of options per underlying security. Be aware that requesting option chains for large universes of underlying securities, such as all stocks on the NYSE, can take numerous hours to complete, add hundreds of thousands of rows to the securities master database, increase the database file size by several hundred megabytes, and potentially add latency to database queries.

Example URI

POST http://houston:1969/master/options?universes=my-universe&conids=123456
URI Parameters
universes
str (optional) Example: my-universe

fetch options for these universes of underlying securities (pass multiple times for multiple universes)

conids
int (optional) Example: 123456

fetch options for these underlying conids (pass multiple times for multiple conids)

Request
Headers
Content-Type: text/csv
Body
ConId,OtherField,OtherField2
123456,other,fields
234567,will,be
345678,ignored,
Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the option chains will be fetched asynchronously"
}

Diff

Diff Securities
GET/master/diff{?universes,conids,fields,delist_missing,delist_exchanges,wait}

Flag security details that have changed in IB’s system since the time they were last loaded into the securities master database. Specify conids or universes or upload a CSV of conids as the request body. Can be run synchronously or asynchronously (asynchronous is the default and is recommended if diffing more than a handful of securities).

Example URI

GET http://houston:1969/master/diff?universes=my-universe&conids=123456&fields=PrimaryExchange&delist_missing=true&delist_exchanges=PINK&wait=true
URI Parameters
universes
str (optional) Example: my-universe

limit to these universes (pass multiple times for multiple universes)

conids
int (optional) Example: 123456

limit to these conids (pass multiple times for multiple conids)

fields
str (optional) Example: PrimaryExchange

only diff these fields (pass multiple times for multiple fields)

delist_missing
bool (optional) Example: true

auto-delist securities that are no longer available from IB

delist_exchanges
str (optional) Example: PINK

auto-delist securities that are associated with these exchanges

wait
bool (optional) Example: true

run the diff synchronously and return the diff (otherwise run asynchronously and log the results, if any, to flightlog)

Request
Headers
Content-Type: text/csv
Body
ConId,OtherField,OtherField2
123456,other,fields
234567,will,be
345678,ignored,
Response  200
Headers
Content-Type: application/json
Body
{
  "security_diffs": [
    {
      "as_stored_in_db": {
        "Symbol": "ABC",
        "Currency": "USD",
        "SecType": "STK",
        "PrimaryExchange": "NYSE",
        "ConId": 123456
      },
      "changes_in_ib": {
        "PrimaryExchange": {
          "new": "PINK",
          "old": "NYSE"
        }
      }
    }
  ]
}
Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the diff, if any, will be logged to flightlog asynchronously"
}

Securities Files

Download Securities File
GET/master/securities.{output}{?exchanges,sec_types,currencies,symbols,universes,conids,exclude_universes,exclude_conids,sectors,industries,categories,delisted,frontmonth}

Query security details from the securities master database and download to file.

Example URI

GET http://houston:1969/master/securities.csv?exchanges=NYSE&sec_types=STK&currencies=USD&symbols=LVS&universes=my-universe&conids=123456&exclude_universes=another-universe&exclude_conids=234567&sectors=Basic Materials&industries=Mining&categories=Diversified Minerals&delisted=false&frontmonth=false
URI Parameters
output
str (required) Example: csv

output format

Choices: csv json

exchanges
str (optional) Example: NYSE

limit to these exchanges (pass multiple times for multiple exchanges)

sec_types
str (optional) Example: STK

limit to these security types (pass multiple times for multiple security types)

Choices: STK ETF FUT CASH IND OPT FOP

currencies
str (optional) Example: USD

limit to these currencies (pass multiple times for multiple currencies)

symbols
str (optional) Example: LVS

limit to these symbols (pass multiple times for multiple symbols)

universes
str (optional) Example: my-universe

limit to these universes (pass multiple times for multiple universes)

conids
int (optional) Example: 123456

limit to these conids (pass multiple times for multiple conids)

exclude_universes
str (optional) Example: another-universe

exclude these universes (pass multiple times for multiple universes)

exclude_conids
int (optional) Example: 234567

exclude these conids (pass multiple times for multiple conids)

sectors
str (optional) Example: Basic Materials

limit to these sectors (pass multiple times for multiple sectors)

industries
str (optional) Example: Mining

limit to these industries (pass multiple times for multiple industries)

categories
str (optional) Example: Diversified Minerals

limit to these categories (pass multiple times for multiple categories)

delisted
bool (required) Example: false

include delisted securities (default false)

frontmonth
bool (required) Example: false

exclude backmonth and expired futures contracts (default False)

Response  200
Headers
Content-Type: text/csv
Body
279016041,NSC,FUT,0,ONE,USD,NSC3MM7,NSC3M,NSC3M,"NORFOLK SOUTHERN CORP",EST,Industrial,Transportation,Transport-Rail,0.01,1,1,20170619,201706,100,,0
279016083,NUS,FUT,0,ONE,USD,NUS3MM7,NUS3M,NUS3M,"NU SKIN ENTERPRISES INC - A",EST,"Consumer, Cyclical",Retail,"Multilevel Dir Selling",0.01,1,1,20170619,201706,100,,0
279016106,O,FUT,0,ONE,USD,O3MM7,O3M,O3M,"REALTY INCOME CORP",EST,Financial,REITS,"REITS-Single Tenant",0.01,1,1,20170619,201706,100,,0

Securities

Delist Security
DELETE/master/securities{?exchanges,sec_types,currencies,symbols,conids}

Mark a security as delisted.

The security can be specified by conid or a combination of other parameters (for example, symbol + exchange). As a precaution, the request will fail if the parameters match more than one security.

Example URI

DELETE http://houston:1969/master/securities?exchanges=NYSE&sec_types=STK&currencies=USD&symbols=ABC&conids=123456
URI Parameters
conids
int (optional) Example: 123456

the conid of the security to be delisted

symbols
str (optional) Example: ABC

the symbol to be delisted (if conid not provided)

exchanges
str (optional) Example: NYSE

the exchange of the security to be delisted (if needed to disambiguate)

sec_types
str (optional) Example: STK

the security type of the security to be delisted (if needed to disambiguate)

Choices: STK ETF FUT CASH IND

currencies
str (optional) Example: USD

the currency of the security to be delisted (if needed to disambiguate)

Response  200
Headers
Content-Type: application/json
Body
{
  "msg": "delisted conid 123456"
}

Universes

List Universes
GET/master/universes

List universes and their size.

Example URI

GET http://houston:1969/master/universes
Response  200
Headers
Content-Type: application/json
Body
{
  "jpn-fut": 196,
  "fx": 98,
  "arca-etf": 1514,
  "asx-stk": 2313
}

Universes

Create Universe
PUT/master/universes/{code}{?from_universes,exclude_delisted,replace}

Create a universe of securities, either from existing universes and/or from a CSV containing conids and uploaded as the request body.

Example URI

PUT http://houston:1969/master/universes/arca-etf?from_universes=&exclude_delisted=true&replace=true
URI Parameters
code
str (required) Example: arca-etf

the code to assign to the universe (lowercase alphanumerics and hyphens only)

from_universes
str (optional) 

create the universe from these existing universes (pass multiple times for multiple existing universes)

exclude_delisted
bool (required) Example: true

exclude delisted securities that would otherwise be included (default is not to exclude them)

replace
bool (required) Example: true

replace universe if universe already exists (default is to fail if universe already exists)

Request
Headers
Content-Type: text/csv
Body
ConId,OtherField,OtherField2
123456,other,fields
234567,will,be
345678,ignored,
Response  200
Headers
Content-Type: application/json
Body
{
  "code": "arca-etf",
  "provided": 1514,
  "inserted": 1514,
  "total_after_insert": 1514
}

Append to Universe
PATCH/master/universes/{code}{?from_universes,exclude_delisted}

Append to a universe of securities, either from existing universes and/or from a CSV containing conids and uploaded as the request body.

Example URI

PATCH http://houston:1969/master/universes/arca-etf?from_universes=&exclude_delisted=true
URI Parameters
code
str (required) Example: arca-etf

the code to assign to the universe (lowercase alphanumerics and hyphens only)

from_universes
str (optional) 

create the universe from these existing universes (pass multiple times for multiple existing universes)

exclude_delisted
bool (required) Example: true

exclude delisted securities that would otherwise be included (default is not to exclude them)

Request
Headers
Content-Type: text/csv
Body
ConId,OtherField,OtherField2
123456,other,fields
234567,will,be
345678,ignored,
Response  200
Headers
Content-Type: application/json
Body
{
  "code": "arca-etf",
  "provided": 1534,
  "inserted": 30,
  "total_after_insert": 1534
}

Delete Universe
DELETE/master/universes/{code}

Delete a universe. (The listings details of the member securities won’t be deleted, only their grouping as a universe).

Example URI

DELETE http://houston:1969/master/universes/arca-etf
URI Parameters
code
str (required) Example: arca-etf

the universe code

Response  200
Headers
Content-Type: application/json
Body
{
  "code": "arca-etf",
  "deleted": 1534
}

Rollover Config

Get Rollover Config
GET/master/config/rollover

Returns the current rollover rules config.

Example URI

GET http://houston:1969/master/config/rollover
Response  200
Headers
Content-Type: application/json
Body
{
  "GLOBEX": {
    "ES": {
      "rollrule": {
        "days": -8
      },
      "same_for": [
        "NQ",
        "RS",
        "YM"
      ]
    },
    "HE": {
      "only_months": [
        2,
        4,
        6,
        8,
        10,
        12
      ],
      "rollrule": {
        "months": -1,
        "day": 27
      },
      "same_for": [
        "LE"
      ]
    }
  },
  "NYMEX": {
    "CL": {
      "rollrule": {
        "days": -1
      },
      "same_for": [
        "NG"
      ]
    }
  }
}

Load Rollover Config
PUT/master/config/rollover

Upload a new rollover rules config.

Example URI

PUT http://houston:1969/master/config/rollover
Request
Headers
Content-Type: application/x-yaml
Body
GLOBEX:
  ES:
    rollrule:
      days: -8
    same_for:
      `- NQ`
      `- RS`
      `- YM`
  HE:
    only_months:
      \- 2
      \- 4
      \- 6
      \- 8
      \- 10
      \- 12
    rollrule:
      months: -1
      day: 27
    same_for:
      \- LE
NYMEX:
  CL:
    rollrule:
      days: -1
    same_for:
      \- NG
Response  202
Headers
Content-Type: application/json
Body
{
  "status": "the config will be loaded asynchronously"
}

moonshot

Moonshot backtesting and trading engine

moonshot-client

Moonshot client

QuantRocket Moonshot CLI

usage: quantrocket moonshot [-h] {backtest,paramscan} ...
Sub-commands:
backtest

backtest one or more strategies

usage: quantrocket moonshot backtest [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                     [-l [CODE:FLOAT [CODE:FLOAT ...]]]
                                     [-n [CURRENCY:NLV [CURRENCY:NLV ...]]]
                                     [-p [PARAM:VALUE [PARAM:VALUE ...]]] [-d]
                                     [--csv] [-o FILEPATH]
                                     CODE [CODE ...]
Positional arguments:
strategies one or more strategy codes
Options:
-s, --start-date
 the backtest start date (default is to use all available history)
-e, --end-date the backtest end date (default is to use all available history)
-l, --allocations
 the allocation for each strategy, passed as ‘code:allocation’ (default allocation is 1.0 / number of strategies)
-n, --nlv the NLV (net liquidation value, i.e. account balance) to assume for the backtest, expressed in each currency represented in the backtest (pass as ‘currency:nlv’)
-p, --params one or more strategy params to set on the fly before backtesting (pass as ‘param:value’)
-d=False, --details=False
 return detailed results for all securities instead of aggregating to strategy level (only supported for single-strategy backtests)
--csv=False return a CSV of performance data (default is to return a PDF performance tear sheet)
-o, --outfile the location to write the results file (omit to write to stdout)
paramscan

run a parameter scan for one or more strategies

usage: quantrocket moonshot paramscan [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD] -p
                                      PARAM -v VALUE [VALUE ...]
                                      [--param2 PARAM]
                                      [--vals2 [VALUE [VALUE ...]]]
                                      [-l [CODE:FLOAT [CODE:FLOAT ...]]]
                                      [-n [CURRENCY:NLV [CURRENCY:NLV ...]]]
                                      [--params [PARAM:VALUE [PARAM:VALUE ...]]]
                                      [--csv] [-o FILEPATH]
                                      CODE [CODE ...]
Positional arguments:
strategies one or more strategy codes
Options:
-s, --start-date
 the backtest start date (default is to use all available history)
-e, --end-date the backtest end date (default is to use all available history)
-p, --param1 the name of the parameter to test (a class attribute on the strategy)
-v, --vals1 parameter values to test (values can be integers, floats, strings, ‘True’, ‘False’, ‘None’, or ‘default’ (to test current param value); for lists/tuples, use comma-separated values)
--param2 name of a second parameter to test (for 2-D parameter scans)
--vals2 values to test for parameter 2 (values can be integers, floats, strings, ‘True’, ‘False’, ‘None’, or ‘default’ (to test current param value); for lists/tuples, use comma-separated values)
-l, --allocations
 the allocation for each strategy, passed as ‘code:allocation’ (default allocation is 1.0 / number of strategies)
-n, --nlv the NLV (net liquidation value, i.e. account balance) to assume for the backtests, expressed in each currency represented in the backtest (pass as ‘currency:nlv’)
--params one or more strategy params to set on the fly before backtesting (pass as ‘param:value’)
--csv=False return a CSV of results data (default is to return a PDF tear sheet)
-o, --outfile the location to write the results file (omit to write to stdout)
quantrocket.moonshot.backtest(strategies, start_date=None, end_date=None, allocations=None, nlv=None, params=None, details=None, csv=None, filepath_or_buffer=None)

Backtest one or more strategies.

By default returns a PDF tear sheet of performance charts but can also return a CSV of backtest results.

Parameters:

strategies : list of str, required

one or more strategy codes

start_date : str (YYYY-MM-DD), optional

the backtest start date (default is to use all available history)

end_date : str (YYYY-MM-DD), optional

the backtest end date (default is to use all available history)

allocations : dict of CODE:FLOAT, optional

the allocation for each strategy, passed as {code:allocation} (default allocation is 1.0 / number of strategies)

nlv : dict of CURRENCY:NLV, optional

the NLV (net liquidation value, i.e. account balance) to assume for the backtest, expressed in each currency represented in the backtest (pass as {currency:nlv})

params : dict of PARAM:VALUE, optional

one or more strategy params to set on the fly before backtesting (pass as {param:value})

details : bool

return detailed results for all securities instead of aggregating to strategy level (only supported for single-strategy backtests)

csv : bool

return a CSV of performance data (default is to return a PDF performance tear sheet)

filepath_or_buffer : str, optional

the location to write the results file (omit to write to stdout)

Returns:

None

quantrocket.moonshot.scan_parameters(strategies, start_date=None, end_date=None, param1=None, vals1=None, param2=None, vals2=None, allocations=None, nlv=None, params=None, csv=None, filepath_or_buffer=None)

Run a parameter scan for one or more strategies.

By default returns a PDF tear sheet of results but can also return a CSV.

Parameters:

strategies : list of str, required

one or more strategy codes

start_date : str (YYYY-MM-DD), optional

the backtest start date (default is to use all available history)

end_date : str (YYYY-MM-DD), optional

the backtest end date (default is to use all available history)

param1 : str, required

the name of the parameter to test (a class attribute on the strategy)

vals1 : list of int/float/str/tuple, required

parameter values to test (values can be ints, floats, strings, False, True, None, ‘default’ (to test current param value), or lists of ints/floats/strings)

param2 : str, optional

name of a second parameter to test (for 2-D parameter scans)

vals2 : list of int/float/str/tuple, optional

values to test for parameter 2 (values can be ints, floats, strings, False, True, None, ‘default’ (to test current param value), or lists of ints/floats/strings)

allocations : dict of CODE:FLOAT, optional

the allocation for each strategy, passed as {code:allocation} (default allocation is 1.0 / number of strategies)

nlv : dict of CURRENCY:NLV, optional

the NLV (net liquidation value, i.e. account balance) to assume for the backtest, expressed in each currency represented in the backtest (pass as {currency:nlv})

params : dict of PARAM:VALUE, optional

one or more strategy params to set on the fly before backtesting (pass as {param:value})

csv : bool

return a CSV of performance data (default is to return a PDF tear sheet)

filepath_or_buffer : str, optional

the location to write the results file (omit to write to stdout)

Returns:

None

 

Moonshot API

Moonshot

Backtests

Run Backtest
POST/moonshot/backtests{?strategies,start_date,end_date,allocations,nlv,params,details,csv}

Backtest one or more strategies.

By default returns a PDF tear sheet of performance charts but can also return a CSV of backtest results.

Example URI

POST http://houston:1969/moonshot/backtests?strategies=umd-nyse&start_date=2015-02-01&end_date=2017-06-06&allocations=umd-nyse:0.25&nlv=USD:500000&params=BENCHMARK:None&details=true&csv=false
URI Parameters
strategies
str (required) Example: umd-nyse

the strategy code to test (pass multiple times for multiple strategies)

start_date
str (optional) Example: 2015-02-01

the backtest start date (default is to use all available history)

end_date
str (optional) Example: 2017-06-06

the backtest end date (default is to use all available history)

allocations
str (optional) Example: umd-nyse:0.25

the allocation for each strategy, passed as ‘code:allocation’ (default allocation is 1.0 / number of strategies) (pass multiple times for multiple strategies)

nlv
str (optional) Example: USD:500000

the NLV (net liquidation value, i.e. account balance) to assume for the backtest, expressed in each currency represented in the backtest (pass as ‘currency:nlv’) (pass multiple times for multiple currencies)

params
str (optional) Example: BENCHMARK:None

one or more strategy params to set on the fly before backtesting (pass as ‘param:value’) (pass multiple times for multiple params)

details
bool (optional) Example: true

return detailed results for all securities instead of aggregating to strategy level (only supported for single-strategy backtests)

csv
bool (optional) Example: false

return a CSV of performance data (default is to return a PDF performance tear sheet)

Response  200
Headers
Content-Type: application/pdf
Response  200
Headers
Content-Type: text/csv

Parameter Scans

Run Parameter Scan
POST/moonshot/paramscans{?strategies,start_date,end_date,param1,vals1,param2,vals2,allocations,nlv,params,csv}

Run a parameter scan for one or more strategies.

By default returns a PDF tear sheet of results but can also return a CSV.

Example URI

POST http://houston:1969/moonshot/paramscans?strategies=umd-nyse&start_date=2015-02-01&end_date=2017-06-06&param1=SMAVG_WINDOW&vals1=20&param2=LMAVG_WINDOW&vals2=180&allocations=umd-nyse:0.25&nlv=USD:500000&params=BENCHMARK:None&csv=false
URI Parameters
strategies
str (required) Example: umd-nyse

the strategy code to test (pass multiple times for multiple strategies)

start_date
str (optional) Example: 2015-02-01

the backtest start date (default is to use all available history)

end_date
str (optional) Example: 2017-06-06

the backtest end date (default is to use all available history)

param1
str (required) Example: SMAVG_WINDOW

the name of the parameter to test (a class attribute on the strategy)

vals1
str (required) Example: 20

parameter values to test (values can be ints, floats, strings, False, True, None, ‘default’ (to test current param value), or lists of ints/floats/strings) (pass multiple times for multiple values)

param2
str (optional) Example: LMAVG_WINDOW

name of a second parameter to test (for 2-D parameter scans)

vals2
str (optional) Example: 180

values to test for parameter 2 (values can be ints, floats, strings, False, True, None, ‘default’ (to test current param value), or lists of ints/floats/strings) (pass multiple times for multiple values)

allocations
str (optional) Example: umd-nyse:0.25

the allocation for each strategy, passed as ‘code:allocation’ (default allocation is 1.0 / number of strategies) (pass multiple times for multiple strategies)

nlv
str (optional) Example: USD:500000

the NLV (net liquidation value, i.e. account balance) to assume for the backtest, expressed in each currency represented in the backtest (pass as ‘currency:nlv’) (pass multiple times for multiple currencies)

params
str (optional) Example: BENCHMARK:None

one or more strategy params to set on the fly before backtesting (pass as ‘param:value’) (pass multiple times for multiple params)

details
bool (optional) Example: true

return detailed results for all securities instead of aggregating to strategy level (only supported for single-strategy backtests)

csv
bool (optional) Example: false

return a CSV of performance data (default is to return a PDF performance tear sheet)

Response  200
Headers
Content-Type: application/pdf
Response  200
Headers
Content-Type: text/csv

quandl

Quandl data service

QuantRocket Quandl data CLI

usage: quantrocket quandl [-h] {download,ns1,zep} ...
Sub-commands:
download

download a database from Quandl

usage: quantrocket quandl download [-h] DATABASE_CODE
Positional arguments:
database_code

the code of the database to download

Possible choices: ZEP, NS1

ns1

query the FinSentS News Sentiment database

usage: quantrocket quandl ns1 [-h] [-s DATE] [-e DATE]
                              [-g [GROUP [GROUP ...]]]
                              [-i [CONID [CONID ...]]]
                              [-t [TICKER [TICKER ...]]]
                              [--exclude-groups [GROUP [GROUP ...]]]
                              [--exclude-conids [CONID [CONID ...]]]
Options:
-s, --start-date
 limit to on or after this date
-e, --end-date limit to on or before this date
-g, --groups limit to these groups (will be translated to NS1 tickers)
-i, --conids limit to these IB conids (will be translated to NS1 tickers)
-t, --tickers limit to these NS1 tickers
--exclude-groups
 exclude these groups (will be translated to NS1 tickers)
--exclude-conids
 exclude these conids (will be translated to NS1 tickers)
zep

query the Zacks Equity Prices database

usage: quantrocket quandl zep [-h] [-s DATE] [-e DATE]
                              [-g [GROUP [GROUP ...]]]
                              [-i [CONID [CONID ...]]]
                              [-t [TICKER [TICKER ...]]]
                              [--exclude-groups [GROUP [GROUP ...]]]
                              [--exclude-conids [CONID [CONID ...]]]
                              [--exclude-delisted]
Options:
-s, --start-date
 limit to on or after this date
-e, --end-date limit to on or before this date
-g, --groups limit to these groups (will be translated to ZEP tickers)
-i, --conids limit to these conids (will be translated to ZEP tickers)
-t, --tickers limit to these ZEP tickers
--exclude-groups
 exclude these groups (will be translated to ZEP tickers)
--exclude-conids
 exclude these conids (will be translated to ZEP tickers)
--exclude-delisted=False
 exclude delisted tickers

realtime

Real-time market data service

QuantRocket realtime data CLI

usage: quantrocket realtime [-h] {quote,add,cancel} ...
Sub-commands:
quote

get realtime quotes for securities

usage: quantrocket realtime quote [-h] [-g [GROUP [GROUP ...]]]
                                  [-i [CONID [CONID ...]]]
                                  [--exclude-groups [GROUP [GROUP ...]]]
                                  [--exclude-conids [CONID [CONID ...]]]
                                  [-f [FIELD [FIELD ...]]] [-w HH:MM:SS] [-s]
                                  [--save DB] [--disable-backmonth-filter]
Options:
-g, --groups limit to these groups
-i, --conids limit to these IB conids
--exclude-groups
 exclude these groups
--exclude-conids
 exclude these conids
-f, --fields limit to these fields
-w, --window limit to this historical window (use Pandas timedelta string)
-s=False, --snapshot=False
 return a snapshot of the latest quotes
--save save the quotes asynchronously to the named database after returning them
--disable-backmonth-filter=False
 don’t filter out back month contracts (default is to filter out everything except front month)
add

add securities to the realtime data stream

usage: quantrocket realtime add [-h] [-g [GROUP [GROUP ...]]]
                                [-i [CONID [CONID ...]]]
                                [--exclude-groups [GROUP [GROUP ...]]]
                                [--exclude-conids [CONID [CONID ...]]]
                                [-c HH:MM:SS] [--disable-backmonth-filter]
Options:
-g, --groups limit to these groups
-i, --conids limit to these IB conids
--exclude-groups
 exclude these groups
--exclude-conids
 exclude these conids
-c, --cancel-in
 automatically cancel the securities after this much time (use Pandas timedelta string)
--disable-backmonth-filter=False
 don’t filter out back month contracts (default is to filter out everything except front month)
cancel

remove securities from the realtime data stream

usage: quantrocket realtime cancel [-h] [-g [GROUP [GROUP ...]]]
                                   [-i [CONID [CONID ...]]]
                                   [--exclude-groups [GROUP [GROUP ...]]]
                                   [--exclude-conids [CONID [CONID ...]]]
Options:
-g, --groups limit to these groups
-i, --conids limit to these IB conids
--exclude-groups
 exclude these groups
--exclude-conids
 exclude these conids

satellite

satellite service

QuantRocket Satellite CLI

usage: quantrocket satellite [-h] {exec} ...
Sub-commands:
exec

execute an abitrary command on a satellite service and optionally return a file

usage: quantrocket satellite exec [-h] [-r FILEPATH] [-o FILEPATH]
                                  SERVICE_NAME CMD
Positional arguments:
service the service name
cmd the command to run
Options:
-r, --return-file
 the path of a file to be returned after the command completes
-o, --outfile the location to write the return_file (omit to write to stdout)
quantrocket.satellite.execute_command(service, cmd, return_file=None, filepath_or_buffer=None)

Execute an abitrary command on a satellite service and optionally return a file.

Parameters:

service : str, required

the service name

cmd: str, required

the command to run

return_file : str, optional

the path of a file to be returned after the command completes

filepath_or_buffer : str, optional

the location to write the return_file (omit to write to stdout)

Returns:

dict or None

None if return_file, otherwise status message

 

Satellite API

Satellite

Commands

Execute Command
POST/{service}/commands{?cmd,return_file}

Execute an abitrary command on a satellite service and optionally return a file.

Example URI

POST http://houston:1969/satellite-bt/commands?cmd=python%20%2Fetc%2Fopt%2Fquantrocket%2Fquickstart.py&return_file=%2Ftmp%2Fbacktrader-plot.pdf
URI Parameters
service
str (required) Example: satellite-bt

the service name

cmd
str (required) Example: python%20%2Fetc%2Fopt%2Fquantrocket%2Fquickstart.py

the command to run

return_file
str (optional) Example: %2Ftmp%2Fbacktrader-plot.pdf

the path of a file to be returned after the command completes

Response  200
Headers
Content-Type: application/octet-stream

zipline

zipline service

QuantRocket CLI for Zipline

usage: quantrocket zipline [-h] {ingest,bundles,clean,run,tearsheet} ...
Sub-commands:
ingest

ingest a data bundle

usage: quantrocket zipline ingest [-h] [-d CODE] [-c NAME] [-b BUNDLE-NAME]
                                  [--assets-versions [INTEGER [INTEGER ...]]]
Options:
-d, --history-db
 the code of a history db to ingest
-c, --calendar the name of the calendar to use with this history db bundle (default is NYSE; provide an invalid calendar name to see available choices)
-b, --bundle the data bundle to ingest (default is quantopian-quandl); don’t provide if specifying –history-db
--assets-versions
 versions of the assets db to which to downgrade
bundles

list all of the available data bundles

usage: quantrocket zipline bundles [-h]
clean

clean up data downloaded with the ingest command

usage: quantrocket zipline clean [-h] [-b BUNDLE-NAME] [-e TIMESTAMP]
                                 [-a TIMESTAMP] [-k N]
Options:
-b, --bundle the data bundle to clean (default is quantopian-quandl)
-e, --before clear all data before TIMESTAMP. This may not be passed with -k / –keep-last
-a, --after clear all data after TIMESTAMP. This may not be passed with -k / –keep-last
-k, --keep-last
 clear all but the last N downloads. This may not be passed with -e / –before or -a / –after
run

run a Zipline backtest and write the test results to a CSV file

usage: quantrocket zipline run [-h] -f FILENAME
                               [--data-frequency {daily,minute}]
                               [--capital-base FLOAT] [-b BUNDLE-NAME]
                               [--bundle-timestamp TIMESTAMP] -s DATE -e DATE
                               [-o FILENAME] [--calendar CALENDAR]
Options:
-f, --algofile the file that contains the algorithm to run
--data-frequency
 

the data frequency of the simulation (default is daily)

Possible choices: daily, minute

--capital-base the starting capital for the simulation (default is 10000000.0)
-b, --bundle the data bundle to use for the simulation (default is quantopian-quandl)
--bundle-timestamp
 the date to lookup data on or before (default is <current-time>)
-s, --start the start date of the simulation
-e, --end the end date of the simulation
-o, --output the location to write the output file (omit to write to stdout)
--calendar the calendar you want to use e.g. LSE (default is to use the calendar associated with the data bundle)
tearsheet

create a pyfolio tear sheet from a Zipline backtest result

usage: quantrocket zipline tearsheet [-h] -o FILENAME [-s] [-l YYYY-MM-DD]
                                     [--slippage INT] [--hide-positions]
                                     [--bayesian] [--round-trips]
                                     [--bootstrap]
                                     [FILENAME]
Positional arguments:
infilepath_or_buffer
 the CSV file from a Zipline backtest (omit to read file from stdin)
Options:
-o, --output the location to write the pyfolio tear sheet
-s=False, --simple=False
 create a simple tear sheet (default is to create a full tear sheet)
-l, --live-start-date
 date when the strategy began live trading
--slippage basis points of slippage to apply to returns before generating tear sheet stats and plots
--hide-positions=False
 don’t output any symbol names
--bayesian=False
 include a Bayesian tear sheet
--round-trips=False
 include a round-trips tear sheet
--bootstrap=False
 perform bootstrap analysis for the performance metrics (takes a few minutes longer)
class quantrocket.zipline.ZiplineBacktestResult

Convenience class for parsing a CSV result file from a Zipline backtest into a variety of useful DataFrames, which can be passed to pyfolio or inspected by the user.

Examples

Run a Zipline backtest and parse the CSV results:

>>> f = io.StringIO()
>>> run_algorithm("momentum_pipeline.py",
          bundle="etf-sampler-1d",
          start="2015-02-04",
          end="2015-12-31",
          filepath_or_buffer=f)
>>> zipline_result = ZiplineBacktestResult.from_csv(f)

The ZiplineBacktestResult object contains returns, positions, transactions, benchmark_returns, and the performance DataFrame.

>>> print(zipline_result.returns.head())
>>> print(zipline_result.positions.head())
>>> print(zipline_result.transactions.head())
>>> print(zipline_result.benchmark_returns.head())
>>> print(zipline_result.perf.head())

The outputs are ready to be passed to pyfolio:

>>> pf.create_full_tear_sheet(
        zipline_result.returns,
        positions=zipline_result.positions,
        transactions=zipline_result.transactions,
        benchmark_rets=zipline_result.benchmark_returns)
quantrocket.zipline.clean_bundles(bundle=None, before=None, after=None, keep_last=None)

Clean up data downloaded with the ingest command.

Parameters:

bundle : str, optional

the data bundle to clean (default is quantopian-quandl)

before : str, optional

clear all data before this TIMESTAMP. This may not be passed with keep_last

after : str, optional

clear all data after this TIMESTAMP. This may not be passed with keep_last

keep_last : int, optional

clear all but the last N downloads. This may not be passed with before or after.

Returns:

list

bundles removed

quantrocket.zipline.create_tearsheet(infilepath_or_buffer, outfilepath_or_buffer=None, simple=None, live_start_date=None, slippage=None, hide_positions=None, bayesian=None, round_trips=None, bootstrap=None)

Create a pyfolio PDF tear sheet from a Zipline backtest result.

Parameters:

infilepath_or_buffer : str, required

the CSV file from a Zipline backtest (specify ‘-‘ to read file from stdin)

outfilepath_or_buffer : str or file-like, optional

the location to write the pyfolio tear sheet (write to stdout if omitted)

simple : bool

create a simple tear sheet (default is to create a full tear sheet)

live_start_date : str (YYYY-MM-DD), optional

date when the strategy began live trading

slippage : int or float, optional

basis points of slippage to apply to returns before generating tear sheet stats and plots

hide_positions : bool

don’t output any symbol names

bayesian : bool

include a Bayesian tear sheet

round_trips : bool

include a round-trips tear sheet

bootstrap : bool

perform bootstrap analysis for the performance metrics (takes a few minutes longer)

Returns:

None

quantrocket.zipline.ingest_bundle(history_db=None, calendar=None, bundle=None, assets_versions=None)

Ingest a data bundle into Zipline for later backtesting.

You can ingest 1-minute or 1-day history databases from QuantRocket, or you can ingest data using Zipline’s built-in capabilities.

Parameters:

history_db : str, optional

the code of a history db to ingest

calendar : str, optional

the name of the calendar to use with this history db bundle (default is NYSE; provide an invalid calendar name to see available choices)

bundle : str, optional

the data bundle to ingest (default is quantopian-quandl); don’t provide if specifying history_db

assets_versions : list of int, optional

versions of the assets db to which to downgrade

Returns:

dict

status message

quantrocket.zipline.list_bundles()

List all of the available data bundles.

Returns:

dict

data bundles and timestamps

quantrocket.zipline.run_algorithm(algofile, data_frequency=None, capital_base=None, bundle=None, bundle_timestamp=None, start=None, end=None, filepath_or_buffer=None, calendar=None)

Run a Zipline backtest and write the test results to a CSV file.

The CSV result file contains several DataFrames stacked into one: the Zipline performance results, plus the extracted returns, transactions, positions, and benchmark returns from those results.

Parameters:

algofile : str, required

the file that contains the algorithm to run

data_frequency : str, optional

the data frequency of the simulation. Possible choices: daily, minute (default is daily)

capital_base : float, optional

the starting capital for the simulation (default is 10000000.0)

bundle : str, optional

the data bundle to use for the simulation (default is quantopian-quandl)

bundle_timestamp : str, optional

the date to lookup data on or before (default is <current-time>)

start : str (YYYY-MM-DD), required

the start date of the simulation

end : str (YYYY-MM-DD), required

the end date of the simulation

filepath_or_buffer : str, optional

the location to write the output file (omit to write to stdout)

calendar : str, optional

the calendar you want to use e.g. LSE. NYSE is the default.

Returns:

None

Examples

Run a backtest and load the results into pandas.

>>> from quantrocket.zipline import run_algorithm
>>> import pandas as pd
>>> import io
>>> f = io.StringIO()
>>> run_algorithm("momentum_pipeline.py", bundle="my-bundle", start="2015-02-04", end="2015-12-31", filepath_or_buffer=f)
>>> results = pd.read_csv(f, index_col=["dataframe", "index", "column"])["value"]

To use the results with pyfolio, extract and massage the returns, positions, transactions, and benchmark returns:

>>> # Extract returns
>>> returns = results.loc["returns"].unstack()
>>> returns.index = returns.index.droplevel(0).tz_localize("UTC")
>>> returns = returns["returns"].astype(float)
>>> # Extract positions
>>> positions = results.loc["positions"].unstack()
>>> positions.index = positions.index.droplevel(0).tz_localize("UTC")
>>> positions = positions.astype(float)
>>> # Extract transactions
>>> transactions = results.loc["transactions"].unstack()
>>> transactions.index = transactions.index.droplevel(0).tz_localize("UTC")
>>> transactions = transactions.apply(pd.to_numeric, errors='ignore')
>>> # Extract benchmark
>>> benchmark_returns = results.loc["benchmark"].unstack()
>>> benchmark_returns.index = benchmark_returns.index.droplevel(0).tz_localize("UTC")
>>> benchmark_returns = benchmark_returns["benchmark"].astype(float)

Ready for pyfolio:

>>> pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions, benchmark_rets=benchmark_returns)
 

Zipline API

Zipline

Backtests

Run Backtest
POST/zipline/backtests/{algofile}{?data_frequency,capital_base,bundle,bundle_timestamp,start,end,calendar}

Run a Zipline backtest and write the test results to a CSV file.

The CSV result file contains several DataFrames stacked into one: the Zipline performance results, plus the extracted returns, transactions, positions, and benchmark returns from those results.

Example URI

POST http://houston:1969/zipline/backtests/dual_moving_average.py?data_frequency=daily&capital_base=100000&bundle=quantopian-quandl&bundle_timestamp=&start=&end=&calendar=NYSE
URI Parameters
algofile
str (required) Example: dual_moving_average.py

the file that contains the algorithm to run

data_frequency
str (optional) Example: daily

the data frequency of the simulation

Choices: daily minute

capital_base
float (optional) Example: 100000

the starting capital for the simulation (default is 10000000.0)

bundle
str (optional) Example: quantopian-quandl

the data bundle to use for the simulation (default is quantopian-quandl)

bundle_timestamp
str (optional) 

the date to lookup data on or before (default is )

start
str (required) 

the start date of the simulation

end
str (required) 

the end date of the simulation

calendar
str (optional) Example: NYSE

the calendar you want to use e.g. LSE. NYSE is the default.

Response  200
Headers
Content-Type: text/csv
Body
dataframe,index,date,column,value
benchmark,1,2010-01-05 00:00:00+00:00,benchmark,0.0016353229762877675
benchmark,2,2010-01-06 00:00:00+00:00,benchmark,-0.015836734693877474
transactions,754,2014-12-30 21:00:00+00:00,price,112.5200000000018
transactions,754,2014-12-30 21:00:00+00:00,sid,Equity(265598 [AAPL])
transactions,754,2014-12-30 21:00:00+00:00,symbol,Equity(265598 [AAPL])

Tear Sheets

Create Tear Sheet
POST/zipline/tearsheets{?simple,live_start_date,slippage,hide_positions,bayesian,round_trips,bootstrap}

Create a pyfolio PDF tear sheet from a Zipline backtest result.

Example URI

POST http://houston:1969/zipline/tearsheets?simple=false&live_start_date=2017-06-01&slippage=5&hide_positions=false&bayesian=false&round_trips=false&bootstrap=false
URI Parameters
simple
bool (optional) Example: false

create a simple tear sheet (default is to create a full tear sheet)

live_start_date
str (optional) Example: 2017-06-01

date when the strategy began live trading

slippage
float (optional) Example: 5

basis points of slippage to apply to returns before generating tear sheet stats and plots

hide_positions
bool (optional) Example: false

don’t output any symbol names

bayesian
bool (optional) Example: false

include a Bayesian tear sheet

round_trips
bool (optional) Example: false

include a round-trips tear sheet

bootstrap
bool (optional) Example: false

perform bootstrap analysis for the performance metrics (takes a few minutes longer)

Request
Headers
Content-Type: text/csv
Body
dataframe,index,date,column,value
benchmark,1,2010-01-05 00:00:00+00:00,benchmark,0.0016353229762877675
benchmark,2,2010-01-06 00:00:00+00:00,benchmark,-0.015836734693877474
transactions,754,2014-12-30 21:00:00+00:00,price,112.5200000000018
transactions,754,2014-12-30 21:00:00+00:00,sid,Equity(265598 [AAPL])
transactions,754,2014-12-30 21:00:00+00:00,symbol,Equity(265598 [AAPL])
Response  200
Headers
Content-Type: application/pdf

Bundles

List Bundles
GET/zipline/bundles

List all of the available data bundles.

Example URI

GET http://houston:1969/zipline/bundles
Response  200
Headers
Content-Type: application/json
Body
{
  "quantopian-quandl": [
    "2017-10-11 20:43:05.902937"
  ],
  "quandl": []
}

Ingest Bundle
POST/zipline/bundles{?bundle,history_db,calendar,assets_versions}

Ingest a data bundle into Zipline for later backtesting.

You can ingest 1-minute or 1-day history databases from QuantRocket, or you can ingest data using Zipline’s built-in capabilities.

Example URI

POST http://houston:1969/zipline/bundles?bundle=&history_db=my-db&calendar=us_futures&assets_versions=
URI Parameters
history_db
str (optional) Example: my-db

the code of a history db to ingest

calendar
str (optional) Example: us_futures

the name of the calendar to use with this history db bundle (default is NYSE; provide an invalid calendar name to see available choices)

bundle
str (optional) 

the data bundle to ingest (default is quantopian-quandl); don’t provide if specifying history_db

assets_versions
int (optional) 

versions of the assets db to which to downgrade

Response  200
Headers
Content-Type: application/json
Body
{
  "status": "success",
  "msg": "successfully ingested my-db bundle"
}

Clean Bundles
DELETE/zipline/bundles{?bundle,before,after,keep_last}

Clean up data downloaded with the ingest command.

Example URI

DELETE http://houston:1969/zipline/bundles?bundle=my-db&before=&after=&keep_last=1
URI Parameters
bundle
str (optional) Example: my-db

the data bundle to clean (default is quantopian-quandl)

before
str (optional) 

clear all data before this TIMESTAMP. This may not be passed with keep_last

after
str (optional) 

clear all data after this TIMESTAMP. This may not be passed with keep_last

keep_last
int (optional) Example: 1

clear all but the last N downloads. This may not be passed with before or after.

Response  200
Headers
Content-Type: application/json
Body
[
  "/root/.zipline/data/my-db/2017-10-20T14;29;32.118636",
  "/root/.zipline/data/my-db/2017-10-19T22;35;10.045909"
]