# OneTick Cloud KDB-X Module

_This page explains what the OneTick Cloud KDB-X module is, how it works, and when to use it._

[OneTick](https://www.onetick.com/onetick-tick-analytics-platform) is a time-series data management and analytics platform for financial market data. The [OneTick Cloud REST API](https://www.onetick.com/cloud-services/rest-api-end-point-documentation) lets applications submit SQL queries against the real-time and historical datasets available to an account and retrieve results over HTTPS.

The OneTick Cloud KDB-X module connects KDB-X to this API. It lets you submit OneTick SQL from q and receive the main query result as a q table for analysis, transformation, or storage.

## How it works

When you call [`.otc.sql_rest`](reference.md#otcsql_rest), the module:

1. Uses the configured OAuth 2.0 client credentials to request an access token.
2. Submits the SQL statement to the OneTick REST API over HTTPS.
3. Requests the response as an [Apache Arrow interprocess communication (IPC) stream](https://arrow.apache.org/docs/format/Columnar.html#serialization-and-interprocess-communication-ipc), using gzip compression when `zlib` is available to KDB-X. Otherwise, the module requests an uncompressed response and prints a warning.
4. Converts OneTick's main query-result message, `PROCESS_EVENT`, into a q table.
5. Removes OneTick transport columns and converts timestamps and strings to q types.

The module caches the access token for the q session. If OneTick returns HTTP status `401`, the module obtains a new token and retries the request once.

## Key features

The OneTick Cloud KDB-X module:

- Supports the packaged OneTick demonstration credentials or subscriber-provided OAuth 2.0 credentials.
- Accepts a SQL string or a dictionary containing SQL and an [IANA time zone identifier](https://www.iana.org/time-zones).
- Converts Arrow IPC responses directly to q tables.
- Converts time columns to q timestamps and commonly repeated strings to symbols.

## When to use the OneTick Cloud KDB-X module

Use the module when you want to:

- Query OneTick market data without leaving the q environment.
- Combine OneTick results with in-memory or persisted KDB-X data.
- Transform, aggregate, or store OneTick query results in KDB-X.
- Use OneTick SQL while building downstream analytics in q.

## Limitations

- `sql_rest` is synchronous and blocks until the REST request completes or fails.
- The module returns the main `PROCESS_EVENT` table, not the complete set of OneTick callback message tables.
- A query that contains no `PROCESS_EVENT` data signals `"No data returned."`.
- OneTick limits responses made with demonstration credentials to 10 MB. Subscriber limits depend on the OneTick account.
- The module exposes no public timeout or general retry settings.

## Next steps

- Follow the [OneTick Cloud Quickstart](quickstart.md) to install the module and run your first query.
- Explore [OneTick Cloud Examples](examples.md) for common query patterns.
- Explore the [OneTick Cloud Reference](reference.md) for API and configuration details.
- Check the [OneTick Cloud Release Notes](release-notes/changelog.md) for version history, fixes, and improvements.
