quantrocket.account
QuantRocket account CLI
usage: quantrocket account [-h] {balance,portfolio,rates} ...
subcommands¶
- subcommand
Possible choices: balance, portfolio, rates
Sub-commands:¶
balance¶
query account balances
quantrocket account balance [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-l]
[-a [ACCOUNT [ACCOUNT ...]]]
[-b [FIELD:AMOUNT [FIELD:AMOUNT ...]]]
[-o OUTFILE] [-j] [-f [FIELD [FIELD ...]]]
[--force-refresh]
Named Arguments¶
- --force-refresh
refresh account balances to ensure the latest data (default is to query the database, which is refreshed every minute)
Default: False
filtering options¶
- -s, --start-date
limit to account balance snapshots taken on or after this date
- -e, --end-date
limit to account balance snapshots taken on or before this date
- -l, --latest
return the latest account balance snapshot
Default: False
- -a, --accounts
limit to these accounts
- -b, --below
limit to accounts where the specified field is below the specified amount (pass as field:amount, for example Cushion:0.05)
output options¶
- -o, --outfile
filename to write the data to (default is stdout)
- -j, --json
format output as JSON (default is CSV)
- -f, --fields
only return these fields. By default a core set of fields is returned. Pass a list of fields, or ‘*’ to return all fields. Pass ‘?’ or any invalid fieldname to see available fields.
Query account balances.
Examples:
Query the latest account balances.
quantrocket account balance --latest
Query the latest NLV (Net Liquidation Value) for a particular account:
quantrocket account balance --latest --fields NetLiquidation --accounts U123456
Check for accounts that have fallen below a 5% cushion and log the results, if any, to flightlog:
quantrocket account balance --latest --below Cushion:0.05 | quantrocket flightlog log --name quantrocket.account --level CRITICAL
Query historical account balances over a date range:
quantrocket account balance --start-date 2017-06-01 --end-date 2018-01-31
portfolio¶
download current portfolio
quantrocket account portfolio [-h] [-b [BROKER [BROKER ...]]]
[-a [ACCOUNT [ACCOUNT ...]]]
[-t [SEC_TYPE [SEC_TYPE ...]]]
[-e [EXCHANGE [EXCHANGE ...]]]
[-i [SID [SID ...]]] [-s [SYMBOL [SYMBOL ...]]]
[-z] [-o OUTFILE] [-j] [-f [FIELD [FIELD ...]]]
filtering options¶
- -b, --brokers
Possible choices: alpaca, ibkr
limit to these brokers. Possible choices: [‘alpaca’, ‘ibkr’]
- -a, --accounts
limit to these accounts
- -t, --sec-types
limit to these security types
- -e, --exchanges
limit to these exchanges
- -i, --sids
limit to these sids
- -s, --symbols
limit to these symbols
- -z, --zero
include zero position rows (default is to exclude them). Only supported for Interactive Brokers.
Default: False
output options¶
- -o, --outfile
filename to write the data to (default is stdout)
- -j, --json
format output as JSON (default is CSV)
- -f, --fields
only return these fields. By default a core set of fields is returned. Pass a list of fields, or ‘*’ to return all fields. Pass ‘?’ or any invalid fieldname to see available fields.
Download current portfolio.
Examples:
View current portfolio in terminal:
quantrocket account portfolio | csvlook
Download current portfolio for a particular account and save to file:
quantrocket account portfolio --accounts U12345 -o portfolio.csv
rates¶
query exchange rates for the base currency
quantrocket account rates [-h] [-s YYYY-MM-DD] [-e YYYY-MM-DD] [-l]
[-b [CURRENCY [CURRENCY ...]]]
[-q [CURRENCY [CURRENCY ...]]] [-o OUTFILE] [-j]
filtering options¶
- -s, --start-date
limit to exchange rates on or after this date
- -e, --end-date
limit to exchange rates on or before this date
- -l, --latest
return the latest exchange rates
Default: False
- -b, --base-currencies
limit to these base currencies
- -q, --quote-currencies
limit to these quote currencies
output options¶
- -o, --outfile
filename to write the data to (default is stdout)
- -j, --json
format output as JSON (default is CSV)
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.
Examples:
Query the latest exchange rates.
quantrocket account rates --latest
- 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 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 or csv, 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. By default a core set of fields is returned. Pass a list of fields, or ‘*’ to return all fields. Pass [‘?’] or any invalid fieldname to see available fields.
force_refresh (bool) – refresh account balances to ensure the latest data (default is to query the database, which is refreshed every minute)
- Return type:
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', brokers=None, accounts=None, sec_types=None, exchanges=None, sids=None, symbols=None, include_zero=False, fields=None)¶
Download current 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)
brokers (list of str, optional) – limit to these brokers. Possible choices: alpaca, ibkr
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
sids (list of str, optional) – limit to these sids
symbols (list of str, optional) – limit to these symbols
include_zero (bool) – include zero position rows (default is to exclude them). Only supported for Interactive Brokers.
fields (list of str, optional) – only return these fields. By default a core set of fields is returned. Pass a list of fields, or ‘*’ to return all fields. Pass ‘?’ or any invalid fieldname to see available fields.
- Return type:
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, 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
- Return type:
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
Resource Group ¶
Account Balances ¶
Get Account BalancesGET/account/balances.{output}{?start_date,end_date,latest,accounts,below,fields,force_refresh}
Query account balances.
Example URI
- output
str
(required) Example: csvoutput format
Choices:
csv
json
- start_date
str
(optional) Example: 2017-01-01limit to account balance snapshots taken on or after this date
- end_date
str
(optional) Example: 2018-01-01limit to account balance snapshots taken on or before this date
- latest
bool
(optional) Example: truereturn the latest account balance snapshot
- accounts
str
(optional) Example: U123456limit to these accounts (pass multiple times for multiple accounts)
- below
str
(optional) Example: Cushion:0.05limit 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: NetLiquidationonly return these fields (pass ‘?’ or any invalid fieldname to see available fields) (pass multiple times for multiple fields)
- force_refresh
bool
(optional) Example: truerefresh account balances to ensure the latest data (default is to query the database, which is refreshed every minute)
200
Headers
Content-Type: text/csv
Body
Broker,Account,Currency,NetLiquidation,LastUpdated
ibkr,DU123456,USD,500000.0,"2017-12-16 14:28:54"
Exchange rates ¶
Get Exchange RatesGET/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
- output
str
(required) Example: csvoutput format
Choices:
csv
json
- start_date
str
(optional) Example: 2017-01-01limit to exchange rates on or after this date
- end_date
str
(optional) Example: 2018-01-01limit to exchange rates on or before this date
- latest
bool
(optional) Example: truereturn the latest exchange rates
- base_currencies
str
(optional) Example: USDlimit to these base currencies (pass multiple times for multiple base currencies)
- quote_currencies
str
(optional) Example: CADlimit to these quote currencies (pass multiple times for multiple quote currencies)
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
Account Portfolio ¶
Get Account PortfolioGET/account/portfolio.{output}{?brokers,accounts,sec_types,exchanges,sids,symbols,include_zero,fields}
Download current portfolio.
Example URI
- output
str
(required) Example: csvoutput format
Choices:
csv
json
- brokers
str
(optional) Example: ibkrlimit to these brokers.
Choices:
alpaca
ibkr
- accounts
str
(optional) Example: U12345limit to these accounts
- sec_types
str
(optional) Example: STKlimit to these security types
- exchanges
str
(optional) Example: XNYSlimit to these exchanges
- sids
str
(optional) Example: FI12345limit to these sids
- symbols
str
(optional) Example: AAPLlimit to these symbols
- include_zero
bool
(optional) Example: trueinclude zero position rows (default is to exclude them). Only supported for Interactive Brokers.
- fields
str
(optional) Example: Sidonly return these fields. By default a core set of fields is returned. Pass a list of fields, or ‘*’ to return all fields. Pass ‘?’ or any invalid fieldname to see available fields.
200
Headers
Content-Type: text/csv