jupyter/orderbook-simplified.ipynb (184 lines of code) (raw):

{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "c3f93d54-0248-4957-9028-6b75d7003d15", "metadata": {}, "outputs": [], "source": [ "from perspective import Table, PerspectiveWidget, Plugin\n", "from demo import Demo\n", "import ipywidgets as widgets\n", "from datetime import datetime\n", "import logging\n", "\n", "\n", "logger = logging.getLogger()\n", "logger.setLevel(logging.DEBUG)\n", "\n", "\n", "tb_info_url = 'dxtick://localhost:8011'\n", "key = 'coinbase'\n", "symbol = 'BTC/USD'\n", "record_type = 'com.epam.deltix.timebase.messages.universal.PackageHeader'\n", "booksize = 20\n", "time_widget = widgets.Text(\n", " disabled=True,\n", " value=str(datetime.now())\n", ")\n", "demo = Demo(tb_info_url, key, symbol, record_type, time_widget, booksize=booksize)" ] }, { "cell_type": "code", "execution_count": 2, "id": "8e506216-af09-42ad-9473-a0dac9b08d3e", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "18ccb97ca3bb4c79b2bb196af9ce0a0d", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Tab(children=(PerspectiveWidget(aggregates={'price': 'avg', 'numberOfOrders': 'sum'}, columns=['size', 'price'…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "grid = PerspectiveWidget(\n", " demo.table, \n", " sort=[], \n", " group_by=['symbol', 'price'], \n", " split_by=['side'], \n", " aggregates={'price': 'avg', 'numberOfOrders': 'sum'},\n", " columns=['size', 'price', 'numberOfOrders'],\n", " plugin=Plugin.GRID\n", ")\n", "xbar = PerspectiveWidget(\n", " demo.table, \n", " sort=[], \n", " columns=['size'],\n", " group_by=['symbol', 'price'], \n", " split_by=['side'], \n", " plugin=Plugin.XBAR\n", ")\n", "ybar = PerspectiveWidget(\n", " demo.table, \n", " sort=[], \n", " columns=['size'],\n", " group_by=['symbol', 'price'], \n", " split_by=['side'], \n", " plugin=Plugin.YBAR\n", ")\n", "tabs = widgets.Tab()\n", "tabs.children = [grid, xbar, ybar, time_widget]\n", "tabs.set_title(0, 'Grid')\n", "tabs.set_title(1, 'Horizontal Depth Chart')\n", "tabs.set_title(2, 'Vertical Depth Chart')\n", "tabs.set_title(3, 'Timestamp')\n", "tabs" ] }, { "cell_type": "code", "execution_count": 3, "id": "802b775f-1a28-4d34-86d2-5bf839f20ded", "metadata": { "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:root:Started streaming!\n", "DEBUG:asyncio:Using selector: SelectSelector\n" ] } ], "source": [ "demo.start()" ] }, { "cell_type": "code", "execution_count": 4, "id": "e4800d6e-86ae-4e6e-8b30-ffc7ccf9c315", "metadata": {}, "outputs": [], "source": [ "demo.stop()" ] }, { "cell_type": "code", "execution_count": 5, "id": "fd7bf73a-43ef-4e74-b640-377b3f8f1db7", "metadata": {}, "outputs": [], "source": [ "demo.clear()" ] }, { "cell_type": "code", "execution_count": null, "id": "f0927bfd-ee3d-4d67-ad82-b586ddc95a56", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "a0de7e03-e609-418d-9147-e356c6732ba6", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "cee0a255-262f-47c9-a735-5cbaf24a8b08", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "ecbe656d-0587-47fe-bb57-08a7502779ae", "metadata": {}, "outputs": [], "source": [] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 5 }