Created
November 16, 2025 17:31
-
-
Save danwagnerco/1004188d110d8c6929c78f45713a2728 to your computer and use it in GitHub Desktop.
Example that demonstrates how to collect many parameters (including option theo price) from the Custom Alerts endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "id": "d4f26ddc", | |
| "metadata": {}, | |
| "source": [ | |
| "The Unusual Whales API endpoints we will access in this example:\n", | |
| "\n", | |
| "**Alert Configurations**\n", | |
| "\n", | |
| "- Docs: [https://api.unusualwhales.com/docs#/operations/PublicApi.AlertsController.configs](https://api.unusualwhales.com/docs#/operations/PublicApi.AlertsController.configs)\n", | |
| "- GET: `https://api.unusualwhales.com/api/alerts/configuration`\n", | |
| "\n", | |
| "**Alerts**\n", | |
| "\n", | |
| "- Docs: [https://api.unusualwhales.com/docs#/operations/PublicApi.AlertsController.alerts](https://api.unusualwhales.com/docs#/operations/PublicApi.AlertsController.alerts)\n", | |
| "- GET: `https://api.unusualwhales.com/api/alerts`" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "f705f579", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import os\n", | |
| "import httpx # pip install httpx\n", | |
| "import polars as pl # pip install polars\n", | |
| "from pathlib import Path\n", | |
| "from dataclasses import dataclass\n", | |
| "\n", | |
| "uw_token = os.getenv(\"UW_TOKEN\") # API token in environment variable\n", | |
| "headers = {\n", | |
| " \"Accept\": \"application/json, text/plain\",\n", | |
| " \"Authorization\": uw_token\n", | |
| "}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "da66705f", | |
| "metadata": {}, | |
| "source": [ | |
| "This is overkill but dataclasses make it easy to pick-and-choose the fields you find most important from a larger resposne payload:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "30503510", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "@dataclass\n", | |
| "class CustomAlertConfig:\n", | |
| " name: str\n", | |
| " noti_type: str\n", | |
| " id: str\n", | |
| " created_at: str\n", | |
| " updated_at: str\n", | |
| " status: str\n", | |
| " \n", | |
| "def get_custom_alert_configs(headers: dict) -> list[CustomAlertConfig]:\n", | |
| " \"\"\"Convert the large API response into a list of CustomAlertConfigs\"\"\"\n", | |
| " url = f\"https://api.unusualwhales.com/api/alerts/configuration\"\n", | |
| " rsp = httpx.get(url, headers=headers)\n", | |
| " raw_data = rsp.json()[\"data\"]\n", | |
| " results = []\n", | |
| " for record in raw_data:\n", | |
| " results.append(\n", | |
| " CustomAlertConfig(\n", | |
| " name=record[\"name\"],\n", | |
| " noti_type=record[\"noti_type\"],\n", | |
| " id=record[\"id\"],\n", | |
| " created_at=record[\"created_at\"],\n", | |
| " updated_at=record[\"updated_at\"],\n", | |
| " status=record[\"status\"],\n", | |
| " )\n", | |
| " )\n", | |
| " return results" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "id": "735ef259", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[CustomAlertConfig(name='milt True Freelance', noti_type='option_trade', id='41c29b4f-ffb2-4e24-b247-801d81d7aa6d', created_at='2025-11-06T16:41:16Z', updated_at='2025-11-06T16:41:16Z', status='active'),\n", | |
| " CustomAlertConfig(name='OS Call Spread 100K', noti_type='option_contract', id='68d2fac2-696e-4a80-853a-93759d667a54', created_at='2025-11-05T17:33:58Z', updated_at='2025-11-05T17:33:58Z', status='active'),\n", | |
| " CustomAlertConfig(name='coolguy5255 FLOW FEED no report flags', noti_type='option_trade', id='64f2ef0f-db6a-46ee-ad0a-e5d161c0b845', created_at='2025-10-31T18:13:15Z', updated_at='2025-10-31T18:13:15Z', status='active'),\n", | |
| " CustomAlertConfig(name='coolguy5255 FLOW FEED', noti_type='option_trade', id='8c978b7d-ad69-4266-b76f-ebd5d363db4c', created_at='2025-10-31T16:58:05Z', updated_at='2025-10-31T16:58:05Z', status='active'),\n", | |
| " CustomAlertConfig(name='Unusually Bullish Single Transaction', noti_type='option_trade', id='2a79d4ad-087e-4cbc-8395-1a8758d479cf', created_at='2025-10-27T13:58:29Z', updated_at='2025-10-27T13:58:29Z', status='active')]" | |
| ] | |
| }, | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "custom_alert_configs = get_custom_alert_configs(headers)\n", | |
| "custom_alert_configs[:5] # Display the first 5 CustomAlertConfigs for reference" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "8228148d", | |
| "metadata": {}, | |
| "source": [ | |
| "Let's get the latest \"Unusually Bullish Single Transaction\" Custom Alerts:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "id": "4c787047", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "alerts_url = f\"https://api.unusualwhales.com/api/alerts\"\n", | |
| "params = {\n", | |
| " \"config_ids[]\": \"2a79d4ad-087e-4cbc-8395-1a8758d479cf\",\n", | |
| "}\n", | |
| "rsp = httpx.get(alerts_url, headers=headers, params=params)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "df5caed3", | |
| "metadata": {}, | |
| "source": [ | |
| "The response is quite large and very descriptive! For reference:\n", | |
| "\n", | |
| "```\n", | |
| ">>> rsp.json()\n", | |
| "{'data': [{'id': '4f0b31ff-e36f-4d54-8616-6619c563d533',\n", | |
| " 'meta': {'open_interest': 340,\n", | |
| " 'ask_vol': 724,\n", | |
| " 'ewma_nbbo_bid': '48.20',\n", | |
| " 'bid_vol': 11,\n", | |
| " 'delta': '0.523',\n", | |
| " 'ewma_nbbo_ask': '51.00',\n", | |
| " 'multi_vol': 29,\n", | |
| " 'industry_type': 'Computer Hardware',\n", | |
| " 'implied_volatility': '1.134',\n", | |
| " 'is_agg': False,\n", | |
| " 'theo': '50.8',\n", | |
| " 'stock_multi_vol': 0,\n", | |
| " 'theta': '-0.272',\n", | |
| " 'gamma': '0.002',\n", | |
| " 'option_chain_id': 'SNDK260320C00310000',\n", | |
| " 'premium': '3556000.00',\n", | |
| " 'id': '9b42da28-23c3-4c60-b99c-0f26bf80b1c8',\n", | |
| " 'exchange': 'XPHO',\n", | |
| " 'price': '50.80',\n", | |
| " 'tags': ['ask_side', 'bullish'],\n", | |
| " 'size': 700,\n", | |
| " 'mid_vol': 0,\n", | |
| " 'executed_at': '2025-11-14T20:40:49.575Z',\n", | |
| " 'next_earnings_date': None,\n", | |
| " 'report_flags': ['futures_floor'],\n", | |
| " 'underlying_price': '257.855',\n", | |
| " 'volume': 735,\n", | |
| " 'rho': '0.290',\n", | |
| " 'no_side_vol': 0,\n", | |
| " 'upstream_condition_detail': 'SLFT',\n", | |
| " 'sector': 'Technology',\n", | |
| " 'vega': '0.603',\n", | |
| " 'issue_type': 'Common Stock',\n", | |
| " 'marketcap': '35695957809'},\n", | |
| " 'name': 'Unusually Bullish Single Transaction',\n", | |
| " 'symbol': 'SNDK260320C00310000',\n", | |
| " 'created_at': '2025-11-14T20:40:50Z',\n", | |
| " 'tape_time': '2025-11-14T20:40:49Z',\n", | |
| " 'user_noti_config_id': '2a79d4ad-087e-4cbc-8395-1a8758d479cf',\n", | |
| " 'noti_type': 'option_trade',\n", | |
| " 'symbol_type': 'option_chain'},\n", | |
| " # many more records...\n", | |
| "]}\n", | |
| "```\n", | |
| "\n", | |
| "Let's create a convenience function that expands the `meta` sub-dictionary and returns a Polars dataframe:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "id": "f27d88a0", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def convert_option_trades_to_df(option_trades: list) -> pl.DataFrame:\n", | |
| " \"\"\"Convert the 'data' list of dictionaries into a Polars DataFrame.\"\"\"\n", | |
| " records = []\n", | |
| " for r in option_trades:\n", | |
| " records.append({\n", | |
| " \"id\": r.get(\"id\"),\n", | |
| " \"name\": r.get(\"name\"),\n", | |
| " \"symbol\": r.get(\"symbol\"),\n", | |
| " \"created_at\": r.get(\"created_at\"),\n", | |
| " \"tape_time\": r.get(\"tape_time\"),\n", | |
| " \"user_noti_config_id\": r.get(\"user_noti_config_id\"),\n", | |
| " \"noti_type\": r.get(\"noti_type\"),\n", | |
| " \"symbol_type\": r.get(\"symbol_type\"),\n", | |
| " \"open_interest\": r.get(\"meta\", {}).get(\"open_interest\"),\n", | |
| " \"ask_vol\": r.get(\"meta\", {}).get(\"ask_vol\"),\n", | |
| " \"ewma_nbbo_bid\": r.get(\"meta\", {}).get(\"ewma_nbbo_bid\"),\n", | |
| " \"bid_vol\": r.get(\"meta\", {}).get(\"bid_vol\"),\n", | |
| " \"delta\": r.get(\"meta\", {}).get(\"delta\"),\n", | |
| " \"ewma_nbbo_ask\": r.get(\"meta\", {}).get(\"ewma_nbbo_ask\"),\n", | |
| " \"multi_vol\": r.get(\"meta\", {}).get(\"multi_vol\"),\n", | |
| " \"industry_type\": r.get(\"meta\", {}).get(\"industry_type\"),\n", | |
| " \"implied_volatility\": r.get(\"meta\", {}).get(\"implied_volatility\"),\n", | |
| " \"is_agg\": r.get(\"meta\", {}).get(\"is_agg\"),\n", | |
| " \"theo\": r.get(\"meta\", {}).get(\"theo\"),\n", | |
| " \"stock_multi_vol\": r.get(\"meta\", {}).get(\"stock_multi_vol\"),\n", | |
| " \"theta\": r.get(\"meta\", {}).get(\"theta\"),\n", | |
| " \"gamma\": r.get(\"meta\", {}).get(\"gamma\"),\n", | |
| " \"option_chain_id\": r.get(\"meta\", {}).get(\"option_chain_id\"),\n", | |
| " \"premium\": r.get(\"meta\", {}).get(\"premium\"),\n", | |
| " \"meta_id\": r.get(\"meta\", {}).get(\"id\"),\n", | |
| " \"exchange\": r.get(\"meta\", {}).get(\"exchange\"),\n", | |
| " \"price\": r.get(\"meta\", {}).get(\"price\"),\n", | |
| " \"size\": r.get(\"meta\", {}).get(\"size\"),\n", | |
| " \"mid_vol\": r.get(\"meta\", {}).get(\"mid_vol\"),\n", | |
| " \"executed_at\": r.get(\"meta\", {}).get(\"executed_at\"),\n", | |
| " \"next_earnings_date\": r.get(\"meta\", {}).get(\"next_earnings_date\"),\n", | |
| " \"underlying_price\": r.get(\"meta\", {}).get(\"underlying_price\"),\n", | |
| " \"volume\": r.get(\"meta\", {}).get(\"volume\"),\n", | |
| " \"rho\": r.get(\"meta\", {}).get(\"rho\"),\n", | |
| " \"no_side_vol\": r.get(\"meta\", {}).get(\"no_side_vol\"),\n", | |
| " \"upstream_condition_detail\": r.get(\"meta\", {}).get(\n", | |
| " \"upstream_condition_detail\"\n", | |
| " ),\n", | |
| " \"sector\": r.get(\"meta\", {}).get(\"sector\"),\n", | |
| " \"vega\": r.get(\"meta\", {}).get(\"vega\"),\n", | |
| " \"issue_type\": r.get(\"meta\", {}).get(\"issue_type\"),\n", | |
| " \"market_cap\": r.get(\"meta\", {}).get(\"market_cap\"),\n", | |
| " })\n", | |
| " return pl.DataFrame(records)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "a62fc2bb", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div><style>\n", | |
| ".dataframe > thead > tr,\n", | |
| ".dataframe > tbody > tr {\n", | |
| " text-align: right;\n", | |
| " white-space: pre-wrap;\n", | |
| "}\n", | |
| "</style>\n", | |
| "<small>shape: (5, 40)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>id</th><th>name</th><th>symbol</th><th>created_at</th><th>tape_time</th><th>user_noti_config_id</th><th>noti_type</th><th>symbol_type</th><th>open_interest</th><th>ask_vol</th><th>ewma_nbbo_bid</th><th>bid_vol</th><th>delta</th><th>ewma_nbbo_ask</th><th>multi_vol</th><th>industry_type</th><th>implied_volatility</th><th>is_agg</th><th>theo</th><th>stock_multi_vol</th><th>theta</th><th>gamma</th><th>option_chain_id</th><th>premium</th><th>meta_id</th><th>exchange</th><th>price</th><th>size</th><th>mid_vol</th><th>executed_at</th><th>next_earnings_date</th><th>underlying_price</th><th>volume</th><th>rho</th><th>no_side_vol</th><th>upstream_condition_detail</th><th>sector</th><th>vega</th><th>issue_type</th><th>market_cap</th></tr><tr><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>str</td><td>i64</td><td>str</td><td>str</td><td>i64</td><td>str</td><td>str</td><td>bool</td><td>str</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>i64</td><td>str</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>null</td></tr></thead><tbody><tr><td>"4f0b31ff-e36f-4d54-8616-6619c5…</td><td>"Unusually Bullish Single Trans…</td><td>"SNDK260320C00310000"</td><td>"2025-11-14T20:40:50Z"</td><td>"2025-11-14T20:40:49Z"</td><td>"2a79d4ad-087e-4cbc-8395-1a8758…</td><td>"option_trade"</td><td>"option_chain"</td><td>340</td><td>724</td><td>"48.20"</td><td>11</td><td>"0.523"</td><td>"51.00"</td><td>29</td><td>"Computer Hardware"</td><td>"1.134"</td><td>false</td><td>"50.8"</td><td>0</td><td>"-0.272"</td><td>"0.002"</td><td>"SNDK260320C00310000"</td><td>"3556000.00"</td><td>"9b42da28-23c3-4c60-b99c-0f26bf…</td><td>"XPHO"</td><td>"50.80"</td><td>700</td><td>0</td><td>"2025-11-14T20:40:49.575Z"</td><td>null</td><td>"257.855"</td><td>735</td><td>"0.290"</td><td>0</td><td>"SLFT"</td><td>"Technology"</td><td>"0.603"</td><td>"Common Stock"</td><td>null</td></tr><tr><td>"109a6db3-66c4-4287-bc09-cba40f…</td><td>"Unusually Bullish Single Trans…</td><td>"COIN251121C00295000"</td><td>"2025-11-14T20:30:34Z"</td><td>"2025-11-14T20:30:33Z"</td><td>"2a79d4ad-087e-4cbc-8395-1a8758…</td><td>"option_trade"</td><td>"option_chain"</td><td>367</td><td>2518</td><td>"6.05"</td><td>308</td><td>"0.365"</td><td>"6.35"</td><td>2386</td><td>"Software"</td><td>"0.676"</td><td>false</td><td>"6.310"</td><td>1</td><td>"-0.715"</td><td>"0.014"</td><td>"COIN251121C00295000"</td><td>"1388200.00"</td><td>"fe89c901-c90e-4661-9b57-3fcab8…</td><td>"XBOX"</td><td>"6.31"</td><td>2200</td><td>168</td><td>"2025-11-14T20:30:33.162Z"</td><td>"2026-02-12"</td><td>"284.34"</td><td>2994</td><td>"0.019"</td><td>0</td><td>"MLFT"</td><td>"Technology"</td><td>"0.148"</td><td>"Common Stock"</td><td>null</td></tr><tr><td>"419b6743-547a-4cfd-82e9-01c66d…</td><td>"Unusually Bullish Single Trans…</td><td>"MSTR251121C00220000"</td><td>"2025-11-14T20:06:06Z"</td><td>"2025-11-14T20:06:05Z"</td><td>"2a79d4ad-087e-4cbc-8395-1a8758…</td><td>"option_trade"</td><td>"option_chain"</td><td>1039</td><td>8746</td><td>"2.48"</td><td>5366</td><td>"0.221"</td><td>"2.64"</td><td>4721</td><td>"Software"</td><td>"0.766"</td><td>false</td><td>"2.580"</td><td>0</td><td>"-0.454"</td><td>"0.014"</td><td>"MSTR251121C00220000"</td><td>"645000.00"</td><td>"76c48844-c9c9-4b42-8511-32fc6c…</td><td>"XPHO"</td><td>"2.58"</td><td>2500</td><td>1727</td><td>"2025-11-14T20:06:05.403Z"</td><td>"2026-02-04"</td><td>"201.615"</td><td>15839</td><td>"0.008"</td><td>0</td><td>"MLAT"</td><td>"Technology"</td><td>"0.083"</td><td>"Common Stock"</td><td>null</td></tr><tr><td>"a2304507-0a7e-48dd-9b32-f0d904…</td><td>"Unusually Bullish Single Trans…</td><td>"MSTR251121C00210000"</td><td>"2025-11-14T19:28:40Z"</td><td>"2025-11-14T19:28:37Z"</td><td>"2a79d4ad-087e-4cbc-8395-1a8758…</td><td>"option_trade"</td><td>"option_chain"</td><td>603</td><td>4317</td><td>"4.80"</td><td>2805</td><td>"0.352"</td><td>"5.10"</td><td>2946</td><td>"Software"</td><td>"0.804"</td><td>false</td><td>"4.990"</td><td>1</td><td>"-0.591"</td><td>"0.017"</td><td>"MSTR251121C00210000"</td><td>"1247500.00"</td><td>"e7f28b9a-8deb-493a-b4fe-8c4e02…</td><td>"XCBO"</td><td>"4.99"</td><td>2500</td><td>302</td><td>"2025-11-14T19:28:37.561Z"</td><td>"2026-02-04"</td><td>"200.07"</td><td>7424</td><td>"0.013"</td><td>0</td><td>"MLAT"</td><td>"Technology"</td><td>"0.103"</td><td>"Common Stock"</td><td>null</td></tr><tr><td>"c6aae01c-63e8-4b90-9a71-1c2036…</td><td>"Unusually Bullish Single Trans…</td><td>"ASND260417C00250000"</td><td>"2025-11-14T19:03:15Z"</td><td>"2025-11-14T19:03:14Z"</td><td>"2a79d4ad-087e-4cbc-8395-1a8758…</td><td>"option_trade"</td><td>"option_chain"</td><td>1</td><td>1000</td><td>"10.20"</td><td>0</td><td>"0.321"</td><td>"11.20"</td><td>0</td><td>"Biotechnology"</td><td>"0.437"</td><td>false</td><td>"10.800"</td><td>0</td><td>"-0.070"</td><td>"0.006"</td><td>"ASND260417C00250000"</td><td>"1080000.00"</td><td>"ae7471ad-bd40-46ac-be1f-560223…</td><td>"AMXO"</td><td>"10.80"</td><td>1000</td><td>0</td><td>"2025-11-14T19:03:14.057Z"</td><td>"2026-02-11"</td><td>"210.34"</td><td>1000</td><td>"0.240"</td><td>0</td><td>"SLFT"</td><td>"Healthcare"</td><td>"0.489"</td><td>"ADR"</td><td>null</td></tr></tbody></table></div>" | |
| ], | |
| "text/plain": [ | |
| "shape: (5, 40)\n", | |
| "┌────────────┬────────────┬────────────┬───────────┬───┬───────────┬───────┬───────────┬───────────┐\n", | |
| "│ id ┆ name ┆ symbol ┆ created_a ┆ … ┆ sector ┆ vega ┆ issue_typ ┆ market_ca │\n", | |
| "│ --- ┆ --- ┆ --- ┆ t ┆ ┆ --- ┆ --- ┆ e ┆ p │\n", | |
| "│ str ┆ str ┆ str ┆ --- ┆ ┆ str ┆ str ┆ --- ┆ --- │\n", | |
| "│ ┆ ┆ ┆ str ┆ ┆ ┆ ┆ str ┆ null │\n", | |
| "╞════════════╪════════════╪════════════╪═══════════╪═══╪═══════════╪═══════╪═══════════╪═══════════╡\n", | |
| "│ 4f0b31ff-e ┆ Unusually ┆ SNDK260320 ┆ 2025-11-1 ┆ … ┆ Technolog ┆ 0.603 ┆ Common ┆ null │\n", | |
| "│ 36f-4d54-8 ┆ Bullish ┆ C00310000 ┆ 4T20:40:5 ┆ ┆ y ┆ ┆ Stock ┆ │\n", | |
| "│ 616-6619c5 ┆ Single ┆ ┆ 0Z ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ … ┆ Trans… ┆ ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ 109a6db3-6 ┆ Unusually ┆ COIN251121 ┆ 2025-11-1 ┆ … ┆ Technolog ┆ 0.148 ┆ Common ┆ null │\n", | |
| "│ 6c4-4287-b ┆ Bullish ┆ C00295000 ┆ 4T20:30:3 ┆ ┆ y ┆ ┆ Stock ┆ │\n", | |
| "│ c09-cba40f ┆ Single ┆ ┆ 4Z ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ … ┆ Trans… ┆ ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ 419b6743-5 ┆ Unusually ┆ MSTR251121 ┆ 2025-11-1 ┆ … ┆ Technolog ┆ 0.083 ┆ Common ┆ null │\n", | |
| "│ 47a-4cfd-8 ┆ Bullish ┆ C00220000 ┆ 4T20:06:0 ┆ ┆ y ┆ ┆ Stock ┆ │\n", | |
| "│ 2e9-01c66d ┆ Single ┆ ┆ 6Z ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ … ┆ Trans… ┆ ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ a2304507-0 ┆ Unusually ┆ MSTR251121 ┆ 2025-11-1 ┆ … ┆ Technolog ┆ 0.103 ┆ Common ┆ null │\n", | |
| "│ a7e-48dd-9 ┆ Bullish ┆ C00210000 ┆ 4T19:28:4 ┆ ┆ y ┆ ┆ Stock ┆ │\n", | |
| "│ b32-f0d904 ┆ Single ┆ ┆ 0Z ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ … ┆ Trans… ┆ ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ c6aae01c-6 ┆ Unusually ┆ ASND260417 ┆ 2025-11-1 ┆ … ┆ Healthcar ┆ 0.489 ┆ ADR ┆ null │\n", | |
| "│ 3e8-4b90-9 ┆ Bullish ┆ C00250000 ┆ 4T19:03:1 ┆ ┆ e ┆ ┆ ┆ │\n", | |
| "│ a71-1c2036 ┆ Single ┆ ┆ 5Z ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ … ┆ Trans… ┆ ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "└────────────┴────────────┴────────────┴───────────┴───┴───────────┴───────┴───────────┴───────────┘" | |
| ] | |
| }, | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "raw_df = convert_option_trades_to_df(rsp.json()[\"data\"])\n", | |
| "raw_df.head(5)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "594e3f45", | |
| "metadata": {}, | |
| "source": [ | |
| "Now we can whittle this down to a more concise set of columns, for example:\n", | |
| "- `id`\n", | |
| "- `tape_time`\n", | |
| "- `symbol`\n", | |
| "- `size`\n", | |
| "- `volume`\n", | |
| "- `open_interest`\n", | |
| "- `price`\n", | |
| "- `premium`\n", | |
| "- `theo` **<- note that option theoretical price is available**\n", | |
| "- `implied_volatility`\n", | |
| "- `delta`\n", | |
| "- `gamma`\n", | |
| "- `theta`\n", | |
| "- `vega`\n", | |
| "- `rho`" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "id": "95a76854", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div><style>\n", | |
| ".dataframe > thead > tr,\n", | |
| ".dataframe > tbody > tr {\n", | |
| " text-align: right;\n", | |
| " white-space: pre-wrap;\n", | |
| "}\n", | |
| "</style>\n", | |
| "<small>shape: (5, 15)</small><table border=\"1\" class=\"dataframe\"><thead><tr><th>id</th><th>tape_time</th><th>symbol</th><th>size</th><th>volume</th><th>open_interest</th><th>price</th><th>premium</th><th>theo</th><th>implied_volatility</th><th>delta</th><th>gamma</th><th>theta</th><th>vega</th><th>rho</th></tr><tr><td>str</td><td>str</td><td>str</td><td>i64</td><td>i64</td><td>i64</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td><td>str</td></tr></thead><tbody><tr><td>"4f0b31ff-e36f-4d54-8616-6619c5…</td><td>"2025-11-14T20:40:49Z"</td><td>"SNDK260320C00310000"</td><td>700</td><td>735</td><td>340</td><td>"50.80"</td><td>"3556000.00"</td><td>"50.8"</td><td>"1.134"</td><td>"0.523"</td><td>"0.002"</td><td>"-0.272"</td><td>"0.603"</td><td>"0.290"</td></tr><tr><td>"109a6db3-66c4-4287-bc09-cba40f…</td><td>"2025-11-14T20:30:33Z"</td><td>"COIN251121C00295000"</td><td>2200</td><td>2994</td><td>367</td><td>"6.31"</td><td>"1388200.00"</td><td>"6.310"</td><td>"0.676"</td><td>"0.365"</td><td>"0.014"</td><td>"-0.715"</td><td>"0.148"</td><td>"0.019"</td></tr><tr><td>"419b6743-547a-4cfd-82e9-01c66d…</td><td>"2025-11-14T20:06:05Z"</td><td>"MSTR251121C00220000"</td><td>2500</td><td>15839</td><td>1039</td><td>"2.58"</td><td>"645000.00"</td><td>"2.580"</td><td>"0.766"</td><td>"0.221"</td><td>"0.014"</td><td>"-0.454"</td><td>"0.083"</td><td>"0.008"</td></tr><tr><td>"a2304507-0a7e-48dd-9b32-f0d904…</td><td>"2025-11-14T19:28:37Z"</td><td>"MSTR251121C00210000"</td><td>2500</td><td>7424</td><td>603</td><td>"4.99"</td><td>"1247500.00"</td><td>"4.990"</td><td>"0.804"</td><td>"0.352"</td><td>"0.017"</td><td>"-0.591"</td><td>"0.103"</td><td>"0.013"</td></tr><tr><td>"c6aae01c-63e8-4b90-9a71-1c2036…</td><td>"2025-11-14T19:03:14Z"</td><td>"ASND260417C00250000"</td><td>1000</td><td>1000</td><td>1</td><td>"10.80"</td><td>"1080000.00"</td><td>"10.800"</td><td>"0.437"</td><td>"0.321"</td><td>"0.006"</td><td>"-0.070"</td><td>"0.489"</td><td>"0.240"</td></tr></tbody></table></div>" | |
| ], | |
| "text/plain": [ | |
| "shape: (5, 15)\n", | |
| "┌──────────────────┬─────────────────┬─────────────────┬──────┬───┬───────┬────────┬───────┬───────┐\n", | |
| "│ id ┆ tape_time ┆ symbol ┆ size ┆ … ┆ gamma ┆ theta ┆ vega ┆ rho │\n", | |
| "│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │\n", | |
| "│ str ┆ str ┆ str ┆ i64 ┆ ┆ str ┆ str ┆ str ┆ str │\n", | |
| "╞══════════════════╪═════════════════╪═════════════════╪══════╪═══╪═══════╪════════╪═══════╪═══════╡\n", | |
| "│ 4f0b31ff-e36f-4d ┆ 2025-11-14T20:4 ┆ SNDK260320C0031 ┆ 700 ┆ … ┆ 0.002 ┆ -0.272 ┆ 0.603 ┆ 0.290 │\n", | |
| "│ 54-8616-6619c5… ┆ 0:49Z ┆ 0000 ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ 109a6db3-66c4-42 ┆ 2025-11-14T20:3 ┆ COIN251121C0029 ┆ 2200 ┆ … ┆ 0.014 ┆ -0.715 ┆ 0.148 ┆ 0.019 │\n", | |
| "│ 87-bc09-cba40f… ┆ 0:33Z ┆ 5000 ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ 419b6743-547a-4c ┆ 2025-11-14T20:0 ┆ MSTR251121C0022 ┆ 2500 ┆ … ┆ 0.014 ┆ -0.454 ┆ 0.083 ┆ 0.008 │\n", | |
| "│ fd-82e9-01c66d… ┆ 6:05Z ┆ 0000 ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ a2304507-0a7e-48 ┆ 2025-11-14T19:2 ┆ MSTR251121C0021 ┆ 2500 ┆ … ┆ 0.017 ┆ -0.591 ┆ 0.103 ┆ 0.013 │\n", | |
| "│ dd-9b32-f0d904… ┆ 8:37Z ┆ 0000 ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "│ c6aae01c-63e8-4b ┆ 2025-11-14T19:0 ┆ ASND260417C0025 ┆ 1000 ┆ … ┆ 0.006 ┆ -0.070 ┆ 0.489 ┆ 0.240 │\n", | |
| "│ 90-9a71-1c2036… ┆ 3:14Z ┆ 0000 ┆ ┆ ┆ ┆ ┆ ┆ │\n", | |
| "└──────────────────┴─────────────────┴─────────────────┴──────┴───┴───────┴────────┴───────┴───────┘" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "unusually_bullish_single_transaction_df = (\n", | |
| " raw_df\n", | |
| " .select([\n", | |
| " \"id\",\n", | |
| " \"tape_time\",\n", | |
| " \"symbol\",\n", | |
| " \"size\",\n", | |
| " \"volume\",\n", | |
| " \"open_interest\",\n", | |
| " \"price\",\n", | |
| " \"premium\",\n", | |
| " \"theo\",\n", | |
| " \"implied_volatility\",\n", | |
| " \"delta\",\n", | |
| " \"gamma\",\n", | |
| " \"theta\",\n", | |
| " \"vega\",\n", | |
| " \"rho\",\n", | |
| " ])\n", | |
| ")\n", | |
| "unusually_bullish_single_transaction_df.head(5)" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "dans-magic-house", | |
| "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.11.11" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment