Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions content/quantrocket/docs/account/python/DOC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: account
description: "QuantRocket Account module - query account balances, portfolio holdings, and exchange rates"
metadata:
languages: "python"
versions: "2.11.0.0"
revision: 1
updated-on: "2026-03-19"
source: community
tags: "quantrocket,account,balance,portfolio,exchange-rates"
---

# quantrocket.account

Query account balances, portfolio holdings, and exchange rates.

## Import

```python
from quantrocket.account import (
download_account_balances,
download_account_portfolio,
download_exchange_rates,
)
```

## Account Balances

```python
from quantrocket.account import download_account_balances

download_account_balances(filepath_or_buffer="/tmp/balances.csv", latest=True)

download_account_balances(
filepath_or_buffer="/tmp/balances.csv",
start_date="2024-01-01",
accounts=["DU12345"],
fields=["NetLiquidation", "BuyingPower", "Cushion"],
)

# Alert if cushion below threshold
download_account_balances(
filepath_or_buffer="/tmp/alert.csv",
below={"Cushion": 0.05},
latest=True,
)
```

**Common fields:** `"NetLiquidation"`, `"BuyingPower"`, `"Cushion"`, `"EquityWithLoanValue"`, `"GrossPositionValue"`, `"MaintMarginReq"`, `"TotalCashValue"`, `"UnrealizedPnL"`, `"RealizedPnL"` (40+ available)

## Portfolio

```python
from quantrocket.account import download_account_portfolio

download_account_portfolio(filepath_or_buffer="/tmp/portfolio.csv")

download_account_portfolio(
filepath_or_buffer="/tmp/portfolio.csv",
brokers=["alpaca"],
fields=["Position", "MarketValue", "AverageCost", "UnrealizedPnl"],
include_zero=True,
)
```

**brokers:** `"alpaca"`, `"ibkr"`

## Exchange Rates

```python
from quantrocket.account import download_exchange_rates

download_exchange_rates(filepath_or_buffer="/tmp/fx.csv", latest=True)
download_exchange_rates(
filepath_or_buffer="/tmp/fx.csv",
start_date="2024-01-01",
base_currencies=["AUD"],
quote_currencies=["USD"],
)
```

## CLI Equivalents

```bash
quantrocket account balance --latest -o balances.csv
quantrocket account portfolio -o portfolio.csv
quantrocket account rates --latest -o fx.csv
```
128 changes: 128 additions & 0 deletions content/quantrocket/docs/blotter/python/DOC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
name: blotter
description: "QuantRocket Blotter module - place orders, track positions, cancel orders, download executions, and query PnL"
metadata:
languages: "python"
versions: "2.11.0.0"
revision: 1
updated-on: "2026-03-19"
source: community
tags: "quantrocket,blotter,orders,positions,executions,pnl,trading"
---

# quantrocket.blotter

Place and manage orders, track positions and executions, query PnL.

## Import

```python
from quantrocket.blotter import (
place_orders,
cancel_orders,
download_order_statuses,
download_positions,
list_positions,
close_positions,
download_executions,
record_executions,
apply_split,
download_pnl,
read_pnl_csv,
)
```

## Place Orders

```python
from quantrocket.blotter import place_orders

order_ids = place_orders(orders=[{
"Sid": "FIBBG000BDTBL9",
"Action": "BUY", # BUY or SELL
"Exchange": "SMART",
"TotalQuantity": 100,
"OrderType": "MKT", # MKT, LMT, STP, etc.
"Tif": "DAY", # DAY, GTC, IOC, OPG
"Account": "DU12345",
"OrderRef": "my-strategy", # tags order for tracking
}])

# Limit order
order_ids = place_orders(orders=[{
"Sid": "FIBBG000BDTBL9",
"Action": "BUY",
"Exchange": "SMART",
"TotalQuantity": 100,
"OrderType": "LMT",
"LmtPrice": 590.50,
"Tif": "DAY",
"Account": "DU12345",
"OrderRef": "my-strategy",
}])
```

**Required fields:** `Sid`, `Action`, `Exchange`, `TotalQuantity`, `OrderType`, `Tif`, `Account`, `OrderRef`

## Positions

```python
from quantrocket.blotter import list_positions, download_positions, close_positions

positions = list_positions(order_refs=["my-strategy"])
# Returns: [{"Account": "DU12345", "Sid": "...", "Quantity": 100, ...}]

download_positions(filepath_or_buffer="/tmp/positions.csv", order_refs=["my-strategy"])
download_positions(filepath_or_buffer="/tmp/broker_pos.csv", view="broker")

# Generate close orders (does NOT place them)
close_positions(filepath_or_buffer="/tmp/close_orders.csv", order_refs=["my-strategy"])
```

## Orders and Cancellations

```python
from quantrocket.blotter import download_order_statuses, cancel_orders

download_order_statuses(filepath_or_buffer="/tmp/orders.csv", order_refs=["my-strategy"])
download_order_statuses(filepath_or_buffer="/tmp/open.csv", open_orders=True)

cancel_orders(order_refs=["my-strategy"])
cancel_orders(sids=["FIBBG000BDTBL9"])
cancel_orders(cancel_all=True)
```

**Order statuses:** `"Submitted"`, `"Filled"`, `"Cancelled"`, `"Error"`, `"Inactive"`

## Executions and PnL

```python
from quantrocket.blotter import download_executions, download_pnl, read_pnl_csv

download_executions(filepath_or_buffer="/tmp/executions.csv", order_refs=["my-strategy"])

download_pnl(filepath_or_buffer="/tmp/pnl.csv", order_refs=["my-strategy"])
download_pnl(filepath_or_buffer="/tmp/pnl.csv", details=True) # detailed
download_pnl(filepath_or_buffer="/tmp/tearsheet.pdf", output="pdf") # PDF tearsheet

pnl = read_pnl_csv("/tmp/pnl.csv") # MultiIndex (Field, Date) DataFrame
returns = pnl.loc["Return"]
```

## Stock Splits

```python
from quantrocket.blotter import apply_split
apply_split(sid="FIBBG000BDTBL9", old_shares=1, new_shares=4)
```

## CLI Equivalents

```bash
quantrocket blotter order -f orders.csv
quantrocket blotter status --order-refs 'my-strategy' -o statuses.csv
quantrocket blotter cancel --order-refs 'my-strategy'
quantrocket blotter positions --order-refs 'my-strategy' -o positions.csv
quantrocket blotter executions --order-refs 'my-strategy' -o executions.csv
quantrocket blotter pnl --order-refs 'my-strategy' -o pnl.csv
```
65 changes: 65 additions & 0 deletions content/quantrocket/docs/countdown/python/DOC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: countdown
description: "QuantRocket Countdown module - crontab scheduling service timezone management and conditional scheduling"
metadata:
languages: "python"
versions: "2.11.0.0"
revision: 1
updated-on: "2026-03-19"
source: community
tags: "quantrocket,countdown,crontab,scheduling,timezone"
---

# quantrocket.countdown

Crontab scheduling service and timezone management.

## Import

```python
from quantrocket.countdown import get_timezone, set_timezone
```

## Timezone

```python
from quantrocket.countdown import get_timezone, set_timezone

tz = get_timezone()
set_timezone("America/New_York")
tz = get_timezone(service="countdown-usa") # specific service
```

## Crontab Management

Crontab is managed via file, not Python API. The countdown service auto-loads the crontab file.

### Crontab syntax

```bash
# minute hour day month weekday command

# Run at 14:30 UTC, Mon-Fri
30 14 * * mon-fri quantrocket satellite exec 'mypackage.mymodule.my_function'

# Conditional: only if NYSE is open
0 14 * * mon-fri quantrocket master isopen 'XNYS' && quantrocket satellite exec 'mypackage.run'

# Conditional: only if NYSE will be open in 30 minutes
30 9 * * mon-fri quantrocket master isopen 'XNYS' --in '30min' && quantrocket satellite exec 'mypackage.run'
```

### Validate

```bash
quantrocket countdown validate
```

## CLI Equivalents

```bash
quantrocket countdown timezone
quantrocket countdown timezone 'America/New_York'
quantrocket countdown validate
quantrocket countdown crontab
```
89 changes: 89 additions & 0 deletions content/quantrocket/docs/db/python/DOC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: db
description: "QuantRocket DB module - database management, S3 backup/restore, SQLite utilities, and disk space management"
metadata:
languages: "python"
versions: "2.11.0.0"
revision: 1
updated-on: "2026-03-19"
source: community
tags: "quantrocket,database,sqlite,s3,backup,restore"
---

# quantrocket.db

Database management: list databases, S3 backup/restore, SQLite utilities.

## Import

```python
from quantrocket.db import (
list_databases,
get_s3_config,
set_s3_config,
s3_push_databases,
s3_pull_databases,
optimize_databases,
connect_sqlite,
insert_or_fail,
insert_or_replace,
insert_or_ignore,
)
```

## List Databases

```python
from quantrocket.db import list_databases

dbs = list_databases() # {"sqlite": [...], "postgres": [...]}
dbs = list_databases(services=["history"]) # filter by service
dbs = list_databases(detail=True) # include size, path
```

## S3 Backup/Restore

```python
from quantrocket.db import set_s3_config, s3_push_databases, s3_pull_databases

set_s3_config(
access_key_id="AKIA...", secret_access_key="...",
bucket="my-backups", region="us-east-1",
)

s3_push_databases()
s3_push_databases(services=["history"], codes=["my-db"])
s3_pull_databases()
s3_pull_databases(force=True) # overwrite local
```

## SQLite Utilities

```python
from quantrocket.db import connect_sqlite, insert_or_replace, insert_or_ignore
import pandas as pd

engine = connect_sqlite("/path/to/database.sqlite") # SQLAlchemy engine
df = pd.read_sql("SELECT * FROM my_table LIMIT 10", engine)
insert_or_replace(df, "my_table", engine)
insert_or_ignore(df, "my_table", engine)
```

## Optimize

```python
from quantrocket.db import optimize_databases
optimize_databases() # VACUUM all
optimize_databases(services=["history"]) # specific service
```

## CLI Equivalents

```bash
quantrocket db list
quantrocket db list --services 'history' --detail
quantrocket db s3config --access-key-id 'AKIA...' --bucket 'my-backups'
quantrocket db s3-push
quantrocket db s3-pull --force
quantrocket db optimize
```
Loading