API Reference
SpiceClient(apiKey, url)
The top-level object that connects to Spice.ai
apiKey
(string, required): API key to authenticate with the endpointurl
(string, optional): URL of the endpoint to use (default: flight.spiceai.io:443)
SpiceClient Methods
query(queryText: string, onData: (partialData: Table) => void) => Table
queryText
: (string, required): The SQL query to executeonData
: (callback, optional): The callback function that is used for handling streaming data.
query
returns an Apache Arrow Table.
To get the data in JSON format, iterate over each row by calling toArray()
on the table and call toJSON()
on each row.
Get all of the elements for a column by calling getChild(name: string)
and then calling toJSON()
on the result.
getLatestPrices(pairs: string[]) => LatestPrices
pairs
: (Array of string, required): The crypto/currency pairs, for example ["BTC-USD", "USD-ETH"].
getLatestPrices
returns the latest prices for a list of asset pairs. getLatestPrices
returns
Example API query
getPrices(pair: string[], startTime?: number, endTime?: number, granularity?: string) => HistoricalPrices
pairs
: (Array of string, required): The crypto/currency pairs, for example ["BTC-USD", "USD-ETH"].startTime
: start time milliseconds since Unix EpochendTime
: end time milliseconds since Unix Epochgranularity
: valid duration
getPrices
returns prices for a list of asset pairs for a given period of time. getPrices
returns
Example API Query
Last updated