# OneTick Cloud KDB-X Module Quickstart

_This guide shows how to install the OneTick Cloud KDB-X module and retrieve OneTick sample market data as a q table._

## Before you begin

Ensure you have:

- A working [KDB-X installation](../../get_started/kdb-x-install.md) and valid license.
- The `kurl` module included with KDB-X.
- HTTPS access to `cloud-auth.parent.onetick.com` and `rest.cloud.onetick.com`, or to the endpoints supplied for your OneTick environment.
- The OneTick Cloud KDB-X module archive for your platform.

> **Info — New to KDB-X or OneTick?**
>
> If you are new to q and KDB-X, start with [A brief introduction to q and KDB-X](../../learn/brief-introduction.md). If you are new to OneTick SQL, review the [OneTick SQL querying examples](https://www.onetick.com/cloud-services/sql-querying-examples).
>
> In interactive examples, `q)` is the q prompt. Enter only the command that follows it.
>
The release archives use the following platform names:

| **Archive prefix** | **Platform** |
|---|---|
| `l64` | Linux x86-64 |
| `l64arm` | Linux ARM64 |
| `m64` | macOS x86-64 or ARM64 |

## Install the module

Download the appropriate archive from the [OneTick Cloud KDB-X module directory in the KX downloads portal](https://portal.dl.kx.com/assets/raw/kdb-x/modules/onetickcloud/). For example, download the latest Linux x86-64 archive with:
```bash
curl -L -O https://portal.dl.kx.com/assets/raw/kdb-x/modules/onetickcloud/~latest~/l64-onetickcloud.zip
```

The following commands use the default KDB-X installation directory, `$HOME/.kx`. If you installed KDB-X elsewhere, replace `$HOME/.kx` with your installation directory.

Extract the archive into the KDB-X module directory:
```bash
unzip -q l64-onetickcloud.zip -d "$HOME/.kx/mod/kx"
```

The installed module is under:
```text
$HOME/.kx/mod/kx/onetickcloud/
```

> **Note**
>
> Extract the complete release archive, including all files and subdirectories.
>
If the module fails to load on macOS, refer to [Module load fails on macOS](troubleshooting-errors.md#module-load-fails-on-macos).

## Configure access

Release archives contain demonstration credentials that provide limited access to OneTick sample data. You do not need to configure credentials to run the example in this quickstart.

To configure access to your OneTick account, obtain the endpoint URLs and OAuth 2.0 client credentials from your OneTick administrator. Set them before starting q:
```bash
export OTP_HTTP_ADDRESS="https://rest.example.com"
export OTP_ACCESS_TOKEN_URL="https://auth.example.com/realms/example/protocol/openid-connect/token"
export OTP_CLIENT_ID="your-client-id"
export OTP_CLIENT_SECRET="your-client-secret"
```

> **Warning — Protect your credentials**
>
> Do not commit client secrets to source control or include them in logs and support bundles. Follow your organization's process for storing and supplying secrets.
>
For configuration precedence and session overrides, refer to [Configure the module](reference.md#configure-the-module).

## Load the module

Start q and import `kx.onetickcloud` into the `.otc` namespace:
```q
q).otc:use`kx.onetickcloud
```

The assignment loads the module interface under the local `.otc` alias. The examples use this alias to call functions such as `.otc.sql_rest`; it is not the name of an object in OneTick.

The module displays initialization messages and returns without error when it loads successfully.

## Query OneTick sample data

Run a SQL query against the `LSE_SAMPLE.TRD` table:
```q
q)sql:"select SYMBOL_NAME, TIMESTAMP, TRADE_ID, PRICE, SIZE from LSE_SAMPLE.TRD where SYMBOL_NAME='VOD' and TIMESTAMP >= '2024-01-03 00:00:00 UTC' and TIMESTAMP < '2024-01-04 00:00:00 UTC' limit 10"
q)data:.otc.sql_rest[sql]
q)data
SYMBOL_NAME TIMESTAMP                     TRADE_ID              PRICE   SIZE
--------------------------------------------------------------------------------
VOD         2024.01.03D07:15:10.133000000 "1075835351045197936" 69.76   40000
VOD         2024.01.03D08:00:06.232000000 "911727684223506"     70      184613
VOD         2024.01.03D08:00:06.233000000 "911727684223588"     70.01   140
..
```

The query selects five columns from the demonstration trade table, filters for the `VOD` symbol during one UTC day, and returns at most 10 rows.

`data` is an unkeyed q table. The module removes the internal `CALLBACK_ID` column before returning it.

Check the result type and row count:
```q
q)type data
98h
q)count data
10
```

`98h` is the q [type](../../ref/type.md) code for a table. The row count matches the SQL `limit 10` clause.

## Upgrade the module

Stop any q processes using the module. Remove the existing `onetickcloud` directory, then extract the new archive into the same KDB-X module directory using the installation steps above.

> **Warning**
>
> Extracting a new archive over an existing installation can leave obsolete files in place. Replace the complete `onetickcloud` directory when upgrading.
>
## Next steps

- Explore [OneTick Cloud Examples](examples.md) for time zones, calculations, and result processing.
- Explore the [OneTick Cloud Reference](reference.md) for all public APIs.
- Visit [Troubleshooting OneTick Cloud](troubleshooting-errors.md) if a query fails.
