<a id="getting-started"></a>

# Getting Started

The guides in this section take you through the typical uses of `onetick-py` and are structured
in the order that facilitates learning `onetick-py` from scratch.

## Basic configuration

`onetick-py` requires some configuration to be set up before running the queries.
Note that for readability reasons the code for configurating `onetick-py` was omitted in the examples.

This code can be used to set some basic configuration on Linux:

```default
export OTP_DEFAULT_DB="US_COMP_SAMPLE"
export OTP_DEFAULT_SYMBOL="AAPL"
export OTP_DEFAULT_START_TIME="2024/02/01 00:00:00"
export OTP_DEFAULT_END_TIME="2024/02/02 00:00:00"
export OTP_DEFAULT_TZ="EST5EDT"
```

On Windows:

```default
set OTP_DEFAULT_DB=US_COMP_SAMPLE
set OTP_DEFAULT_SYMBOL=AAPL
set OTP_DEFAULT_START_TIME=2024/02/01 00:00:00
set OTP_DEFAULT_END_TIME=2024/02/02 00:00:00
set OTP_DEFAULT_TZ=EST5EDT
```

In the python code on any system (before importing `onetick-py`):

```default
import os
os.environ['OTP_DEFAULT_DB'] = 'US_COMP_SAMPLE'
os.environ['OTP_DEFAULT_SYMBOL'] = 'AAPL'
os.environ['OTP_DEFAULT_START_TIME'] = '2024/02/01 00:00:00'
os.environ['OTP_DEFAULT_END_TIME'] = '2024/02/02 00:00:00'
os.environ['OTP_DEFAULT_TZ'] = 'EST5EDT'
```

See details about `onetick-py` configuration in [Configuration](https://docs.pip.distribution.sol.onetick.com/static/configuration/root.html.md#configuration).

## Authentication with OneTick Cloud

If you are using `onetick-py` to connect to OneTick cloud, you will need to authenticate.

You will need to create or log-in to account on [https://www.onetick.com/cloud-services/](https://www.onetick.com/cloud-services/)
and get `CLIENT_ID` and `CLIENT_SECRET` there.

Run this code to set up authentication for `onetick-py`:

```default
import os
os.environ['OTP_WEBAPI'] = '1'
os.environ['OTP_HTTP_ADDRESS'] = 'https://rest.cloud.onetick.com'
os.environ['OTP_ACCESS_TOKEN_URL'] = 'https://cloud-auth.parent.onetick.com/realms/OMD/protocol/openid-connect/token'
os.environ['OTP_CLIENT_ID'] = '__FILL_IN__'
os.environ['OTP_CLIENT_SECRET'] = '__FILL_IN__'
```

## Quick examples

### Runnable code for US equities

```default
import onetick.py as otp

sym = 'AAPL'
start = otp.dt(2024, 2, 1, 10)
еnd = start + otp.Minute(1)

# Get trades
trades = otp.DataSource('US_COMP_SAMPLE', tick_type='TRD')
print(otp.run(trades, start=start, end=еnd, symbols=sym))

# Join trades with quotes
quotes = otp.DataSource(db='US_COMP_SAMPLE', tick_type='NBBO')

joined = otp.join_by_time([trades, quotes])

res = otp.run(joined,
              symbols=[sym],
              start=start,
              end=еnd)

print(res)
```

### Runnable code for futures

```default
import onetick.py as otp

sym = r'NG\N24'
start = otp.dt(2024, 2, 1, 10)
еnd = start + otp.Minute(100)

# Get trades
trades = otp.DataSource('CME_SAMPLE', tick_type='TRD')
print(otp.run(trades, start=start, end=еnd, symbols=sym))

# Join trades with quotes
quotes = otp.DataSource(db='CME_SAMPLE', tick_type='QTE')

joined = otp.join_by_time([trades, quotes])

res = otp.run(joined,
              symbols=[sym],
              start=start,
              end=еnd)

print(res)
```

## Table Of Contents

* [Data Retrieval](https://docs.pip.distribution.sol.onetick.com/static/getting_started/data_retrieval.html.md)
* [Filtering](https://docs.pip.distribution.sol.onetick.com/static/getting_started/filtering.html.md)
* [Aggregating](https://docs.pip.distribution.sol.onetick.com/static/getting_started/aggregations.html.md)
* [Time-Based Joins](https://docs.pip.distribution.sol.onetick.com/static/getting_started/time_based_joins.html.md)
* [`join_by_time`: Enhancing a time series with information from other time series at the time of each tick](https://docs.pip.distribution.sol.onetick.com/static/getting_started/time_based_joins.html.md#join-by-time-enhancing-a-time-series-with-information-from-other-time-series-at-the-time-of-each-tick)
* [`join_with_query`: Executing a query on each tick](https://docs.pip.distribution.sol.onetick.com/static/getting_started/time_based_joins.html.md#join-with-query-executing-a-query-on-each-tick)
* [Interval VWAP: the efficient way](https://docs.pip.distribution.sol.onetick.com/static/getting_started/time_based_joins.html.md#interval-vwap-the-efficient-way)
* [Order Book Analytics](https://docs.pip.distribution.sol.onetick.com/static/getting_started/order_book_analytics.html.md)
* [Real-time processing](https://docs.pip.distribution.sol.onetick.com/static/getting_started/real_time_processing.html.md)
* [Use case: Signal Generation](https://docs.pip.distribution.sol.onetick.com/static/getting_started/real_time_processing.html.md#use-case-signal-generation)
* [Variables and Data Structures](https://docs.pip.distribution.sol.onetick.com/static/getting_started/variables_and_data_structures.html.md)
* [Dictionaries / Maps (aka `tick sets`)](https://docs.pip.distribution.sol.onetick.com/static/getting_started/variables_and_data_structures.html.md#dictionaries-maps-aka-tick-sets)
* [Lists and Queues](https://docs.pip.distribution.sol.onetick.com/static/getting_started/variables_and_data_structures.html.md#lists-and-queues)
* [Symbologies](https://docs.pip.distribution.sol.onetick.com/static/getting_started/symbologies.html.md)
* [Symbol name changes](https://docs.pip.distribution.sol.onetick.com/static/getting_started/symbologies.html.md#symbol-name-changes)
* [Corporate Actions](https://docs.pip.distribution.sol.onetick.com/static/getting_started/corporate_actions.html.md)
* [Adjusting prices for corporate actions](https://docs.pip.distribution.sol.onetick.com/static/getting_started/corporate_actions.html.md#adjusting-prices-for-corporate-actions)
* [Retrieving Corporate actions for a symbol](https://docs.pip.distribution.sol.onetick.com/static/getting_started/corporate_actions.html.md#retrieving-corporate-actions-for-a-symbol)
* [Daily OHLCV (with closing prices)](https://docs.pip.distribution.sol.onetick.com/static/getting_started/daily_OHLCV.html.md)
* [Accessing a Lower Level API](https://docs.pip.distribution.sol.onetick.com/static/getting_started/accessing_lower_level_api.html.md)
* [Data inspection](https://docs.pip.distribution.sol.onetick.com/static/getting_started/data_inspection.html.md)
* [otp.Session: set up OneTick configuration files](https://docs.pip.distribution.sol.onetick.com/static/getting_started/session.html.md)
* [Rendering query graphs](https://docs.pip.distribution.sol.onetick.com/static/getting_started/rendering_graphs.html.md)
