{ "cells": [ { "cell_type": "code", "execution_count": 134, "id": "c0bfb3b5", "metadata": {}, "outputs": [], "source": [ "import modules.api as api\n", "import pandas as pd\n", "from datetime import datetime, timezone, timedelta\n", "import math\n", "import requests\n", "import json\n", "from dataclasses import dataclass\n", "\n", "from py_clob_client.clob_types import OrderArgs, OrderType, PostOrdersArgs, PartialCreateOrderOptions, BalanceAllowanceParams\n", "from py_clob_client.order_builder.constants import BUY, SELL\n" ] }, { "cell_type": "code", "execution_count": 135, "id": "7d7dc787", "metadata": {}, "outputs": [], "source": [ "def time_round_down(dt, interval_mins=5) -> int: # returns timestamp in seconds\n", " interval_secs = interval_mins * 60\n", " seconds = dt.timestamp()\n", " rounded_seconds = math.floor(seconds / interval_secs) * interval_secs\n", " \n", " return rounded_seconds\n", "\n", "def get_mkt_details_by_slug(slug: str) -> dict[str, str, str]: # {'Up' : 123, 'Down': 456, 'isActive': True, 'MinTickSize': 0.01, 'isNegRisk': False}\n", " r = requests.get(f\"https://gamma-api.polymarket.com/events/slug/{slug}\")\n", " market = r.json()['markets'][0]\n", " token_ids = json.loads(market.get(\"clobTokenIds\", \"[]\"))\n", " outcomes = json.loads(market.get(\"outcomes\", \"[]\"))\n", " d = dict(zip(outcomes, token_ids))\n", " d['isActive'] = market['negRisk']\n", " d['MinTickSize'] = market['orderPriceMinTickSize']\n", " d['isNegRisk'] = market['negRisk']\n", " d['ConditionId'] = market['conditionId']\n", "\n", " return d, market" ] }, { "cell_type": "code", "execution_count": 136, "id": "c3e07e21", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-31 05:45:00')" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "slug_prefix = 'btc-updown-5m-'\n", "slug_time_id = time_round_down(dt=datetime.now(timezone.utc))\n", "slug_full = slug_prefix + str(slug_time_id)\n", "market_details, market = get_mkt_details_by_slug(slug_full)\n", "pd.to_datetime(slug_time_id, unit='s')" ] }, { "cell_type": "code", "execution_count": 137, "id": "10671da4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': '1787714',\n", " 'question': 'Bitcoin Up or Down - March 31, 1:45AM-1:50AM ET',\n", " 'conditionId': '0xd1773b412dacad884c202a7b14f0197918b1e22028ce2b5737fbd659bbe150f0',\n", " 'slug': 'btc-updown-5m-1774935900',\n", " 'resolutionSource': 'https://data.chain.link/streams/btc-usd',\n", " 'endDate': '2026-03-31T05:50:00Z',\n", " 'liquidity': '12631.9812',\n", " 'startDate': '2026-03-30T05:53:51.811773Z',\n", " 'image': 'https://polymarket-upload.s3.us-east-2.amazonaws.com/BTC+fullsize.png',\n", " 'icon': 'https://polymarket-upload.s3.us-east-2.amazonaws.com/BTC+fullsize.png',\n", " 'description': 'This market will resolve to \"Up\" if the Bitcoin price at the end of the time range specified in the title is greater than or equal to the price at the beginning of that range. Otherwise, it will resolve to \"Down\".\\nThe resolution source for this market is information from Chainlink, specifically the BTC/USD data stream available at https://data.chain.link/streams/btc-usd.\\nPlease note that this market is about the price according to Chainlink data stream BTC/USD, not according to other sources or spot markets.',\n", " 'outcomes': '[\"Up\", \"Down\"]',\n", " 'outcomePrices': '[\"0.875\", \"0.125\"]',\n", " 'volume': '94249.88157999996',\n", " 'active': True,\n", " 'closed': False,\n", " 'marketMakerAddress': '',\n", " 'createdAt': '2026-03-30T05:52:34.18484Z',\n", " 'updatedAt': '2026-03-31T05:48:51.799961Z',\n", " 'new': False,\n", " 'featured': False,\n", " 'archived': False,\n", " 'restricted': True,\n", " 'groupItemThreshold': '0',\n", " 'questionID': '0x33d208062bed0d8fcf68d2f3899e528f103ad7e7763efc763f71c065ea6c842c',\n", " 'enableOrderBook': True,\n", " 'orderPriceMinTickSize': 0.01,\n", " 'orderMinSize': 5,\n", " 'volumeNum': 94249.88157999996,\n", " 'liquidityNum': 12631.9812,\n", " 'endDateIso': '2026-03-31',\n", " 'startDateIso': '2026-03-30',\n", " 'hasReviewedDates': True,\n", " 'volume24hr': 93644.03624199987,\n", " 'volume1wk': 93644.03624199987,\n", " 'volume1mo': 93644.03624199987,\n", " 'volume1yr': 93644.03624199987,\n", " 'clobTokenIds': '[\"13157292356296687506747919717798752029699544499054519087985411865141996614822\", \"70507961363566124468475538524172170043725846352735387705515911177933084557518\"]',\n", " 'volume24hrClob': 93644.03624199987,\n", " 'volume1wkClob': 93644.03624199987,\n", " 'volume1moClob': 93644.03624199987,\n", " 'volume1yrClob': 93644.03624199987,\n", " 'volumeClob': 94249.88157999996,\n", " 'liquidityClob': 12631.9812,\n", " 'makerBaseFee': 1000,\n", " 'takerBaseFee': 1000,\n", " 'acceptingOrders': True,\n", " 'negRisk': False,\n", " 'ready': False,\n", " 'funded': False,\n", " 'acceptingOrdersTimestamp': '2026-03-30T05:52:46Z',\n", " 'cyom': False,\n", " 'competitive': 0.8767123287671234,\n", " 'pagerDutyNotificationEnabled': False,\n", " 'approved': True,\n", " 'rewardsMinSize': 50,\n", " 'rewardsMaxSpread': 4.5,\n", " 'spread': 0.01,\n", " 'lastTradePrice': 0.89,\n", " 'bestBid': 0.87,\n", " 'bestAsk': 0.88,\n", " 'automaticallyActive': True,\n", " 'clearBookOnStart': False,\n", " 'showGmpSeries': False,\n", " 'showGmpOutcome': False,\n", " 'manualActivation': False,\n", " 'negRiskOther': False,\n", " 'umaResolutionStatuses': '[]',\n", " 'pendingDeployment': False,\n", " 'deploying': False,\n", " 'rfqEnabled': False,\n", " 'eventStartTime': '2026-03-31T05:45:00Z',\n", " 'holdingRewardsEnabled': False,\n", " 'feesEnabled': True,\n", " 'requiresTranslation': False,\n", " 'makerRebatesFeeShareBps': 10000,\n", " 'feeType': 'crypto_fees_v2',\n", " 'feeSchedule': {'exponent': 1,\n", " 'rate': 0.072,\n", " 'takerOnly': True,\n", " 'rebateRate': 0.2}}" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "market" ] }, { "cell_type": "code", "execution_count": 132, "id": "5ba43ffc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Up': '29663568421665501825278796284809925893978140634751674792176179244450686939029',\n", " 'Down': '17234806616394620691850452772328817031586809400835664344689152810552758258009',\n", " 'isActive': False,\n", " 'MinTickSize': 0.01,\n", " 'isNegRisk': False,\n", " 'ConditionId': '0x1778b4a38f2ce99260f9d3d0d78729d37fbd24439e06e6c92aad429439e0f7b2'}" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "market_details" ] }, { "cell_type": "code", "execution_count": 124, "id": "5d356d3b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "creating client...\n", "You've made 55 trades\n", "client created successfully!\n" ] } ], "source": [ "client = api.create_client()" ] }, { "cell_type": "code", "execution_count": 128, "id": "de5ccc3a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7.6829" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "collateral = client.get_balance_allowance(\n", " BalanceAllowanceParams(\n", " asset_type='CONDITIONAL',\n", " token_id='29663568421665501825278796284809925893978140634751674792176179244450686939029',\n", " )\n", ")\n", "a = collateral['balance']\n", "a = int(a) / 1_000_000\n", "a" ] }, { "cell_type": "code", "execution_count": 129, "id": "40323f8d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'balance': '7682900',\n", " 'allowances': {'0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E': '115792089237316195398462578067141184799968521174335529155754622898352762650625',\n", " '0xC5d563A36AE78145C45a50134d48A1215220f80a': '115792089237316195398462578067141184799968521174335529155754622898352762650625',\n", " '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296': '115792089237316195398462578067141184799968521174335529155754622898352762650625'}}" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "collateral" ] }, { "cell_type": "code", "execution_count": 119, "id": "45fe4f53", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'balance': '24494337',\n", " 'allowances': {'0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E': '115792089237316195423570985008687907853269984665640564039457584007912981179951',\n", " '0xC5d563A36AE78145C45a50134d48A1215220f80a': '115792089237316195423570985008687907853269984665640564039457584007913129639935',\n", " '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296': '115792089237316195423570985008687907853269984665640564039457584007913129639935'}}" ] }, "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ "collateral" ] }, { "cell_type": "code", "execution_count": null, "id": "6cf19a23", "metadata": {}, "outputs": [], "source": [ "client.cancel(order_id=)" ] }, { "cell_type": "code", "execution_count": 106, "id": "bebb53eb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'price': '0.3', 'side': 'BUY'}\n" ] } ], "source": [ "last = client.get_last_trade_price(market_details['Up'])\n", "print(last)" ] }, { "cell_type": "code", "execution_count": 109, "id": "1c5a6c9a", "metadata": {}, "outputs": [], "source": [ "d = client.cancel_all()" ] }, { "cell_type": "code", "execution_count": null, "id": "7bc2b7e7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bool(d['not_canceled'])" ] }, { "cell_type": "code", "execution_count": null, "id": "52c0c38a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[{'errorMsg': '', 'orderID': '0x575c43f35b1f5e3e01779df5293d987dc81a347a4e09423a856ecb45555e30cb', 'takingAmount': '', 'makingAmount': '', 'status': 'live', 'success': True}]\n" ] } ], "source": [ "### POST \n", "response = client.post_orders([\n", " PostOrdersArgs(\n", " order=client.create_order(\n", " order_args=OrderArgs(\n", " token_id=market_details['Up'],\n", " price=0.1,\n", " size=10,\n", " side=BUY,\n", " ),\n", " options=PartialCreateOrderOptions(\n", " tick_size=str(market_details['MinTickSize']),\n", " neg_risk=market_details['isNegRisk']\n", " ),\n", " ),\n", " orderType=OrderType.GTC,\n", " postOnly=False,\n", " ),\n", " # PostOrdersArgs(\n", " # order=client.create_order(\n", " # order_args=OrderArgs(\n", " # token_id=market_details['Down'],\n", " # price=0.10,\n", " # size=10,\n", " # side=BUY,\n", " # ),\n", " # options=PartialCreateOrderOptions(\n", " # tick_size=str(market_details['MinTickSize']),\n", " # neg_risk=market_details['isNegRisk']\n", " # ),\n", " # ),\n", " # orderType=OrderType.GTC,\n", " # postOnly=True,\n", " # ),\n", "])\n", "\n", "print(response)" ] }, { "cell_type": "code", "execution_count": 15, "id": "52a7229b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'errorMsg': '',\n", " 'orderID': '0x483e094216d6453f0398875094a29a29a913b103fb1180164e092e3ee65209fe',\n", " 'takingAmount': '',\n", " 'makingAmount': '',\n", " 'status': 'live',\n", " 'success': True}]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response" ] }, { "cell_type": "code", "execution_count": null, "id": "bbed2536", "metadata": {}, "outputs": [], "source": [ "### POST \n", "response = client.post_orders([\n", " PostOrdersArgs(\n", " order=client.create_order(\n", " order_args=OrderArgs(\n", " token_id=market_details['Up'],\n", " price=0.1,\n", " size=10,\n", " side=BUY,\n", " ),\n", " options=PartialCreateOrderOptions(\n", " tick_size=str(market_details['MinTickSize']),\n", " neg_risk=market_details['isNegRisk']\n", " ),\n", " ),\n", " orderType=OrderType.GTC,\n", " postOnly=False,\n", " ),\n", " # PostOrdersArgs(\n", " # order=client.create_order(\n", " # order_args=OrderArgs(\n", " # token_id=market_details['Down'],\n", " # price=0.10,\n", " # size=10,\n", " # side=BUY,\n", " # ),\n", " # options=PartialCreateOrderOptions(\n", " # tick_size=str(market_details['MinTickSize']),\n", " # neg_risk=market_details['isNegRisk']\n", " # ),\n", " # ),\n", " # orderType=OrderType.GTC,\n", " # postOnly=True,\n", " # ),\n", "])\n", "\n", "print(response)" ] }, { "cell_type": "code", "execution_count": 138, "id": "9ec69680", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'errorMsg': '',\n", " 'orderID': '0x575c43f35b1f5e3e01779df5293d987dc81a347a4e09423a856ecb45555e30cb',\n", " 'takingAmount': '',\n", " 'makingAmount': '',\n", " 'status': 'live',\n", " 'success': True}]" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "response" ] }, { "cell_type": "code", "execution_count": null, "id": "b7234035", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "4b3ccf83", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 68, "id": "75d45cd8", "metadata": {}, "outputs": [], "source": [ "d = [{'asset_id': '97987758532314346863331680319607711694838937984814950023901315671390566048932', 'price': '0.37', 'size': '429.41', 'side': 'BUY', 'hash': '999d5b73d83a840c0df7dc2d817ae55a242845d5', 'best_bid': '0.37', 'best_ask': '0.38'}, {'asset_id': '92959981857766705879127008770062050214089835506649207585188324269480756219695', 'price': '0.63', 'size': '429.41', 'side': 'SELL', 'hash': 'ead5af5a55f8b125b1e50f1c80a783c3c2d33187', 'best_bid': '0.62', 'best_ask': '0.63'}]" ] }, { "cell_type": "code", "execution_count": null, "id": "2fe32a82", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-30 23:32:03')" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hist_trades_lookback_ts = round(datetime.now().timestamp() - 10)*1000\n", "pd.to_datetime(hist_trades_lookback_ts*1000, unit='ms')" ] }, { "cell_type": "code", "execution_count": 81, "id": "2a3b19f2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-30 04:22:23.585000')" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.to_datetime(1774844543585, unit='ms')" ] }, { "cell_type": "code", "execution_count": 79, "id": "b5139910", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1774913409000" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hist_trades_lookback_ts*1000" ] }, { "cell_type": "code", "execution_count": null, "id": "d6d3c1bb", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "n = np.empty((0, 3))\n", "np.append(n, [1,2,3])" ] }, { "cell_type": "code", "execution_count": null, "id": "1e5cba44", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 75, "id": "c099da9a", "metadata": {}, "outputs": [], "source": [ "start = 1774585800\n", "end = 1774585800 + 60*5" ] }, { "cell_type": "code", "execution_count": null, "id": "b631306d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-27 04:35:00')" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.to_datetime(start, unit='s')" ] }, { "cell_type": "code", "execution_count": 77, "id": "685d7dd9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "300" ] }, "execution_count": 77, "metadata": {}, "output_type": "execute_result" } ], "source": [ "end - start" ] }, { "cell_type": "code", "execution_count": 78, "id": "bdd681cc", "metadata": {}, "outputs": [], "source": [ "def format_timestamp(total_seconds):\n", " minutes, seconds = divmod(total_seconds, 60)\n", " print(f\"{minutes} minutes and {seconds} seconds\")" ] }, { "cell_type": "code", "execution_count": 79, "id": "7ba83cea", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5 minutes and 0 seconds\n" ] } ], "source": [ "format_timestamp(end - start)" ] }, { "cell_type": "code", "execution_count": 88, "id": "4e211e0d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1774586619" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(datetime.now().timestamp())" ] }, { "cell_type": "code", "execution_count": null, "id": "5dabe016", "metadata": {}, "outputs": [], "source": [ "1774585800" ] }, { "cell_type": "code", "execution_count": 111, "id": "8a65ba6f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-27 03:20:00')" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.to_datetime(1774581600, unit='s')" ] }, { "cell_type": "code", "execution_count": 91, "id": "83f63c10", "metadata": {}, "outputs": [], "source": [ "sdt = '2026-03-27T03:20:00Z'" ] }, { "cell_type": "code", "execution_count": 110, "id": "1f907a71", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1774581600" ] }, "execution_count": 110, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(datetime.strptime(sdt, '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=timezone.utc).timestamp())" ] }, { "cell_type": "code", "execution_count": 113, "id": "fe7c0c12", "metadata": {}, "outputs": [], "source": [ "d = {\"connection_id\":\"a4-i0ecArPECFLQ=\",\"payload\":{\"full_accuracy_value\":\"65779051825748830000000\",\"symbol\":\"btc/usd\",\"timestamp\":1774627572000,\"value\":65779.05182574883},\"timestamp\":1774627573524,\"topic\":\"crypto_prices_chainlink\",\"type\":\"update\"}" ] }, { "cell_type": "code", "execution_count": 114, "id": "a98ace05", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'connection_id': 'a4-i0ecArPECFLQ=',\n", " 'payload': {'full_accuracy_value': '65779051825748830000000',\n", " 'symbol': 'btc/usd',\n", " 'timestamp': 1774627572000,\n", " 'value': 65779.05182574883},\n", " 'timestamp': 1774627573524,\n", " 'topic': 'crypto_prices_chainlink',\n", " 'type': 'update'}" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d" ] }, { "cell_type": "code", "execution_count": 120, "id": "d2278853", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-27 16:06:13.524000')" ] }, "execution_count": 120, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.to_datetime(d['timestamp'], unit='ms')" ] }, { "cell_type": "code", "execution_count": 140, "id": "008cb5c9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Up': '13157292356296687506747919717798752029699544499054519087985411865141996614822',\n", " 'Down': '70507961363566124468475538524172170043725846352735387705515911177933084557518',\n", " 'isActive': False,\n", " 'MinTickSize': 0.01,\n", " 'isNegRisk': False,\n", " 'ConditionId': '0xd1773b412dacad884c202a7b14f0197918b1e22028ce2b5737fbd659bbe150f0'}" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "market_details" ] }, { "cell_type": "code", "execution_count": 130, "id": "f6c647b7", "metadata": {}, "outputs": [], "source": [ "d = {\"id\":\"0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0\",\"owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"market\":\"0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6\",\"asset_id\":\"39378292107289994981363071337831788209917841322683175778910172170676449806535\",\"side\":\"BUY\",\"order_owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"original_size\":\"10\",\"size_matched\":\"0\",\"price\":\"0.2\",\"associate_trades\":[],\"outcome\":\"Up\",\"type\":\"PLACEMENT\",\"created_at\":\"1774818626\",\"expiration\":\"0\",\"order_type\":\"GTC\",\"status\":\"LIVE\",\"maker_address\":\"0xb2967A7e578E700E27611238B7F762BdADC72CcB\",\"timestamp\":\"1774818626080\",\"event_type\":\"order\"}\n", "e = {\"id\":\"0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0\",\"owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"market\":\"0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6\",\"asset_id\":\"39378292107289994981363071337831788209917841322683175778910172170676449806535\",\"side\":\"BUY\",\"order_owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"original_size\":\"10\",\"size_matched\":\"0\",\"price\":\"0.2\",\"associate_trades\":[],\"outcome\":\"Up\",\"type\":\"PLACEMENT\",\"created_at\":\"1774818626\",\"expiration\":\"0\",\"order_type\":\"GTC\",\"status\":\"LIVE\",\"maker_address\":\"0xb2967A7e578E700E27611238B7F762BdADC72CcB\",\"timestamp\":\"9774818626080\",\"event_type\":\"order\"}" ] }, { "cell_type": "code", "execution_count": 131, "id": "00c55bf5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': '0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0',\n", " 'owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'market': '0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6',\n", " 'asset_id': '39378292107289994981363071337831788209917841322683175778910172170676449806535',\n", " 'side': 'BUY',\n", " 'order_owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'original_size': '10',\n", " 'size_matched': '0',\n", " 'price': '0.2',\n", " 'associate_trades': [],\n", " 'outcome': 'Up',\n", " 'type': 'PLACEMENT',\n", " 'created_at': '1774818626',\n", " 'expiration': '0',\n", " 'order_type': 'GTC',\n", " 'status': 'LIVE',\n", " 'maker_address': '0xb2967A7e578E700E27611238B7F762BdADC72CcB',\n", " 'timestamp': '1774818626080',\n", " 'event_type': 'order'}" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d" ] }, { "cell_type": "code", "execution_count": 7, "id": "cf38819c", "metadata": {}, "outputs": [], "source": [ "f = {\"id\":\"0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0\",\"owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"market\":\"0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6\",\"asset_id\":\"39378292107289994981363071337831788209917841322683175778910172170676449806535\",\"side\":\"BUY\",\"order_owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"original_size\":\"10\",\"size_matched\":\"0\",\"price\":\"0.2\",\"associate_trades\":[],\"outcome\":\"Up\",\"type\":\"CANCELLATION\",\"created_at\":\"1774818626\",\"expiration\":\"0\",\"order_type\":\"GTC\",\"status\":\"CANCELED\",\"maker_address\":\"0xb2967A7e578E700E27611238B7F762BdADC72CcB\",\"timestamp\":\"1774818630291\",\"event_type\":\"order\"}" ] }, { "cell_type": "code", "execution_count": null, "id": "ea67fb64", "metadata": {}, "outputs": [], "source": [ "a = json.dumps(f['associate_trades']) if len(f['associate_trades']) > 0 else None" ] }, { "cell_type": "code", "execution_count": null, "id": "59521b6e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "6b4ee964", "metadata": {}, "outputs": [], "source": [ "def live_orders_only(live_orders, new_msg):\n", " return [d for d in live_orders if d.get('status')=='live']" ] }, { "cell_type": "code", "execution_count": 117, "id": "715d8606", "metadata": {}, "outputs": [], "source": [ "def upsert_list_of_dicts_by_id(list_of_dicts, new_dict):\n", " for index, item in enumerate(list_of_dicts):\n", " if item.get('id') == new_dict.get('id'):\n", " list_of_dicts[index] = new_dict\n", " return list_of_dicts\n", " \n", " list_of_dicts.append(new_dict)\n", " return list_of_dicts" ] }, { "cell_type": "code", "execution_count": 113, "id": "4c00fdb7", "metadata": {}, "outputs": [], "source": [ "ORDERS_STATUS = []\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d8a2bbbf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': '0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0',\n", " 'owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'market': '0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6',\n", " 'asset_id': '39378292107289994981363071337831788209917841322683175778910172170676449806535',\n", " 'side': 'BUY',\n", " 'order_owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'original_size': '10',\n", " 'size_matched': '0',\n", " 'price': '0.2',\n", " 'associate_trades': [],\n", " 'outcome': 'Up',\n", " 'type': 'PLACEMENT',\n", " 'created_at': '1774818626',\n", " 'expiration': '0',\n", " 'order_type': 'GTC',\n", " 'status': 'LIVE',\n", " 'maker_address': '0xb2967A7e578E700E27611238B7F762BdADC72CcB',\n", " 'timestamp': '1774818626080',\n", " 'event_type': 'order'}]" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ORDERS_STATUS = upsert_list_of_dicts_by_id(ORDERS_STATUS, d)\n", "ORDERS_STATUS" ] }, { "cell_type": "code", "execution_count": null, "id": "6e8be4ab", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': '0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0',\n", " 'owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'market': '0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6',\n", " 'asset_id': '39378292107289994981363071337831788209917841322683175778910172170676449806535',\n", " 'side': 'BUY',\n", " 'order_owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'original_size': '10',\n", " 'size_matched': '0',\n", " 'price': '0.2',\n", " 'associate_trades': [],\n", " 'outcome': 'Up',\n", " 'type': 'PLACEMENT',\n", " 'created_at': '1774818626',\n", " 'expiration': '0',\n", " 'order_type': 'GTC',\n", " 'status': 'LIVE',\n", " 'maker_address': '0xb2967A7e578E700E27611238B7F762BdADC72CcB',\n", " 'timestamp': '9774818626080',\n", " 'event_type': 'order'}]" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ORDERS_STATUS = upsert_list_of_dicts_by_id(ORDERS_STATUS, e)\n", "ORDERS_STATUS" ] }, { "cell_type": "code", "execution_count": null, "id": "f3b0a0c2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'id': '0x73c6d7c0cba705a06d840c185ef188a195b3e36472dceab61cee23202ec7a9a0',\n", " 'owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'market': '0xf856ff89eb9ed2ab393a1bbc496b5db539b4d7f9cec91202b13c97379e9e58d6',\n", " 'asset_id': '39378292107289994981363071337831788209917841322683175778910172170676449806535',\n", " 'side': 'BUY',\n", " 'order_owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'original_size': '10',\n", " 'size_matched': '0',\n", " 'price': '0.2',\n", " 'associate_trades': [],\n", " 'outcome': 'Up',\n", " 'type': 'CANCELLATION',\n", " 'created_at': '1774818626',\n", " 'expiration': '0',\n", " 'order_type': 'GTC',\n", " 'status': 'CANCELED',\n", " 'maker_address': '0xb2967A7e578E700E27611238B7F762BdADC72CcB',\n", " 'timestamp': '1774818630291',\n", " 'event_type': 'order'}]" ] }, "execution_count": 116, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ORDERS_STATUS = upsert_list_of_dicts_by_id(ORDERS_STATUS, f)\n", "ORDERS_STATUS" ] }, { "cell_type": "code", "execution_count": null, "id": "6be0d1e8", "metadata": {}, "outputs": [], "source": [ "{\n", " \"event_type\": \"order\",\n", " \"id\": \"0xff354cd7ca7539dfa9c28d90943ab5779a4eac34b9b37a757d7b32bdfb11790b\",\n", " \"owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\",\n", " \"market\": \"0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af\",\n", " \"asset_id\": \"52114319501245915516055106046884209969926127482827954674443846427813813222426\",\n", " \"side\": \"SELL\",\n", " \"order_owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\",\n", " \"original_size\": \"10\",\n", " \"size_matched\": \"0\",\n", " \"price\": \"0.57\",\n", " \"associate_trades\": null,\n", " \"outcome\": \"YES\",\n", " \"type\": \"PLACEMENT\",\n", " \"created_at\": \"1672290687\",\n", " \"expiration\": \"1234567\",\n", " \"order_type\": \"GTD\",\n", " \"status\": \"LIVE\",\n", " \"maker_address\": \"0x1234...\",\n", " \"timestamp\": \"1672290687\"\n", "}" ] }, { "cell_type": "code", "execution_count": 10, "id": "761e4f8a", "metadata": {}, "outputs": [], "source": [ "z = {\n", " \"event_type\": \"trade\",\n", " \"type\": \"TRADE\",\n", " \"id\": \"28c4d2eb-bbea-40e7-a9f0-b2fdb56b2c2e\",\n", " \"taker_order_id\": \"0x06bc63e346ed4ceddce9efd6b3af37c8f8f440c92fe7da6b2d0f9e4ccbc50c42\",\n", " \"market\": \"0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af\",\n", " \"asset_id\": \"52114319501245915516055106046884209969926127482827954674443846427813813222426\",\n", " \"side\": \"BUY\",\n", " \"size\": \"10\",\n", " \"price\": \"0.57\",\n", " \"fee_rate_bps\": \"0\",\n", " \"status\": \"MATCHED\",\n", " \"matchtime\": \"1672290701\",\n", " \"last_update\": \"1672290701\",\n", " \"outcome\": \"YES\",\n", " \"owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\",\n", " \"trade_owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\",\n", " \"maker_address\": \"0x1234...\",\n", " \"transaction_hash\": \"\",\n", " \"bucket_index\": 0,\n", " \"maker_orders\": [\n", " {\n", " \"order_id\": \"0xff354cd7ca7539dfa9c28d90943ab5779a4eac34b9b37a757d7b32bdfb11790b\",\n", " \"owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\",\n", " \"maker_address\": \"0x5678...\",\n", " \"matched_amount\": \"10\",\n", " \"price\": \"0.57\",\n", " \"fee_rate_bps\": \"0\",\n", " \"asset_id\": \"52114319501245915516055106046884209969926127482827954674443846427813813222426\",\n", " \"outcome\": \"YES\",\n", " \"side\": \"SELL\"\n", " }\n", " ],\n", " \"trader_side\": \"TAKER\",\n", " \"timestamp\": \"1672290701\"\n", "}" ] }, { "cell_type": "code", "execution_count": 17, "id": "3c5a0922", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'event_type': 'trade',\n", " 'type': 'TRADE',\n", " 'id': '28c4d2eb-bbea-40e7-a9f0-b2fdb56b2c2e',\n", " 'taker_order_id': '0x06bc63e346ed4ceddce9efd6b3af37c8f8f440c92fe7da6b2d0f9e4ccbc50c42',\n", " 'market': '0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af',\n", " 'asset_id': '52114319501245915516055106046884209969926127482827954674443846427813813222426',\n", " 'side': 'BUY',\n", " 'size': '10',\n", " 'price': '0.57',\n", " 'fee_rate_bps': '0',\n", " 'status': 'MATCHED',\n", " 'matchtime': '1672290701',\n", " 'last_update': '1672290701',\n", " 'outcome': 'YES',\n", " 'owner': '9180014b-33c8-9240-a14b-bdca11c0a465',\n", " 'trade_owner': '9180014b-33c8-9240-a14b-bdca11c0a465',\n", " 'maker_address': '0x1234...',\n", " 'transaction_hash': '',\n", " 'bucket_index': 0,\n", " 'maker_orders': [{'order_id': '0xff354cd7ca7539dfa9c28d90943ab5779a4eac34b9b37a757d7b32bdfb11790b',\n", " 'owner': '9180014b-33c8-9240-a14b-bdca11c0a465',\n", " 'maker_address': '0x5678...',\n", " 'matched_amount': '10',\n", " 'price': '0.57',\n", " 'fee_rate_bps': '0',\n", " 'asset_id': '52114319501245915516055106046884209969926127482827954674443846427813813222426',\n", " 'outcome': 'YES',\n", " 'side': 'SELL'}],\n", " 'trader_side': 'TAKER',\n", " 'timestamp': '1672290701'}" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'[{\"order_id\": \"0xff354cd7ca7539dfa9c28d90943ab5779a4eac34b9b37a757d7b32bdfb11790b\", \"owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\", \"maker_address\": \"0x5678...\", \"matched_amount\": \"10\", \"price\": \"0.57\", \"fee_rate_bps\": \"0\", \"asset_id\": \"52114319501245915516055106046884209969926127482827954674443846427813813222426\", \"outcome\": \"YES\", \"side\": \"SELL\"}]'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import json\n", "json.dumps(z['maker_orders'])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "z['maker_orders'] = json.dumps(z['maker_orders'])" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'event_type': 'trade',\n", " 'type': 'TRADE',\n", " 'id': '28c4d2eb-bbea-40e7-a9f0-b2fdb56b2c2e',\n", " 'taker_order_id': '0x06bc63e346ed4ceddce9efd6b3af37c8f8f440c92fe7da6b2d0f9e4ccbc50c42',\n", " 'market': '0xbd31dc8a20211944f6b70f31557f1001557b59905b7738480ca09bd4532f84af',\n", " 'asset_id': '52114319501245915516055106046884209969926127482827954674443846427813813222426',\n", " 'side': 'BUY',\n", " 'size': '10',\n", " 'price': '0.57',\n", " 'fee_rate_bps': '0',\n", " 'status': 'MATCHED',\n", " 'matchtime': '1672290701',\n", " 'last_update': '1672290701',\n", " 'outcome': 'YES',\n", " 'owner': '9180014b-33c8-9240-a14b-bdca11c0a465',\n", " 'trade_owner': '9180014b-33c8-9240-a14b-bdca11c0a465',\n", " 'maker_address': '0x1234...',\n", " 'transaction_hash': '',\n", " 'bucket_index': 0,\n", " 'maker_orders': '[{\"order_id\": \"0xff354cd7ca7539dfa9c28d90943ab5779a4eac34b9b37a757d7b32bdfb11790b\", \"owner\": \"9180014b-33c8-9240-a14b-bdca11c0a465\", \"maker_address\": \"0x5678...\", \"matched_amount\": \"10\", \"price\": \"0.57\", \"fee_rate_bps\": \"0\", \"asset_id\": \"52114319501245915516055106046884209969926127482827954674443846427813813222426\", \"outcome\": \"YES\", \"side\": \"SELL\"}]',\n", " 'trader_side': 'TAKER',\n", " 'timestamp': '1672290701'}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z" ] }, { "cell_type": "code", "execution_count": 29, "id": "0dbb8fa9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1774899574594" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datetime import datetime\n", "import pandas as pd\n", "round(datetime.now().timestamp()*1000)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-30 19:39:16.685000')" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.to_datetime(1774899556685, unit='ms')" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-03-30 19:39:06.685000')" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.to_datetime(1774899556685-10*1000, unit='ms')" ] }, { "cell_type": "code", "execution_count": null, "id": "e1b8d116", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "6765c7e6", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 50, "id": "d367f55b", "metadata": {}, "outputs": [], "source": [ "d = {\"type\":\"TRADE\",\"id\":\"08045b74-925f-4982-bc5b-577104db6530\",\"taker_order_id\":\"0xf6c77c6ef4c229c3edf7ba0a2183c4cd1193211787e2fa7fb0e7bf132189b303\",\"market\":\"0x7cdfcb753bebd87214e719497aa1d1b217582dc22746c8543b74e1e53539a9f5\",\"asset_id\":\"56806427206990113501155420994096888900269904953230745602350514810276549822457\",\"side\":\"BUY\",\"size\":\"7.042251\",\"fee_rate_bps\":\"1000\",\"price\":\"0.71\",\"status\":\"MATCHED\",\"match_time\":\"1774900601\",\"last_update\":\"1774900601\",\"outcome\":\"Up\",\"owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"trade_owner\":\"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\",\"maker_address\":\"0xb2967A7e578E700E27611238B7F762BdADC72CcB\",\"transaction_hash\":\"0x454cbaad0da15d095be778773c362af90de43beb6660c78ff155b3877d283882\",\"bucket_index\":0,\"maker_orders\":[{\"order_id\":\"0x4efdbcd86c81df9d6a02d7e35ff92411af76aa3ca6f445ba9d6e3773e812f706\",\"owner\":\"579ba9d5-cc34-1b66-3b70-d5bb5d1ccc18\",\"maker_address\":\"0x5Bde889dC26B097b5eAa2F1F027e01712EBCcbB7\",\"matched_amount\":\"7.042251\",\"price\":\"0.2900000298200107\",\"fee_rate_bps\":\"1000\",\"asset_id\":\"95594709608392853199445131908660268785353291802775571968225275873296398106331\",\"outcome\":\"Down\",\"outcome_index\":0,\"side\":\"BUY\"}],\"trader_side\":\"TAKER\",\"timestamp\":\"1774900601865\",\"event_type\":\"trade\"}" ] }, { "cell_type": "code", "execution_count": 51, "id": "3e8a71a7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'type': 'TRADE',\n", " 'id': '08045b74-925f-4982-bc5b-577104db6530',\n", " 'taker_order_id': '0xf6c77c6ef4c229c3edf7ba0a2183c4cd1193211787e2fa7fb0e7bf132189b303',\n", " 'market': '0x7cdfcb753bebd87214e719497aa1d1b217582dc22746c8543b74e1e53539a9f5',\n", " 'asset_id': '56806427206990113501155420994096888900269904953230745602350514810276549822457',\n", " 'side': 'BUY',\n", " 'size': '7.042251',\n", " 'fee_rate_bps': '1000',\n", " 'price': '0.71',\n", " 'status': 'MATCHED',\n", " 'match_time': '1774900601',\n", " 'last_update': '1774900601',\n", " 'outcome': 'Up',\n", " 'owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'trade_owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8',\n", " 'maker_address': '0xb2967A7e578E700E27611238B7F762BdADC72CcB',\n", " 'transaction_hash': '0x454cbaad0da15d095be778773c362af90de43beb6660c78ff155b3877d283882',\n", " 'bucket_index': 0,\n", " 'maker_orders': [{'order_id': '0x4efdbcd86c81df9d6a02d7e35ff92411af76aa3ca6f445ba9d6e3773e812f706',\n", " 'owner': '579ba9d5-cc34-1b66-3b70-d5bb5d1ccc18',\n", " 'maker_address': '0x5Bde889dC26B097b5eAa2F1F027e01712EBCcbB7',\n", " 'matched_amount': '7.042251',\n", " 'price': '0.2900000298200107',\n", " 'fee_rate_bps': '1000',\n", " 'asset_id': '95594709608392853199445131908660268785353291802775571968225275873296398106331',\n", " 'outcome': 'Down',\n", " 'outcome_index': 0,\n", " 'side': 'BUY'}],\n", " 'trader_side': 'TAKER',\n", " 'timestamp': '1774900601865',\n", " 'event_type': 'trade'}" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d" ] }, { "cell_type": "code", "execution_count": null, "id": "009fab36", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 1, "id": "56b8e1cc", "metadata": {}, "outputs": [], "source": [ "o = {'type': 'TRADE', 'id': '1de1c277-d281-4be5-a388-305beb95e713', 'taker_order_id': '0xc77331796ad40133a2b4d9a387c10d326c180ad1195306240416150e337f0376', 'market': '0x1cdd4f44f73da702120f02962bf02a2599a7573a39b05ac8ca12a24301542e3e', 'asset_id': '108194336731497303295771496985972597853032131719077291707737599874190461476381', 'side': 'BUY', 'size': '5', 'fee_rate_bps': '1000', 'price': '0.7', 'status': 'CONFIRMED', 'match_time': '1775025187', 'last_update': '1775025253', 'outcome': 'Up', 'owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8', 'trade_owner': '00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8', 'maker_address': '0xb2967A7e578E700E27611238B7F762BdADC72CcB', 'transaction_hash': '0x3654fac56e1548bcc14d01ce4888ea0c3cec29d553009e054fc67088ece5f5b3', 'bucket_index': 0, 'maker_orders': [{'order_id': '0xb9a39a5e8082846bfdd92d33fba5112466b939ad7f33b76905982549767acf0a', 'owner': '70dd335a-6089-6022-6726-565c7480b291', 'maker_address': '0x010138da36CF100c00a5A59C8643E4A4A55DF19C', 'matched_amount': '5', 'price': '0.3', 'fee_rate_bps': '1000', 'asset_id': '26175835004768067043908573558643253609047604517388456461023977022509795794691', 'outcome': 'Down', 'outcome_index': 0, 'side': 'BUY'}], 'trader_side': 'TAKER', 'timestamp': '1775025253290', 'event_type': 'trade'}" ] }, { "cell_type": "code", "execution_count": null, "id": "ae50f082", "metadata": {}, "outputs": [], "source": [ "USER_TRADES = [o]\n", "user_trade = next( ( item for item in USER_TRADES if ( o['orderID'] == item['taker_order_id'] ) or ( o[\"orderID\"] == item['maker_orders'][0]['order_id'] ) ), None )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "3f1e3a83", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py_313", "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.13.12" } }, "nbformat": 4, "nbformat_minor": 5 }