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 a Jupyter Notebook or Console, use the question mark syntax:

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

account

account service

QuantRocket account CLI

usage: quantrocket account [-h] {balance,portfolio,rates} ...
Sub-commands:
balance

query IB account balances

usage: quantrocket account balance [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-l]
                                   [-a [ACCOUNT [ACCOUNT ...]]]
                                   [-b [FIELD:AMOUNT [FIELD:AMOUNT ...]]]
                                   [-o OUTFILE] [-j | -p]
                                   [-f [FIELD [FIELD ...]]] [--force-refresh]
Options:
-s, --start-date
 limit to account balance snapshots taken on or after this date
-e, --end-datelimit to account balance snapshots taken on or before this date
-l=False, --latest=False
 return the latest account balance snapshot
-a, --accountslimit to these accounts
-b, --belowlimit to accounts where the specified field is below the specified amount (pass as field:amount, for example Cushion:0.05)
-o, --outfilefilename to write the data to (default is stdout)
-j, --jsonformat output as JSON (default is CSV)
-p, --prettyformat output in human-readable format (default is CSV)
-f, --fieldsonly return these fields (pass ‘?’ or any invalid fieldname to see available fields)
--force-refresh=False
 refresh account balances from IB (default is to query the database, which is refreshed every minute)
portfolio

download current IB portfolio

usage: quantrocket account portfolio [-h] [-a [ACCOUNT [ACCOUNT ...]]]
                                     [-t [SEC_TYPE [SEC_TYPE ...]]]
                                     [-e [EXCHANGE [EXCHANGE ...]]]
                                     [-i [CONID [CONID ...]]]
                                     [-s [SYMBOL [SYMBOL ...]]] [-z]
                                     [-o OUTFILE] [-j]
                                     [-f [FIELD [FIELD ...]]]
Options:
-a, --accountslimit to these accounts
-t, --sec-types
 limit to these security types
-e, --exchanges
 limit to these exchanges
-i, --conidslimit to these conids
-s, --symbolslimit to these symbols
-z=False, --zero=False
 include zero position rows (default is to exclude them)
-o, --outfilefilename to write the data to (default is stdout)
-j, --jsonformat output as JSON (default is CSV)
-f, --fieldsonly return these fields (pass ‘?’ or any invalid fieldname to see available fields)
rates

query exchange rates for the base currency

usage: quantrocket account rates [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-l]
                                 [-b [CURRENCY [CURRENCY ...]]]
                                 [-q [CURRENCY [CURRENCY ...]]] [-o OUTFILE]
                                 [-j | -p]
Options:
-s, --start-date
 limit to exchange rates on or after this date
-e, --end-datelimit to exchange rates on or before this date
-l=False, --latest=False
 return the latest exchange rates
-b, --base-currencies
 limit to these base currencies
-q, --quote-currencies
 limit to these quote currencies
-o, --outfilefilename to write the data to (default is stdout)
-j, --jsonformat output as JSON (default is CSV)
-p, --prettyformat output in human-readable format (default is CSV)
quantrocket.account.download_account_balances(filepath_or_buffer=None, output='csv', start_date=None, end_date=None, latest=False, accounts=None, below=None, fields=None, force_refresh=False)

Query IB account balances.

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)

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

limit to account balance snapshots taken on or after this date

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

limit to account balance snapshots taken on or before this date

latest : bool

return the latest account balance snapshot

accounts : list of str, optional

limit to these accounts

below : dict of FIELD:AMOUNT, optional

limit to accounts where the specified field is below the specified amount (pass as {field:amount}, for example {‘Cushion’:0.05})

fields : list of str, optional

only return these fields (pass [‘?’] or any invalid fieldname to see available fields)

force_refresh : bool

refresh account balances from IB (default is to query the database, which is refreshed every minute)

Returns:

None

Examples

Query latest balances. You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_account_balances(f, latest=True)
>>> balances = pd.read_csv(f, parse_dates=["LastUpdated"])
quantrocket.account.download_account_portfolio(filepath_or_buffer=None, output='csv', accounts=None, sec_types=None, exchanges=None, conids=None, symbols=None, include_zero=False, fields=None)

Download current IB portfolio.

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 or csv, default is csv)

accounts : list of str, optional

limit to these accounts

sec_types : list of str, optional

limit to these security types

exchanges : list of str, optional

limit to these exchanges

conids : list of int, optional

limit to these conids

symbols : list of str, optional

limit to these symbols

include_zero : bool

include zero position rows (default is to exclude them)

fields : list of str, optional

only return these fields (pass [‘?’] or any invalid fieldname to see available fields)

Returns:

None

Examples

Download current portfolio. You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_account_portfolio(f)
>>> portfolio = pd.read_csv(f, parse_dates=["LastUpdated"])
quantrocket.account.download_exchange_rates(filepath_or_buffer=None, output='csv', start_date=None, end_date=None, latest=False, base_currencies=None, quote_currencies=None)

Query exchange rates for the base currency.

The exchange rates in the exchange rate database are sourced from the European Central Bank’s reference rates, which are updated each day at 4 PM CET.

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)

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

limit to exchange rates on or after this date

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

limit to exchange rates on or before this date

latest : bool

return the latest exchange rates

base_currencies : list of str, optional

limit to these base currencies

quote_currencies : list of str, optional

limit to these quote currencies

Returns:

None

Examples

Query latest exchange rates. You can use StringIO to load the CSV into pandas.

>>> f = io.StringIO()
>>> download_exchange_rates(f, latest=True)
>>> rates = pd.read_csv(f, parse_dates=["Date"])
 

Account API

Account

Account Balances

Get Account Balances
GET/account/balances.{output}{?start_date,end_date,latest,accounts,below,fields,force_refresh}

Query IB account balances.

Example URI

GET http://houston/account/balances.csv?start_date=2017-01-01&end_date=2018-01-01&latest=true&accounts=U123456&below=Cushion:0.05&fields=NetLiquidation&force_refresh=true
URI Parameters
output
str (required) Example: csv

output format

Choices: csv json txt

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

limit to account balance snapshots taken on or after this date

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

limit to account balance snapshots taken on or before this date

latest
bool (optional) Example: true

return the latest account balance snapshot

accounts
str (optional) Example: U123456

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

below
str (optional) Example: Cushion:0.05

limit to accounts where the specified field is below the specified amount (pass as ‘field:amount’, for example ‘Cushion:0.05’) (pass multiple times for multiple filters)

fields
str (optional) Example: NetLiquidation

only return these fields (pass ‘?’ or any invalid fieldname to see available fields) (pass multiple times for multiple fields)

force_refresh
bool (optional) Example: true

refresh account balances from IB (default is to query the database, which is refreshed every minute)

Response  200
Headers
Content-Type: text/csv
Body
Account,Currency,NetLiquidation,LastUpdated
DU123456,USD,500000.0,"2017-12-16 14:28:54"

Exchange rates

Get Exchange Rates
GET/account/rates.{output}{?start_date,end_date,latest,base_currencies,quote_currencies}

Query exchange rates for the base currency.

The exchange rates in the exchange rate database are sourced from the European Central Bank’s reference rates, which are updated each day at 4 PM CET.

Example URI

GET http://houston/account/rates.csv?start_date=2017-01-01&end_date=2018-01-01&latest=true&base_currencies=USD&quote_currencies=CAD
URI Parameters
output
str (required) Example: csv

output format

Choices: csv json txt

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

limit to exchange rates on or after this date

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

limit to exchange rates on or before this date

latest
bool (optional) Example: true

return the latest exchange rates

base_currencies
str (optional) Example: USD

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

quote_currencies
str (optional) Example: CAD

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

Response  200
Headers
Content-Type: text/csv
Body
BaseCurrency,QuoteCurrency,Rate,Date
USD,AUD,1.2774,2018-01-09
USD,CAD,1.2425,2018-01-09
USD,CHF,0.98282,2018-01-09

blotter

order management and trade ledger service

QuantRocket blotter CLI

usage: quantrocket blotter [-h]
                           {order,cancel,status,positions,close,executions,pnl}
                           ...
Sub-commands:
order

place one or more orders

usage: quantrocket blotter order [-h]
                                 [-f INFILE | -p [PARAM:VALUE [PARAM:VALUE ...]]]
Options:
-f, --infileplace orders from this CSV or JSON file (specify ‘-‘ to read file from stdin)
-p, --paramsorder details as multiple key-value pairs (pass as ‘param:value’, for example OrderType:MKT)
cancel

cancel one or more orders by order ID, conid, or order ref

usage: quantrocket blotter cancel [-h] [-d [ORDER_ID [ORDER_ID ...]]]
                                  [-i [CONID [CONID ...]]]
                                  [-r [ORDER_REF [ORDER_REF ...]]]
                                  [-a [ACCOUNT [ACCOUNT ...]]] [--all]
Options:
-d, --order-ids
 cancel these order IDs
-i, --conidscancel orders for these conids
-r, --order-refs
 cancel orders for these order refs
-a, --accountscancel orders for these accounts
--all=Falsecancel all open orders
status

download order statuses

usage: quantrocket blotter status [-h] [-d [ORDER_ID [ORDER_ID ...]]]
                                  [-i [CONID [CONID ...]]]
                                  [-r [ORDER_REF [ORDER_REF ...]]]
                                  [-a [ACCOUNT [ACCOUNT ...]]] [--open]
                                  [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                  [-f [FIELD [FIELD ...]]] [-o OUTFILE] [-j]
Options:
-d, --order-ids
 limit to these order IDs
-i, --conidslimit to orders for these conids
-r, --order-refs
 limit to orders for these order refs
-a, --accountslimit to orders for these accounts
--open=Falselimit to open orders
-s, --start-date
 limit to orders submitted on or after this date
-e, --end-datelimit to orders submitted on or before this date
-f, --fieldsreturn these fields in addition to the default fields (pass ‘?’ or any invalid fieldname to see available fields)
-o, --outfilefilename to write the data to (default is stdout)
-j, --jsonformat output as JSON (default is CSV)
positions

query current positions

usage: quantrocket blotter positions [-h] [-i [CONID [CONID ...]]]
                                     [-r [ORDER_REF [ORDER_REF ...]]]
                                     [-a [ACCOUNT [ACCOUNT ...]]] [--diff]
                                     [--broker] [-o OUTFILE] [-j]
Options:
-i, --conidslimit to these conids
-r, --order-refs
 limit to these order refs (not supported with broker view)
-a, --accountslimit to these accounts
--diff=Falselimit to positions where the blotter quantity and broker quantity disagree (requires –broker)
--brokerreturn ‘broker’ view of positions (by account and conid) instead of default ‘blotter’ view (by account, conid, and order ref)
-o, --outfilefilename to write the data to (default is stdout)
-j, --jsonformat output as JSON (default is CSV)
close

generate orders to close positions

usage: quantrocket blotter close [-h] [-i [CONID [CONID ...]]]
                                 [-r [ORDER_REF [ORDER_REF ...]]]
                                 [-a [ACCOUNT [ACCOUNT ...]]] [-o OUTFILE]
                                 [-p [PARAM:VALUE [PARAM:VALUE ...]]] [-j]
Options:
-i, --conidslimit to these conids
-r, --order-refs
 limit to these order refs
-a, --accountslimit to these accounts
-o, --outfilefilename to write the data to (default is stdout)
-p, --paramsadditional parameters to append to each row in output (pass as ‘param:value’, for example OrderType:MKT)
-j, --jsonformat output as JSON (default is CSV)
executions

query executions from the executions database

usage: quantrocket blotter executions [-h] [-i [CONID [CONID ...]]]
                                      [-r [ORDER_REF [ORDER_REF ...]]]
                                      [-a [ACCOUNT [ACCOUNT ...]]]
                                      [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                      [-o OUTFILE]
Options:
-i, --conidslimit to these conids
-r, --order-refs
 limit to these order refs
-a, --accountslimit to these accounts
-s, --start-date
 limit to executions on or after this date
-e, --end-datelimit to executions on or before this date
-o, --outfilefilename to write the data to (default is stdout)
pnl

query trading performance and return a PDF tearsheet or CSV of results

usage: quantrocket blotter pnl [-h] [-i [CONID [CONID ...]]]
                               [-r [ORDER_REF [ORDER_REF ...]]]
                               [-a [ACCOUNT [ACCOUNT ...]]] [-s YYYY-MM-DD]
                               [-e YYYY-MM-DD] [-t HH:MM:SS [TZ]] [-d] [--pdf]
                               [-o OUTFILE]
Options:
-i, --conidslimit to these conids
-r, --order-refs
 limit to these order refs
-a, --accountslimit to these accounts
-s, --start-date
 limit to pnl on or after this date
-e, --end-datelimit to pnl on or before this date
-t, --timetime of day (with optional timezone) for which to calculate daily PNL (default is 11:59:59 UTC)
-d=False, --details=False
 return detailed results for all securities instead of aggregating to account/order ref level (only supported for a single account and order ref at a time)
--pdfreturn a PDF tear sheet of PNL (default is to return a CSV)
-o, --outfilefilename to write the data to (default is stdout)
quantrocket.blotter.cancel_orders(order_ids=None, conids=None, order_refs=None, accounts=None, cancel_all=None)

Cancel one or more orders by order ID, conid, or order ref.

Parameters:

order_ids : list of str, optional

cancel these order IDs

conids : list of int, optional

cancel orders for these conids

order_refs: list of str, optional

cancel orders for these order refs

accounts : list of str, optional

cancel orders for these accounts

cancel_all : bool

cancel all open orders

Returns:

dict

status message

Examples

Cancel orders by order ID:

>>> cancel_orders(order_ids=['6002:45','6002:46'])

Cancel orders by conid:

>>> cancel_orders(conids=[123456])

Cancel orders by order ref:

>>> cancel_orders(order_refs=['my-strategy'])

Cancel all open orders:

>>> cancel_orders(cancel_all=True)
quantrocket.blotter.close_positions(filepath_or_buffer=None, output='csv', order_refs=None, accounts=None, conids=None, params=None)

Generate orders to close positions.

Doesn’t actually place any orders but returns an orders file that can be placed separately. Additional order parameters can be appended with the params argument.

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 or csv, default is csv)

order_refs : list of str, optional

limit to these order refs

accounts : list of str, optional

limit to these accounts

conids : list of int, optional

limit to these conids

params : dict of PARAM:VALUE, optional

additional parameters to append to each row in output (pass as {param:value}, for example {“OrderType”:”MKT”})

Returns:

None

Examples

Get orders to close positions, then place the orders:

>>> from quantrocket.blotter import place_orders, close_positions
>>> import io
>>> orders_file = io.StringIO()
>>> close_positions(orders_file, params={"OrderType":"MKT", "Tif":"DAY", "Exchange":"SMART"})
>>> place_orders(infilepath_or_buffer=orders_file)
quantrocket.blotter.download_executions(filepath_or_buffer=None, order_refs=None, accounts=None, conids=None, start_date=None, end_date=None)

Query executions from the executions database.

Parameters:

filepath_or_buffer : str or file-like object

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

order_refs : list of str, optional

limit to these order refs

accounts : list of str, optional

limit to these accounts

conids : list of int, optional

limit to these conids

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

limit to executions on or after this date

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

limit to executions on or before this date

Returns:

None

quantrocket.blotter.download_order_statuses(filepath_or_buffer=None, output='csv', order_ids=None, conids=None, order_refs=None, accounts=None, open_orders=None, start_date=None, end_date=None, fields=None)

Download order statuses.

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 or csv, default is csv)

order_ids : list of str, optional

limit to these order IDs

conids : list of int, optional

limit to orders for these conids

order_refs : list of str, optional

limit to orders for these order refs

accounts : list of str, optional

limit to orders for these accounts

open_orders : bool

limit to open orders

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

limit to orders submitted on or after this date

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

limit to orders submitted on or before this date

fields : list of str, optional

return these fields in addition to the default fields (pass ‘?’ or any invalid fieldname to see available fields)

Returns:

None

Examples

Download order status by order ID and load into Pandas:

>>> f = io.StringIO()
>>> download_order_statuses(f, order_ids=['6001:45','6001:46'])
>>> order_statuses = pd.read_csv(f)

Download order status for all open orders and include extra fields in output:

>>> download_order_statuses(open_orders=True, fields=["LmtPrice", "OcaGroup"])

Download order status of open orders by conid:

>>> download_order_statuses(conids=[123456], open_orders=True)

Download order status of open orders by order ref:

>>> download_order_statuses(order_refs=['my-strategy'], open_orders=True)
quantrocket.blotter.download_pnl(filepath_or_buffer=None, order_refs=None, accounts=None, conids=None, start_date=None, end_date=None, time=None, details=False, output='csv')

Query trading performance and return a CSV of results or PDF tearsheet.

Trading performance is broken down by account and order ref and optionally by conid.

Parameters:

filepath_or_buffer : str or file-like object

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

order_refs : list of str, optional

limit to these order refs

accounts : list of str, optional

limit to these accounts

conids : list of int, optional

limit to these conids

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

limit to pnl on or after this date

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

limit to pnl on or before this date

time : str (HH:MM:SS [TZ]), optional

time of day (with optional timezone) for which to calculate daily PNL (default is 11:59:59 UTC)

details : bool

return detailed results for all securities instead of aggregating to account/order ref level (only supported for a single account and order ref at a time)

output : str, required

the output format (choices are csv or pdf, default is csv)

Returns:

None

quantrocket.blotter.download_positions(filepath_or_buffer=None, output='csv', order_refs=None, accounts=None, conids=None, view='blotter', diff=False)

Query current positions and write results to file.

To return positions as a Python list, see list_positions.

There are two ways to view positions: blotter view (default) and broker view.

The default “blotter view” returns positions by account, conid, and order ref. Positions are tracked based on execution records saved to the blotter database.

“Broker view” (view=’broker’) returns positions by account and conid (but not order ref) as reported directly by IB. Broker view is more authoritative but less informative than blotter view. Broker view is typically used to verify the accuracy of blotter view.

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 or csv, default is csv)

order_refs : list of str, optional

limit to these order refs (not supported with broker view)

accounts : list of str, optional

limit to these accounts

conids : list of int, optional

limit to these conids

view : str, optional

whether to return ‘broker’ view of positions (by account and conid) or default ‘blotter’ view (by account, conid, and order ref). Choices are: blotter, broker

diff : bool

limit to positions where the blotter quantity and broker quantity disagree (requires view=’broker’)

Returns:

None

See also

list_positions
load positions into Python list
quantrocket.blotter.list_positions(order_refs=None, accounts=None, conids=None, view='blotter', diff=False)

Query current positions and return them as a Python list.

There are two ways to view positions: blotter view (default) and broker view.

The default “blotter view” returns positions by account, conid, and order ref. Positions are tracked based on execution records saved to the blotter database.

“Broker view” (view=’broker’) returns positions by account and conid (but not order ref) as reported directly by IB. Broker view is more authoritative but less informative than blotter view. Broker view is typically used to verify the accuracy of blotter view.

Parameters:

order_refs : list of str, optional

limit to these order refs (not supported with broker view)

accounts : list of str, optional

limit to these accounts

conids : list of int, optional

limit to these conids

view : str, optional

whether to return ‘broker’ view of positions (by account and conid) or default ‘blotter’ view (by account, conid, and order ref). Choices are: blotter, broker

diff : bool

limit to positions where the blotter quantity and broker quantity disagree (requires view=’broker’)

Returns:

list

Examples

Query current positions and load into Pandas:

>>> positions = list_positions()
>>> if positions:
>>>     positions = pd.DataFrame(positions)
quantrocket.blotter.place_orders(orders=None, infilepath_or_buffer=None)

Place one or more orders.

Returns a list of order IDs, which can be used to cancel the orders or check their status.

Parameters:

orders : list of dict of PARAM:VALUE, optional

a list of one or more orders, where each order is a dict specifying the order parameters (see examples)

infilepath_or_buffer : str or file-like object, optional

place orders from this CSV or JSON file (specify ‘-‘ to read file from stdin). Mutually exclusive with orders argument.

Returns:

list

order IDs

Examples

>>> orders = []
>>> order1 = {
        'ConId':123456,
        'Action':'BUY',
        'Exchange':'SMART',
        'TotalQuantity':100,
        'OrderType':'MKT',
        'Tif':'Day',
        'Account':'DU12345',
        'OrderRef':'my-strategy'
    }
>>> orders.append(order1)
>>> order_ids = place_orders(orders)
 

Blotter API

Blotter

Orders

Place Orders
POST/blotter/orders

Place one or more orders from a CSV or JSON file. Returns a list of order IDs, which can be used to cancel the orders or check their status.

Example URI

POST http://houston/blotter/orders
Request
Headers
Content-Type: text/csv
Body
ConId,Account,Action,OrderRef,TotalQuantity,Exchange,OrderType,Tif
265598,DU123456,BUY,dma-tech,500,SMART,MKT,DAY
3691937,DU123456,BUY,dma-tech,50,SMART,MKT,DAY
Request
Headers
Content-Type: application/json
Body
[
  {
    "ConId": 265598,
    "Account": "DU123456",
    "Action": "BUY",
    "OrderRef": "dma-tech",
    "TotalQuantity": 500,
    "Exchange": "SMART",
    "OrderType": "MKT",
    "Tif": "DAY"
  },
  {
    "ConId": 3691937,
    "Account": "DU123456",
    "Action": "BUY",
    "OrderRef": "dma-tech",
    "TotalQuantity": 50,
    "Exchange": "SMART",
    "OrderType": "MKT",
    "Tif": "DAY"
  }
]
Response  200
Headers
Content-Type: application/json
Body
[
  "6001:25",
  "6001:26"
]

Get Order Status
GET/blotter/orders{output}{?order_ids,conids,order_refs,accounts,open_orders,start_date,end_date,fields}

Download order statuses.

Example URI

GET http://houston/blotter/orders.csv?order_ids=6001:25&conids=123456&order_refs=my-strategy&accounts=U12345&open_orders=true&start_date=2018-02-01&end_date=2018-03-01&fields=LmtPrice
URI Parameters
output
str (required) Example: .csv

output format

Choices: csv json

order_ids
str (optional) Example: 6001:25

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

conids
int (optional) Example: 123456

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

order_refs
str (optional) Example: my-strategy

limit to orders for these order refs (pass multiple times for multiple order refs)

accounts
str (optional) Example: U12345

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

open_orders
bool (optional) Example: true

limit to open orders

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

limit to orders submitted on or after this date

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

limit to orders submitted on or before this date

fields
str (optional) Example: LmtPrice

return these fields in addition to the default fields (pass ‘?’ or any invalid fieldname to see available fields) (pass multiple times for multiple fields)

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

Cancel Orders
DELETE/blotter/orders{?order_ids,conids,order_refs,accounts,cancel_all}

Cancel one or more orders by order ID, conid, or order ref.

Example URI

DELETE http://houston/blotter/orders?order_ids=6001:25&conids=123456&order_refs=my-strategy&accounts=U12345&cancel_all=true
URI Parameters
order_ids
str (optional) Example: 6001:25

cancel these order IDs (pass multiple times for multiple order IDs)

conids
int (optional) Example: 123456

cancel orders for these conids (pass multiple times for multiple conids)

order_refs
str (optional) Example: my-strategy

cancel orders for these order refs (pass multiple times for multiple order refs)

accounts
str (optional) Example: U12345

cancel orders for these accounts (pass multiple times for multiple accounts)

cancel_all
bool (optional) Example: true

cancel all open orders

Response  200
Headers
Content-Type: application/json
Body
{
    "order_ids": [
        "6001:25",
    ],
    "status": "the orders will be canceled asynchronously"
}

Positions

Get Positions
GET/blotter/positions.{output}{?conids,order_refs,accounts,view,diff}

Query current positions and write results to file.

There are two ways to view positions: blotter view (default) and broker view.

The default “blotter view” returns positions by account, conid, and order ref. Positions are tracked based on execution records saved to the blotter database.

“Broker view” (view=‘broker’) returns positions by account and conid (but not order ref) as reported directly by IB. Broker view is more authoritative but less informative than blotter view. Broker view is typically used to verify the accuracy of blotter view.

Example URI

GET http://houston/blotter/positions.csv?conids=123456&order_refs=my-strategy&accounts=U12345&view=blotter&diff=false
URI Parameters
output
str (required) Example: csv

output format

Choices: csv json

view
str (optional) Example: blotter

whether to return ‘broker’ view of positions (by account and conid) or default ‘blotter’ view (by account, conid, and order ref)

Choices: blotter broker

conids
int (optional) Example: 123456

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

order_refs
str (optional) Example: my-strategy

limit to these order refs (not supported with broker view) (pass multiple times for multiple order refs)

accounts
str (optional) Example: U12345

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

diff
bool (optional) Example: false

limit to positions where the blotter quantity and broker quantity disagree (requires broker view)

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

Close Positions
DELETE/blotter/positions.{output}{?conids,order_refs,accounts,params}

Generate orders to close positions. Doesn’t actually place any orders but returns an orders file that can be placed separately. Additional order parameters can be appended with the params argument.

Example URI

DELETE http://houston/blotter/positions.csv?conids=123456&order_refs=my-strategy&accounts=U12345&params=OrderType:MKT
URI Parameters
output
str (required) Example: csv

output format

Choices: csv json

conids
int (optional) Example: 123456

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

order_refs
str (optional) Example: my-strategy

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

accounts
str (optional) Example: U12345

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

params
str (optional) Example: OrderType:MKT

additional parameters to append to each row in output (pass as ‘param:value’) (pass multiple times for multiple params)

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

Executions

Get Executions
GET/blotter/executions.{output}{?conids,order_refs,accounts,start_date,end_date}

Query executions from the executions database.

Example URI

GET http://houston/blotter/executions.csv?conids=123456&order_refs=my-strategy&accounts=U12345&start_date=2018-02-01&end_date=2018-03-01
URI Parameters
output
str (required) Example: csv

output format

Choices: csv

conids
int (optional) Example: 123456

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

order_refs
str (optional) Example: my-strategy

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

accounts
str (optional) Example: U12345

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

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

limit to executions on or after this date

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

limit to executions on or before this date

Response  200
Headers
Content-Type: text/csv

PNL

Get PNL
GET/blotter/pnl.{output}{?conids,order_refs,accounts,start_date,end_date,time,details}

Query trading performance and return a CSV of results or PDF tearsheet. Trading performance is broken down by account and order ref and optionally by conid.

Example URI

GET http://houston/blotter/pnl.csv?conids=123456&order_refs=my-strategy&accounts=U12345&start_date=2018-02-01&end_date=2018-03-01&time=16:30:00 America/New_York&details=true
URI Parameters
output
str (required) Example: csv

output format

Choices: csv pdf

conids
int (optional) Example: 123456

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

order_refs
str (optional) Example: my-strategy

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

accounts
str (optional) Example: U12345

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

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

limit to pnl on or after this date

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

limit to pnl on or before this date

time
str (optional) Example: 16:30:00 America/New_York

time of day (with optional timezone) for which to calculate daily PNL (default is 11:59:59 UTC)

details
bool (optional) Example: true

return detailed results for all securities instead of aggregating to account/order ref level (only supported for a single account and order ref at a time)

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

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/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/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/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/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/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/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/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/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/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/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/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,fetch-shortshares,fetch-shortfees,shortshares,shortfees}
                               ...
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 fiscal period end date
-e, --end-date limit to statements 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
-q=False, --interim=False
 return interim reports (default is to return annual reports, which provide deeper history)
-r=False, --exclude-restatements=False
 exclude restatements (default is to include 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 (pass ‘?’ or any invalid fieldname to see available 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 (pass ‘?’ or any invalid fieldname to see available fields)
fetch-shortshares

fetch IB shortable shares data and save to database

usage: quantrocket fundamental fetch-shortshares [-h]
                                                 [-c [COUNTRY [COUNTRY ...]]]
Options:
-c, --countries
 limit to these countries (pass ‘?’ or any invalid country to see available countries)
fetch-shortfees

fetch IB borrow fees data and save to database

usage: quantrocket fundamental fetch-shortfees [-h]
                                               [-c [COUNTRY [COUNTRY ...]]]
Options:
-c, --countries
 limit to these countries (pass ‘?’ or any invalid country to see available countries)
shortshares

query shortable shares from the stockloan database and download to file

usage: quantrocket fundamental shortshares [-h] [-s YYYY-MM-DD]
                                           [-e YYYY-MM-DD]
                                           [-u [UNIVERSE [UNIVERSE ...]]]
                                           [-i [CONID [CONID ...]]]
                                           [--exclude-universes [UNIVERSE [UNIVERSE ...]]]
                                           [--exclude-conids [CONID [CONID ...]]]
                                           [-o OUTFILE] [-j]
Options:
-s, --start-date
 limit to data on or after this date
-e, --end-date limit to data 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
-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
shortfees

query borrow fees from the stockloan database and download to file

usage: quantrocket fundamental shortfees [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                         [-u [UNIVERSE [UNIVERSE ...]]]
                                         [-i [CONID [CONID ...]]]
                                         [--exclude-universes [UNIVERSE [UNIVERSE ...]]]
                                         [--exclude-conids [CONID [CONID ...]]]
                                         [-o OUTFILE] [-j]
Options:
-s, --start-date
 limit to data on or after this date
-e, --end-date limit to data 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
-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
quantrocket.fundamental.download_borrow_fees(filepath_or_buffer=None, output='csv', start_date=None, end_date=None, universes=None, conids=None, exclude_universes=None, exclude_conids=None)

Query borrow fees from the stockloan database and download to file.

Data timestamps are UTC.

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, default is csv)

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

limit to data on or after this date

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

limit to data on or before this 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

Returns:

None

Examples

Query borrow fees for a universe of Australian stocks.

>>> f = io.StringIO()
>>> download_borrow_fees("asx_borrow_fees.csv", universes=["asx-stk"])
>>> borrow_fees = pd.read_csv("asx_borrow_fees.csv", parse_dates=["Date"])
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 (pass [‘?’] or any invalid fieldname to see available 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, exclude_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 reports are available. Annual is the default and provides deeper history.

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 fiscal period end date

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

limit to statements 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

interim : bool, optional

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

exclude_restatements : bool, optional

exclude restatements (default is to include them)

fields : list of str, optional

only return these fields (pass [‘?’] or any invalid fieldname to see available 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 reports for two securities (identified by conid) and exclude restatements:

>>> download_reuters_financials(["NINC"], f, conids=[123456, 234567],
                                interim=True, exclude_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.download_shortable_shares(filepath_or_buffer=None, output='csv', start_date=None, end_date=None, universes=None, conids=None, exclude_universes=None, exclude_conids=None)

Query shortable shares from the stockloan database and download to file.

Data timestamps are UTC.

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, default is csv)

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

limit to data on or after this date

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

limit to data on or before this 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

Returns:

None

Examples

Query shortable shares for a universe of Australian stocks.

>>> f = io.StringIO()
>>> download_shortable_shares("asx_shortables.csv", universes=["asx-stk"])
>>> shortables = pd.read_csv("asx_shortables.csv", parse_dates=["Date"])
quantrocket.fundamental.fetch_borrow_fees(countries=None)

Fetch IB borrow fees data and save to database.

Data is organized by country and updated every 15 minutes. Historical data is available from April 2018.

Parameters:

countries : list of str, optional

limit to these countries (pass ‘?’ or any invalid country to see available countries)

Returns:

dict

status message

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.fetch_shortable_shares(countries=None)

Fetch IB shortable shares data and save to database.

Data is organized by country and updated every 15 minutes. Historical data is available from April 2018.

Parameters:

countries : list of str, optional

limit to these countries (pass ‘?’ or any invalid country to see available countries)

Returns:

dict

status message

quantrocket.fundamental.get_borrow_fees_reindexed_like(reindex_like, time=None)

Return a DataFrame of borrow fees, reindexed to match the index (dates) and columns (conids) of reindex_like.

Parameters:

reindex_like : DataFrame, required

a DataFrame (usually of prices) with dates for the index and conids for the columns, to which the shape of the resulting DataFrame will be conformed

time : str (HH:MM:SS[ TZ]), optional

return borrow fees as of this time of day. If omitted, borrow fees will be returned as of the times of day in reindex_like‘s DatetimeIndex. (Note that for a DatetimeIndex containing dates only, the time is 00:00:00, meaning borrow fees will be returned as of midnight at the start of the day.) A time and timezone can be passed as a space-separated string (e.g. “09:30:00 America/New_York”). If timezone is omitted, the timezone of reindex_like‘s DatetimeIndex will be used; if reindex_like‘s timezone is not set, the timezone will be inferred from the component securities, if all securities share the same timezone.

Returns:

DataFrame

a DataFrame of borrow fees, shaped like the input DataFrame

Examples

Get borrow fees as of midnight for a DataFrame of US stocks:

>>> closes = prices.loc["Close"]
>>> borrow_fees = get_borrow_fees_reindexed_like(closes)

Get borrow fees as of 4:30 PM for a DataFrame of US stocks (timezone inferred from component stocks):

>>> closes = prices.loc["Close"]
>>> borrow_fees = get_borrow_fees_reindexed_like(closes, time="16:30:00")

Get borrow fees as of 4:30 PM New York time for a multi-timezone DataFrame of stocks:

>>> closes = prices.loc["Close"]
>>> borrow_fees = get_borrow_fees_reindexed_like(closes, time="16:30:00 America/New_York")
quantrocket.fundamental.get_reuters_estimates_reindexed_like(reindex_like, codes, fields=['Actual'], period_types=['Q'], max_lag=None)

Return a multiindex (Indicator, Field, Date) DataFrame of point-in-time Reuters estimates and actuals for one or more indicator codes, reindexed to match the index (dates) and columns (conids) of reindex_like. Estimates and actuals are forward-filled in order to provide the latest reading at any given date, indexed to the UpdatedDate field. UpdatedDate is shifted forward 1 day to avoid lookahead bias.

Parameters:

reindex_like : DataFrame, required

a DataFrame (usually of prices) with dates for the index and conids for the columns, to which the shape of the resulting DataFrame will be conformed

codes : list of str, required

the indicator code(s) to query. Use the list_reuters_codes function to see available codes.

fields : list of str

a list of fields to include in the resulting DataFrame. Defaults to simply including the Actual field.

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. Default is Q/Quarterly.

max_lag : str, optional

maximum amount of time a data point can be used after the associated fiscal period has ended. Setting a limit can prevent using data that is reported long after the fiscal period ended, or can limit how far data is forward filled in the absence of subsequent data. Specify as a Pandas offset alias, e.g. ‘500D’. By default, no maximum limit is applied.

Returns:

DataFrame

a multiindex (Indicator, Field, Date) DataFrame of estimates and actuals, shaped like the input DataFrame

Examples

Query book value per share (code BVPS):

>>> closes = prices.loc["Close"]
>>> estimates = get_reuters_estimates_reindexed_like(closes, codes=["BVPS"])
>>> book_values_per_share = estimates.loc["BVPS"].loc["Actual"]
quantrocket.fundamental.get_reuters_financials_reindexed_like(reindex_like, coa_codes, fields=['Amount'], interim=False, exclude_restatements=False, max_lag=None)

Return a multiindex (CoaCode, Field, Date) DataFrame of point-in-time Reuters financial statements for one or more Chart of Account (COA) codes, reindexed to match the index (dates) and columns (conids) of reindex_like. Financial values are forward-filled in order to provide the latest reading at any given date. Financials are indexed to the SourceDate field, i.e. the date on which the financial statement was released. SourceDate is shifted forward 1 day to avoid lookahead bias.

Parameters:

reindex_like : DataFrame, required

a DataFrame (usually of prices) with dates for the index and conids for the columns, to which the shape of the resulting DataFrame will be conformed

coa_codes : list of str, required

the Chart of Account (COA) code(s) to query. Use the list_reuters_codes function to see available codes.

fields : list of str

a list of fields to include in the resulting DataFrame. Defaults to simply including the Amount field.

interim : bool

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

exclude_restatements : bool, optional

exclude restatements (default is to include them)

max_lag : str, optional

maximum amount of time a data point can be used after the associated fiscal period has ended. Setting a limit can prevent using data that is reported long after the fiscal period ended, or can limit how far data is forward filled in the absence of subsequent data. Specify as a Pandas offset alias, e.g. ‘500D’. By default, no maximum limit is applied.

Returns:

DataFrame

a multiindex (CoaCode, Field, Date) DataFrame of financials, shaped like the input DataFrame

Examples

Let’s calculate book value per share, defined as:

(Total Assets - Total Liabilities) / Number of shares outstanding

The COA codes for these metrics are ‘ATOT’ (Total Assets), ‘LTLL’ (Total Liabilities), and ‘QTCO’ (Total Common Shares Outstanding).

>>> closes = prices.loc["Close"]
>>> financials = get_reuters_financials_reindexed_like(closes, coa_codes=["ATOT", "LTLL", "QTCO"])
>>> tot_assets = financials.loc["ATOT"].loc["Amount"]
>>> tot_liabilities = financials.loc["LTLL"].loc["Amount"]
>>> shares_out = financials.loc["QTCO"].loc["Amount"]
>>> book_values_per_share = (tot_assets - tot_liabilities)/shares_out
quantrocket.fundamental.get_shortable_shares_reindexed_like(reindex_like, time=None)

Return a DataFrame of shortable shares, reindexed to match the index (dates) and columns (conids) of reindex_like.

Parameters:

reindex_like : DataFrame, required

a DataFrame (usually of prices) with dates for the index and conids for the columns, to which the shape of the resulting DataFrame will be conformed

time : str (HH:MM:SS[ TZ]), optional

return shortable shares as of this time of day. If omitted, shortable shares will be returned as of the times of day in reindex_like‘s DatetimeIndex. (Note that for a DatetimeIndex containing dates only, the time is 00:00:00, meaning shortable shares will be returned as of midnight at the start of the day.) A time and timezone can be passed as a space-separated string (e.g. “09:30:00 America/New_York”). If timezone is omitted, the timezone of reindex_like‘s DatetimeIndex will be used; if reindex_like‘s timezone is not set, the timezone will be inferred from the component securities, if all securities share the same timezone.

Returns:

DataFrame

a DataFrame of shortable shares, shaped like the input DataFrame

Examples

Get shortable shares as of midnight for a DataFrame of US stocks:

>>> closes = prices.loc["Close"]
>>> shortables = get_shortable_shares_reindexed_like(closes)

Get shortable shares as of 9:20 AM for a DataFrame of US stocks (timezone inferred from component stocks):

>>> closes = prices.loc["Close"]
>>> shortables = get_shortable_shares_reindexed_like(closes, time="09:20:00")

Get shortable shares as of 9:20 AM New York time for a multi-timezone DataFrame of stocks:

>>> closes = prices.loc["Close"]
>>> shortables = get_shortable_shares_reindexed_like(closes, time="09:20:00 America/New_York")
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/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,exclude_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.

Example URI

GET http://houston/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&exclude_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 fiscal period end date

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

limit to statements 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)

interim
bool (optional) Example: true

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

exclude_restatements
bool (optional) Example: false

exclude restatements (default is to include 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/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/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/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,availability,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 ...]] |
                                     --between-times HH:MM:SS HH:MM:SS]
                                     [--shard HOW] [-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 (refers to the bar’s start time; mutually exclusive with –between-times)
--between-times
 limit to times between these two times (refers to the bar’s start time; mutually exclusive with –times)
--shard

whether and how to shard the database, i.e. break it into smaller pieces. Possible choices are `time` (separate database for each bar time), `off` (no sharding), or `auto` (decide automatically based on bar size and universe size). Default `auto`.

Possible choices: time, off, auto

-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 ...]]]
                                 [-u [UNIVERSE [UNIVERSE ...]]]
                                 [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-a]
                                 [--delist-missing]
                                 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, overriding config (typically used to fetch a subset of securities)
-u, --universes
 fetch history for these universes, overriding config (typically used to fetch a subset of securities)
-s, --start-date
 fetch history back to this start date, overriding config
-e, --end-date fetch history up to this end date, overriding config
-a=False, --availability=False
 determine and store how far back data is available but don’t yet fetch the data
--delist-missing=False
 auto-delist securities that are no longer available from IB
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 (pass ‘?’ or any invalid fieldname to see available 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

availability

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

usage: quantrocket history availability [-h] [-o OUTFILE] [-j] CODE
Positional arguments:
code the code of the database to query
Options:
-o, --outfile filename to write the data to (default is stdout)
-j, --json format output as JSON (default is CSV)
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, between_times=None, shard=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 (refers to the bar’s start time; mutually exclusive with between_times)

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

limit to times between these two times (refers to the bar’s start time; mutually exclusive with times)

shard : str, optional

whether and how to shard the database, i.e. break it into smaller pieces. Possible choices are time (separate database for each bar time), off (no sharding), or auto (decide automatically based on bar size and universe size). Default auto.

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_availability_file(code, filepath_or_buffer=None, output='csv')

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

This function is normally called after running:

quantrocket history fetch mydb –availability
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, default is csv)

Returns:

None

See also

get_history_availability
load historical availability into Series
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 (pass [‘?’] or any invalid fieldname to see available 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

See also

get_historical_prices
load historical prices into DataFrame

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, universes=None, start_date=None, end_date=None, availability_only=False, delist_missing=False)

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, overriding config (typically used to fetch a subset of securities)

universes : list of str, optional

fetch history for these universes, overriding config (typically used to fetch a subset of securities)

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

fetch history back to this start date, overriding config

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

fetch history up to this end date, overriding config

availability_only : bool

determine and store how far back data is available but don’t yet fetch the data

delist_missing : bool

auto-delist securities that are no longer available from IB

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_historical_prices(codes, start_date=None, end_date=None, universes=None, conids=None, exclude_universes=None, exclude_conids=None, times=None, cont_fut=None, fields=None, master_fields=None, timezone=None, infer_timezone=None)

Query one or more history databases and load prices into a DataFrame.

For bar sizes smaller than 1-day, the resulting DataFrame will have a MultiIndex with levels (Field, Date, Time). For bar sizes of 1-day or larger, the MultiIndex will have levels (Field, Date).

Parameters:

codes : str or list of str, required

the code(s) of one or more databases to query. If multiple databases are specified, they must have the same bar size.

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 (pass [‘?’] or any invalid fieldname to see available fields)

master_fields : list of str, optional

append these fields from the securities master database (pass [‘?’] or any invalid fieldname to see available fields)

timezone : str, optional

convert timestamps to this timezone, for example America/New_York (see pytz.all_timezones for choices); ignored for non-intraday bar sizes

infer_timezone : bool

infer the timezone from the securities master Timezone field; defaults to True if using intraday bars and no timezone specified; ignored for non-intraday bars, or if timezone is passed

Returns:

DataFrame

a MultiIndex

Examples

Load intraday prices:

>>> prices = get_historical_prices('stk-sample-5min', fields=["Close", "Volume"], timezone="America/New_York")
>>> prices.head()
                            ConId           265598  38708077
Field       Date            Time
Close       2017-07-26      09:30:00        153.62  2715.0
                            09:35:00        153.46  2730.0
                            09:40:00        153.21  2725.0
                            09:45:00        153.28  2725.0
                            09:50:00        153.18  2725.0

Isolate the closes:

>>> closes = prices.loc["Close"]
>>> closes.head()
            ConId           265598  38708077
Date        Time
2017-07-26  09:30:00        153.62  2715.0
            09:35:00        153.46  2730.0
            09:40:00        153.21  2725.0
            09:45:00        153.28  2725.0
            09:50:00        153.18  2725.0

Isolate the 15:45:00 prices:

>>> session_closes = closes.xs("15:45:00", level="Time")
>>> session_closes.head()
    ConId   265598  38708077
Date
2017-07-26  153.29  2700.00
2017-07-27  150.10  2660.00
2017-07-28  149.43  2650.02
2017-07-31  148.99  2650.34
2017-08-01  149.72  2675.50
quantrocket.history.get_history_availability(code)

Query historical data availability from a history database, returning a Series of start dates (with conids as the index) representing how far back data can be fetched from IB.

This function is normally called after running a command such as:

quantrocket history fetch [DB] –availability
Parameters:

code : str, required

the code of the database to query

Returns:

Series

Series of start dates by conid

Examples

Load start dates and display cumulative number of tickers available by start year:

>>> start_dates = get_history_availability("mydb")
>>> cum_ticker_counts = start_dates.groupby(start_dates.dt.year).count().cumsum()
>>> print(cum_ticker_counts)
StartDate
1984    420
1985    493
1986    539
1987    648
...
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,between_times,shard,no_config}

Create a new history database.

Example URI

PUT http://houston/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&between_times=09:30:00&shard=auto&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)

between_times
str (optional) Example: 09:30:00

limit to times between these two times (refers to the bar’s start time; mutually exclusive with times; should be passed exactly twice, once for start time and once for end time)

no_config
bool (required) Example: false

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

shard
str (optional) Example: auto

whether and how to shard the database, i.e. break it into smaller pieces. Possible choices are “time” (separate database for each bar time), “off” (no sharding), or “auto” (decide automatically based on bar size and universe size). Default “auto”.

Choices: time off auto

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/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/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,universes,start_date,end_date,availability_only,delist_missing}

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/history/queue?codes=japan-bank-eod&priority=false&conids=12345&universes=japan-bank&start_date=2016-06-01&end_date=&availability_only=false&delist_missing=
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 (typically used to fetch a subset of securities) (pass multiple times for multiple conids)

universes
str (optional) Example: japan-bank

fetch history for these universes, overriding config (typically used to fetch a subset of securities) (pass multiple times for multiple universes)

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

availability_only
bool (optional) Example: false

determine and store how far back data is available but don’t yet fetch the data

delist_missing
bool (optional) 

auto-delist securities that are no longer available from IB

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/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/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/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

Historical Market Data Availability

Query Historical Data Availability
GET/history/availability/{code}.{output}

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

Example URI

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

the code of the database to query

output
str (required) Example: csv

output format

Choices: csv json

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

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

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

Example URI

PATCH http://houston/history/availability/japan-bank-eod.
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/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/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/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,credentials,gui} ...
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)
credentials

set IB username/password and trading mode (paper/live)

usage: quantrocket launchpad credentials [-h] [-u USERNAME] [-p PASSWORD]
                                         [--paper | --live]
                                         SERVICE_NAME
Positional arguments:
gateway name of IB Gateway service to set credentials for (for example, ‘ibg1’)
Options:
-u, --username IB username (optional if only modifying trading mode)
-p, --password IB password (if omitted and user is provided, will be prompted for password)
--paper set trading mode to paper trading
--live set trading mode to live trading
gui

access the IB Gateway GUI in a web browser

usage: quantrocket launchpad gui [-h] [-g [SERVICE_NAME [SERVICE_NAME ...]]]
Options:
-g, --gateways limit to these IB Gateway services (default all IB Gateway services)
quantrocket.launchpad.get_credentials(gateway)

Returns IB username and trading mode (paper/live) for IB Gateway.

Parameters:

gateway : str, required

name of IB Gateway service to get credentials for (for example, ‘ibg1’)

Returns:

dict

credentials

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.open_ibg_gui(gateways=None)

Access the IB Gateway GUI in a web browser.

Note: IB Gateway must already be running.

Parameters:

gateways : list of str, optional

limit to these IB Gateway services (default all IB Gateway services)

Returns:

None

quantrocket.launchpad.set_credentials(gateway, username=None, password=None, trading_mode=None)

Set IB username/password and trading mode (paper/live) for IB Gateway.

Can be used to set new credentials or switch between paper and live trading (must have previously entered live credentials). Setting new credentials will restart IB Gateway and takes a moment to complete.

Parameters:

gateway : str, required

name of IB Gateway service to set credentials for (for example, ‘ibg1’)

username : str, optional

IB username (optional if only modifying trading environment)

password : str, optional

IB password (if omitted and username is provided, will be prompted for password)

trading_mode : str, optional

the trading mode to use (‘paper’ or ‘live’)

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/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/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/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/launchpad/config
Response  200
Headers
Content-Type: application/json
Body
{
  "ibg1": {
    "marketdata": {
      "STK": [
        "ASX",
        "ISLAND",
        "NYSE",
        "TSE"
      ]
    },
    "research": [
      "reuters",
      "wsh"
    ]
  },
  "ibg2": {
    "marketdata": {
      "STK": [
        "ISLAND",
        "NYSE"
      ],
      "FUT": [
        "GLOBEX"
      ]
    }
  }
}

Load Config
PUT/launchpad/config

Uploads a new config.

Example URI

PUT http://houston/launchpad/config
Request
Headers
Content-Type: application/x-yaml
Body
ibg1:
  marketdata:
    STK:
      - ASX
      - ISLAND
      - NYSE
      - TSE
ibg2:
  marketdata:
    STK:
      - ISLAND
      - TSEJ
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/ibg1/vnc
URI Parameters
gateway
str (required) Example: ibg1

the name of the IB Gateway service to connect to

Response  301

license-service

license service

QuantRocket license service CLI

usage: quantrocket license [-h] {get} ...
Sub-commands:
get

return the current license profile

usage: quantrocket license get [-h] [--force-refresh]
Options:
--force-refresh=False
 refresh the license profile before returning it (default is to return the cached profile, which is refreshed every few minutes)
quantrocket.license.get_license_profile(force_refresh=False)

Return the current license profile.

Parameters:

force_refresh : bool

refresh the license profile before returning it (default is to return the cached profile, which is refreshed every few minutes)

Returns:

dict

license profile

 

License API

License

License Profile

Get License Profile
GET/license-service/license{?force_refresh}

Return the current license profile.

Example URI

GET http://houston/license-service/license?force_refresh=false
URI Parameters
force_refresh
bool (optional) Example: false

refresh the license profile before returning it (default is to return the cached profile, which is refreshed every few minutes)

Response  200
Headers
Content-Type: application/json
Body
{
    'account': {
        'account_limit': '0 USD'
    },
    'exchanges': 'NYSE',
    'licensekey': 'YXV...............c4',
    'plan': {
        'currency': 'USD',
        'name': 'Flight Simulator'
    }
}

master

securities master service

QuantRocket securities master CLI

usage: quantrocket master [-h]
                          {exchanges,listings,options,get,diff,list-universes,universe,delete-universe,rollrules,delist,fetch-calendar,calendar,isopen,isclosed,ticksize}
                          ...
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 (pass ‘?’ or any invalid fieldname to see available 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

fetch-calendar

fetch upcoming trading hours for exchanges and save to securites master database

usage: quantrocket master fetch-calendar [-h] [-e [EXCHANGE [EXCHANGE ...]]]
Options:
-e, --exchanges
 limit to these exchanges
calendar

check whether exchanges are open or closed

usage: quantrocket master calendar [-h] [-t SEC_TYPE]
                                   [-i TIMEDELTA | -a TIMEDELTA] [-o]
                                   EXCHANGE [EXCHANGE ...]
Positional arguments:
exchanges the exchange(s) to check
Options:
-t, --sec-type

the security type, if needed to disambiguate for exchanges that trade multiple security types. Possible choices: %(choices)s

Possible choices: STK, FUT, CASH, OPT

-i, --in check whether exchanges will be open or closed at this point in the future (use Pandas timedelta string, e.g. 2h or 30min or 1d)
-a, --ago check whether exchanges were open or closed this long ago (use Pandas timedelta string, e.g. 2h or 30min or 1d)
-o=False, --outside-rth=False
 check extended hours calendar (default is to check regular trading hours calendar)
isopen

assert that one or more exchanges are open and exit non-zero if closed

usage: quantrocket master isopen [-h] [-t SEC_TYPE]
                                 [-i TIMEDELTA | -a TIMEDELTA]
                                 [-s FREQ | -u FREQ] [-o]
                                 EXCHANGE [EXCHANGE ...]
Positional arguments:
exchanges the exchange(s) to check
Options:
-t, --sec-type

the security type, if needed to disambiguate for exchanges that trade multiple security types. Possible choices: %(choices)s

Possible choices: STK, FUT, CASH, OPT

-i, --in assert that exchanges will be open at this point in the future (use Pandas timedelta string, e.g. 2h or 30min or 1d)
-a, --ago assert that exchanges were open this long ago (use Pandas timedelta string, e.g. 2h or 30min or 1d)
-s, --since assert that exchanges have been opened (as of –in or –ago if applicable) since at least this time (use Pandas frequency string, e.g. ‘W’ (week end), ‘M’ (month end), ‘Q’ (quarter end), ‘A’ (year end))
-u, --until assert that exchanges will be opened (as of –in or –ago if applicable) until at least this time (use Pandas frequency string, e.g. ‘W’ (week end), ‘M’ (month end), ‘Q’ (quarter end), ‘A’ (year end))
-o=False, --outside-rth=False
 check extended hours calendar (default is to check regular trading hours calendar)
isclosed

assert that one or more exchanges are closed and exit non-zero if open

usage: quantrocket master isclosed [-h] [-t SEC_TYPE]
                                   [-i TIMEDELTA | -a TIMEDELTA]
                                   [-s FREQ | -u FREQ] [-o]
                                   EXCHANGE [EXCHANGE ...]
Positional arguments:
exchanges the exchange(s) to check
Options:
-t, --sec-type

the security type, if needed to disambiguate for exchanges that trade multiple security types. Possible choices: %(choices)s

Possible choices: STK, FUT, CASH, OPT

-i, --in assert that exchanges will be closed at this point in the future (use Pandas timedelta string, e.g. 2h or 30min or 1d)
-a, --ago assert that exchanges were closed this long ago (use Pandas timedelta string, e.g. 2h or 30min or 1d)
-s, --since assert that exchanges have been closed (as of –in or –ago if applicable) since at least this time (use Pandas frequency string, e.g. ‘W’ (week end), ‘M’ (month end), ‘Q’ (quarter end), ‘A’ (year end))
-u, --until assert that exchanges will be closed (as of –in or –ago if applicable) until at least this time (use Pandas frequency string, e.g. ‘W’ (week end), ‘M’ (month end), ‘Q’ (quarter end), ‘A’ (year end))
-o=False, --outside-rth=False
 check extended hours calendar (default is to check regular trading hours calendar)
ticksize

round prices in a CSV to valid tick sizes

usage: quantrocket master ticksize [-h] -f INFILE -r FIELD [FIELD ...]
                                   [-d DIRECTION] [-a] [-o OUTFILE]
Options:
-f, --infile CSV file with prices to be rounded (specify ‘-‘ to read file from stdin)
-r, --round columns to be rounded
-d, --how

which direction to round to. Possible choices: up, down, nearest (default is ‘nearest’)

Possible choices: up, down, nearest

-a=False, --append-ticksize=False
 append a column of tick sizes for each field to be rounded
-o, --outfile filename to write the data to (default is stdout)
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 (pass [‘?’] or any invalid fieldname to see available 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_calendar(exchanges=None)

Fetch upcoming trading hours for exchanges and save to securites master database.

Parameters:

exchanges : list of str, optional

limit to these exchanges

Returns:

dict

status message

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_calendar_statuses(exchanges, sec_type=None, in_=None, ago=None, outside_rth=False)

Check whether exchanges are open or closed.

Parameters:

exchanges : list of str, required

the exchange(s) to check

sec_type : str, optional

the security type, if needed to disambiguate for exchanges that trade multiple security types. Possible choices: STK, FUT, CASH, OPT

in_ : str, optional

check whether exchanges will be open or closed at this point in the future (use Pandas timedelta string, e.g. 2h or 30min or 1d)

ago : str, optional

check whether exchanges were open or closed this long ago (use Pandas timedelta string, e.g. 2h or 30min or 1d)

outside_rth : bool

check extended hours calendar (default is to check regular trading hours calendar)

Returns:

dict

exchange calendar status

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

quantrocket.master.round_to_tick_sizes(infilepath_or_buffer, round_fields, how=None, append_ticksize=False, outfilepath_or_buffer=None)

Round prices in a CSV file to valid tick sizes.

CSV should contain columns ConId, Exchange, and the columns to be rounded (e.g. LmtPrice). Additional columns will be ignored and returned unchanged.

Parameters:

infilepath_or_buffer : str or file-like object, required

CSV file with prices to be rounded (specify ‘-‘ to read file from stdin)

round_fields : list of str, required

columns to be rounded

how : str, optional

which direction to round to. Possible choices: ‘up’, ‘down’, ‘nearest’ (default is ‘nearest’)

append_ticksize : bool

append a column of tick sizes for each field to be rounded (default False)

outfilepath_or_buffer : str or file-like object

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

Returns:

None

 

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/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/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/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/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/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/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/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/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/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/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/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/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"
}

Calendars

Fetch Calendars
POST/master/calendar{?exchanges}

Fetch upcoming trading hours for exchanges and save to securites master database.

Example URI

POST http://houston/master/calendar?exchanges=ARCA
URI Parameters
exchanges
str (optional) Example: ARCA

limit to these exchanges. Pass multiple times for multiple exchanges.

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

Get Exchange Status
GET/master/calendar{?exchanges,sec_type,in,ago}

Check whether exchanges are open or closed.

Example URI

GET http://houston/master/calendar?exchanges=ARCA&sec_type=STK&in=1h&ago=30min
URI Parameters
exchanges
str (required) Example: ARCA

the exchange(s) to check. Pass multiple times for multiple exchanges.

sec_type
str (optional) Example: STK

the security type, if needed to disambiguate for exchanges that trade multiple security types.

Choices: STK FUT CASH OPT

in
str (optional) Example: 1h

check whether exchanges will be open or closed at this point in the future (use Pandas timedelta string, e.g. 2h or 30min or 1d)

ago
str (optional) Example: 30min

check whether exchanges were open or closed this long ago (use Pandas timedelta string, e.g. 2h or 30min or 1d)

Request
Headers
Content-Type: application/json
Body
{
  "ARCA": {
    "status": "open",
    "since": "2018-05-10T09:30:00",
    "until": "2018-05-10T16:00:00",
    "timezone": "America/New_York"
  }
}

Tick Sizes

Round prices
GET/master/ticksizes{?round_fields,how,append_ticksize}

Round prices in a CSV file to valid tick sizes.

CSV should contain columns ConId, Exchange, and the columns to be rounded (e.g. LmtPrice). Additional columns will be ignored and returned unchanged.

Example URI

GET http://houston/master/ticksizes?round_fields=LmtPrice&how=nearest&append_ticksize=true
URI Parameters
round_fields
str (required) Example: LmtPrice

columns to be rounded. Pass multiple times for multiple columns.

how
str (optional) Example: nearest

which direction to round to. Default ‘nearest’.

Choices: up down nearest

append_ticksize
boolean (optional) Example: true

append a column of tick sizes for each field to be rounded (default False)

Request
Headers
Content-Type: text/csv
Body
ConId,Account,Action,OrderRef,TotalQuantity,Exchange,OrderType,Tif,LmtPrice
13905888,DU12345,BUY,japan-strategy,1000,SMART,LMT,DAY,15203.1135
13905888,DDU12345,BUY,japan-strategy,1000,TSEJ,LMT,DAY,15203.1135
Response  200
Headers
Content-Type: text/csv
Body
ConId,Account,Action,OrderRef,TotalQuantity,Exchange,OrderType,Tif,LmtPrice
13905888,DU12345,BUY,japan-strategy,1000,SMART,LMT,DAY,15203.0
13905888,DDU12345,BUY,japan-strategy,1000,TSEJ,LMT,DAY,15205.0

moonshot

Moonshot backtesting and trading engine

moonshot-client

Moonshot client

QuantRocket Moonshot CLI

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

backtest one or more strategies

usage: quantrocket moonshot backtest [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD]
                                     [-g FREQ]
                                     [-l [CODE:FLOAT [CODE:FLOAT ...]]]
                                     [-n [CURRENCY:NLV [CURRENCY:NLV ...]]]
                                     [-p [PARAM:VALUE [PARAM:VALUE ...]]] [-d]
                                     [--pdf] [-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)
-g, --segment backtest in date segments of this size, to reduce memory usage (use Pandas frequency string, e.g. ‘A’ for annual segments or ‘Q’ for quarterly segments)
-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)
--pdf return a PDF performance tear sheet (default is to return a CSV of performance results)
-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]
                                      [-g FREQ] -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 ...]]]
                                      [--pdf] [-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)
-g, --segment backtest in date segments of this size, to reduce memory usage (use Pandas frequency string, e.g. ‘A’ for annual segments or ‘Q’ for quarterly segments)
-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’)
--pdf return a PDF tear sheet of results (default is to return a CSV)
-o, --outfile the location to write the results file (omit to write to stdout)
trade

run one or more strategies and generate orders.

usage: quantrocket moonshot trade [-h] [-a [ACCOUNT [ACCOUNT ...]]]
                                  [-r YYYY-MM-DD] [-j] [-o FILEPATH]
                                  CODE [CODE ...]
Positional arguments:
strategies one or more strategy codes
Options:
-a, --accounts limit to these accounts
-r, --review-date
 generate orders as if it were this date, rather than using today’s date
-j, --json format orders as JSON (default is CSV)
-o, --outfile the location to write the orders file (omit to write to stdout)
quantrocket.moonshot.backtest(strategies, start_date=None, end_date=None, segment=None, allocations=None, nlv=None, params=None, details=None, output='csv', csv=None, filepath_or_buffer=None)

Backtest one or more strategies.

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

If testing multiple strategies, each column in the CSV represents a strategy. If testing a single strategy and details=True, each column in the CSV represents a security in the strategy universe.

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)

segment : str, optional

backtest in date segments of this size, to reduce memory usage (use Pandas frequency string, e.g. ‘A’ for annual segments or ‘Q’ for quarterly segments)

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)

output : str, required

the output format (choices are csv or pdf)

csv : bool

DEPRECATED: this argument will be removed in a future version. This argument may be omitted as CSV is the default.

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, segment=None, param1=None, vals1=None, param2=None, vals2=None, allocations=None, nlv=None, params=None, output='csv', csv=None, filepath_or_buffer=None)

Run a parameter scan for one or more strategies.

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

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)

segment : str, optional

backtest in date segments of this size, to reduce memory usage (use Pandas frequency string, e.g. ‘A’ for annual segments or ‘Q’ for quarterly segments)

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})

output : str, required

the output format (choices are csv or pdf)

csv : bool

DEPRECATED: this argument will be removed in a future version. This argument may be omitted as CSV is the default.

filepath_or_buffer : str, optional

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

Returns:

None

quantrocket.moonshot.trade(strategies, accounts=None, review_date=None, output='csv', filepath_or_buffer=None)

Run one or more strategies and generate orders.

Allocations are read from configuration (quantrocket.moonshot.allocations.yml).

Parameters:

strategies : list of str, required

one or more strategy codes

accounts : list of str, optional

limit to these accounts

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

generate orders as if it were this date, rather than using today’s date

output : str, required

the output format (choices are csv or json)

filepath_or_buffer : str, optional

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

Returns:

None

 

Moonshot API

Moonshot

Backtests

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

Backtest one or more strategies and return a CSV of backtest results or a PDF tear sheet of performance charts.

If testing multiple strategies, each column in the CSV represents a strategy. If testing a single strategy and details=True, each column in the CSV represents a security in the strategy universe.

Example URI

POST http://houston/moonshot/backtests.csv?strategies=umd-nyse&start_date=2015-02-01&end_date=2017-06-06&segment=A&allocations=umd-nyse:0.25&nlv=USD:500000&params=BENCHMARK:None&details=true
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)

segment
str (optional) Example: A

backtest in date segments of this size, to reduce memory usage (use Pandas frequency string, e.g. ‘A’ for annual segments or ‘Q’ for quarterly segments)

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)

output
str (required) Example: csv

the output format (choices are csv or pdf)

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

Parameter Scans

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

Run a parameter scan for one or more strategies and return a PDF tear sheet of results or a CSV.

Example URI

POST http://houston/moonshot/paramscans.csv?strategies=umd-nyse&start_date=2015-02-01&end_date=2017-06-06&segment=A&param1=SMAVG_WINDOW&vals1=20&param2=LMAVG_WINDOW&vals2=180&allocations=umd-nyse:0.25&nlv=USD:500000&params=BENCHMARK:None
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)

segment
str (optional) Example: A

backtest in date segments of this size, to reduce memory usage (use Pandas frequency string, e.g. ‘A’ for annual segments or ‘Q’ for quarterly segments)

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)

output
str (required) Example: csv

the output format (choices are csv or pdf)

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

Orders

Generate Orders
GET/moonshot/orders.{output}{?strategies,accounts,review_date}

Run one or more strategies and generate orders. Allocations are read from configuration (quantrocket.moonshot.allocations.yml).

Example URI

GET http://houston/moonshot/orders.csv?strategies=umd-nyse&accounts=U12345&review_date=2018-05-18
URI Parameters
strategies
str (required) Example: umd-nyse

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

accounts
str (optional) Example: U12345

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

review_date
str (optional) Example: 2018-05-18

generate orders as if it were this date, rather than using today’s date

output
str (required) Example: csv

the output format (choices are csv or json)

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

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]
                                  [-s SERVICE_NAME]
                                  CMD
Positional arguments:
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)
-s=satellite, --service=satellite
 the service name (default ‘satellite’)
quantrocket.satellite.execute_command(cmd, return_file=None, filepath_or_buffer=None, service='satellite')

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

Parameters:

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)

service : str, optional

the service name (default ‘satellite’)

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/satellite/commands?cmd=python%20%2Fcodeload%2Fbacktrader%2Fdual_moving_average.py&return_file=%2Ftmp%2Fbacktrader-plot.pdf
URI Parameters
service
str (required) Example: satellite

the service name

cmd
str (required) Example: python%20%2Fcodeload%2Fbacktrader%2Fdual_moving_average.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/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/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/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/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/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"
]