Skip to main content

Example Queries

Last Known Value

A query without date parameters retrieves the most recent available data.
import liberator

liberator.url = 'https://api.cloudquant.ai'
res = liberator.query(name='daily_bars')
df = liberator.get_dataframe(res)
df[['symbol', 'timestamp', 'open', 'high', 'low', 'close', 'volume']]
Rather than displaying the entire result, you can select specific columns or pass a fields parameter to include only the data you need. Some key fields are returned automatically.

Time Series Queries

Two date parameters control historical data retrieval:
  • as_of — Retrieve data from any past date showing information as known on that date. Defaults to current time. Format: YYYY-MM-DD HH:MM:SS (time optional).
  • back_to — Specifies where the returned dataset begins. Reads all data “back to” the specified date. Format: YYYY-MM-DD HH:MM:SS (time optional).
If as_of and back_to are identical, the result will not be a time series.
df = liberator.get_dataframe(liberator.query(
    name='daily_bars',
    as_of='2020-11-15',
    symbols=['FB', 'AAPL', 'NFLX', 'GOOG', 'MSFT', 'IBM']))

Query All Symbols

Omit the symbols parameter to retrieve all symbols in a dataset.
df = liberator.get_dataframe(liberator.query(
    name='daily_bars',
    as_of='2020-11-15'))

Query a Live Dataset

Set the as_of parameter to "live" for real-time data streaming.
res = liberator.query(name='live_nasdaq_composite', as_of='live')

for batch in res:
    df = batch.to_pandas()
    print(df)

Query Stats as JSON

Setting the stats parameter to "total" returns a JSON result with the count per symbol instead of data rows.
res = liberator.query(
    name='daily_bars',
    as_of='2021-04-10',
    back_to='2021-03-10',
    symbols=['ES'],
    stats='total'
)

Get DataFrame / Table

Convert query results into a tabular format native to your language.
df = liberator.get_dataframe(
    liberator.query(name='daily_bars', as_of='2020-11-15', symbols=['AAPL'])
)