Database
Classes
QuantmodDB
QuantmodDB
Python SDK for registering instruments, ingesting OHLCV price data, and retrieving historical market data from Supabase.
Assumptions:
- Supabase tables instruments and prices already exist
- UNIQUE constraint on instruments.symbol
- UNIQUE constraint on prices (instrument_id, date)
- RLS disabled OR service-role key is used
- getData() returns DataFrame indexed by datetime with
Open, High, Low, Close, Volume columns
Functions
get_asset_prices
get_asset_prices(symbols: Optional[Union[str, List[str]]] = None, start_date: Optional[str] = None, end_date: Optional[str] = None, column: str = 'close') -> pd.DataFrame
Retrieve OHLCV data in wide format (symbols as columns).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str | list[str]
|
Filter by symbol(s) |
None
|
start_date
|
str
|
Start date filter (YYYY-MM-DD) |
None
|
end_date
|
str
|
End date filter (YYYY-MM-DD) |
None
|
column
|
str
|
Price column to pivot ('open', 'high', 'low', 'close', 'volume') |
'close'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Index: date, Columns: symbols |
get_instrument_id
Get instrument ID for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Instrument symbol |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Instrument ID if found, None otherwise |
get_latest_prices
Get the most recent price for each symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str | list[str]
|
Filter by symbol(s) |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Latest price record for each symbol |
get_prices
get_prices(symbols: Optional[Union[str, List[str]]] = None, start_date: Optional[str] = None, end_date: Optional[str] = None, limit: Optional[int] = None) -> pd.DataFrame
Retrieve OHLCV data in long format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str | list[str]
|
Filter by symbol(s). If None, returns all. |
None
|
start_date
|
str
|
Start date filter (YYYY-MM-DD) |
None
|
end_date
|
str
|
End date filter (YYYY-MM-DD) |
None
|
limit
|
int
|
Maximum number of records to return |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns: date, open, high, low, close, volume, symbol Sorted by date ascending |
list_instruments
list_instruments(symbols: Optional[Union[str, List[str]]] = None, exchange: Optional[str] = None, asset_class: Optional[str] = None) -> pd.DataFrame
List registered instruments with optional filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str | list[str]
|
Filter by specific symbol(s) |
None
|
exchange
|
str
|
Filter by exchange |
None
|
asset_class
|
str
|
Filter by asset class |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Registered instruments with metadata |
load_history
load_history(symbols: Union[str, List[str]], start_date: str, end_date: Optional[str] = None) -> Dict[str, int]
Load historical OHLCV data for one or multiple symbols.
All symbols MUST be registered before loading data. Use register() first to add instruments with metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str | list[str]
|
Symbol(s) to load data for (must be pre-registered) |
required |
start_date
|
str
|
Start date in YYYY-MM-DD format |
required |
end_date
|
str
|
End date in YYYY-MM-DD format (defaults to today) |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
{symbol: num_records_loaded} |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any symbol is not registered |
register
Register one or multiple instruments with metadata. Idempotent: existing symbols are updated with new metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instruments
|
dict | list[dict]
|
Instrument(s) to register. Each dict must contain 'symbol'. Optional keys: name, exchange, asset_class, instrument_type |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Instrument IDs (existing or newly created) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If instrument dict is missing 'symbol' key |