Query a table to JSON¶
Goal: pull a Center table out from an external script and work with it as data: a curl check, then a Python example that loads the result into a pandas DataFrame for ad-hoc analysis.
This is the everyday analyst path: positions, fills, or quotes in your notebook without exporting anything by hand.
Prerequisites¶
- The REST
QUERYendpoint is enabled (ami.rest.plugin.classes=*): see Configuration. - A table to read. This example uses
QUOTES(SYM,bid,ask,last,volume); the Quickstart creates it.
1. Check it from the command line¶
Ask for jsonMaps: the format that returns each table as a list of row objects, which is the easiest to consume:
The response looks like:
The rows are under tables.<title>; the title matches the table (or the query's output name). With jsonMaps, tables is an object you index by name (tables["QUOTES"]), and the keys inside each row are alphabetized, not in SELECT order.
2. Load it into pandas¶
df is now a normal DataFrame: filter, aggregate, join with other sources, or write it to a file. Because this is a plain GET, the same call works from any language or from a scheduled job that pulls an end-of-day extract.
Tips¶
- Narrow the query, not the client. Push filtering and aggregation into
cmd(WHERE,GROUP BY) so you transfer only what you need; raiselimitonly when you truly want more than 10,000 rows. - Pick the format for the consumer, and mind the container.
jsonMapsreturnstablesas an object keyed by table name;jsonRowsandjsonreturntablesas an array of table objects. Switching format means changing how you reach the rows (body["tables"]["QUOTES"]vsbody["tables"][0]). UsejsonRows/jsonwhen you need columns in declared order (jsonMapsalphabetizes keys);pipefor a quick shell split. - This is a point-in-time pull. If you need to keep watching the table as it changes, use the WebSocket streaming API instead.