{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cebfc549-640b-42b5-b811-e539d58adfd7",
   "metadata": {},
   "source": [
    "# Accessing a Lower Level API\n",
    "\n",
    "Some of OneTick's functionality may not be explicitly added to `onetick-py` but can be access through a lower-level API called `onetick.query`.\n",
    "See OneTick server documentation for details."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2aa093c6-2cab-47dc-8be1-0fdf13359548",
   "metadata": {},
   "outputs": [],
   "source": [
    "import onetick.py as otp\n",
    "from onetick.py.otq import otq\n",
    "\n",
    "trd = otp.DataSource('US_COMP_SAMPLE', tick_type='TRD')\n",
    "\n",
    "trd.sink(otq.Variance(input_field_name='PRICE', output_field_name='VAR_PRICE', bucket_interval=60))\n",
    "trd = trd.table(VAR_PRICE=float, strict=False) # need to explicitly add the fields added by the `sink` methods to the schema\n",
    "\n",
    "trd['std'] = otp.math.sqrt(trd['VAR_PRICE'])\n",
    "\n",
    "otp.run(trd, start=otp.dt(2024, 2, 1, 10), end=otp.dt(2024, 2, 1, 16), symbols='AA')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
