{ "cells": [ { "cell_type": "code", "execution_count": 1, "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, OpenOrderParams\n", "from py_clob_client.order_builder.constants import BUY, SELL\n" ] }, { "cell_type": "code", "execution_count": 2, "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": 3, "id": "c3e07e21", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-04-04 05:15:00')" ] }, "execution_count": 3, "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": 4, "id": "10671da4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': '1840714',\n", " 'question': 'Bitcoin Up or Down - April 4, 1:15AM-1:20AM ET',\n", " 'conditionId': '0xa71ed436d160cc45bf182b9004e0c10b16322ea1b41375182b747c2629223ecc',\n", " 'slug': 'btc-updown-5m-1775279700',\n", " 'resolutionSource': 'https://data.chain.link/streams/btc-usd',\n", " 'endDate': '2026-04-04T05:20:00Z',\n", " 'liquidity': '19009.3694',\n", " 'startDate': '2026-04-03T05:23:41.149918Z',\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.505\", \"0.495\"]',\n", " 'volume': '1149.1770909999996',\n", " 'active': True,\n", " 'closed': False,\n", " 'marketMakerAddress': '',\n", " 'createdAt': '2026-04-03T05:22:26.236646Z',\n", " 'updatedAt': '2026-04-04T05:14:58.886334Z',\n", " 'new': False,\n", " 'featured': False,\n", " 'archived': False,\n", " 'restricted': True,\n", " 'groupItemThreshold': '0',\n", " 'questionID': '0x1f7b9fd2711422d90794895b99edcb93a81246afd56b08ee4736c9b57565f8f7',\n", " 'enableOrderBook': True,\n", " 'orderPriceMinTickSize': 0.01,\n", " 'orderMinSize': 5,\n", " 'volumeNum': 1149.1770909999996,\n", " 'liquidityNum': 19009.3694,\n", " 'endDateIso': '2026-04-04',\n", " 'startDateIso': '2026-04-03',\n", " 'hasReviewedDates': True,\n", " 'volume24hr': 1149.1770909999998,\n", " 'volume1wk': 1149.1770909999998,\n", " 'volume1mo': 1149.1770909999998,\n", " 'volume1yr': 1149.1770909999998,\n", " 'clobTokenIds': '[\"111612048087962925846397645788043113901565915142888535086349545305985085081594\", \"12874695654084258339187997850118078073676562138805309130550135898707856234061\"]',\n", " 'volume24hrClob': 1149.1770909999998,\n", " 'volume1wkClob': 1149.1770909999998,\n", " 'volume1moClob': 1149.1770909999998,\n", " 'volume1yrClob': 1149.1770909999998,\n", " 'volumeClob': 1149.1770909999996,\n", " 'liquidityClob': 19009.3694,\n", " 'makerBaseFee': 1000,\n", " 'takerBaseFee': 1000,\n", " 'acceptingOrders': True,\n", " 'negRisk': False,\n", " 'ready': False,\n", " 'funded': False,\n", " 'acceptingOrdersTimestamp': '2026-04-03T05:22:35Z',\n", " 'cyom': False,\n", " 'competitive': 0.9999750006249843,\n", " 'pagerDutyNotificationEnabled': False,\n", " 'approved': True,\n", " 'rewardsMinSize': 50,\n", " 'rewardsMaxSpread': 4.5,\n", " 'spread': 0.01,\n", " 'lastTradePrice': 0.51,\n", " 'bestBid': 0.5,\n", " 'bestAsk': 0.51,\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-04-04T05:15: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": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "market" ] }, { "cell_type": "code", "execution_count": 5, "id": "5ba43ffc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Up': '111612048087962925846397645788043113901565915142888535086349545305985085081594',\n", " 'Down': '12874695654084258339187997850118078073676562138805309130550135898707856234061',\n", " 'isActive': False,\n", " 'MinTickSize': 0.01,\n", " 'isNegRisk': False,\n", " 'ConditionId': '0xa71ed436d160cc45bf182b9004e0c10b16322ea1b41375182b747c2629223ecc'}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "market_details" ] }, { "cell_type": "code", "execution_count": 6, "id": "5d356d3b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "creating client...\n", "You've made 297 trades\n", "client created successfully!\n" ] } ], "source": [ "client = api.create_client()" ] }, { "cell_type": "code", "execution_count": null, "id": "22eb81de", "metadata": {}, "outputs": [], "source": [ "# Filtered by market\n", "order_status = client.get_orders(\n", " OpenOrderParams(id=\"0x9249ce4a8bc67de355b487b00eaa6ce25c1b451867f9350672b25eaa1de08494\")\n", ")[0]['status']" ] }, { "cell_type": "code", "execution_count": 14, "id": "fb3b8151", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'CANCELED'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "order" ] }, { "cell_type": "code", "execution_count": 8, "id": "de5ccc3a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 8, "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': '0x0c701329ddd7881505648c5ebdd03cd6f86ae3a70b0cf150bcb53946e043e6bf', 'takingAmount': '', 'makingAmount': '', 'status': 'live', 'success': True}]\n" ] } ], "source": [ "%%time\n", "### 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": 35, "id": "4d524867", "metadata": {}, "outputs": [], "source": [ "o = {'orderID': '0xaebd4053bd167eb7a7fc48ae29036829582787a73d8cc7b8b1afa7294c474972',\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'}" ] }, { "cell_type": "code", "execution_count": 47, "id": "43a68ee8", "metadata": {}, "outputs": [], "source": [ "ut = {'trade_side':'MAKER', 'taker_order_id': None, 'maker_orders': [{\"side\": \"BUY\", \"owner\": \"f44394d9-7782-e5e5-af99-dd515edd7fd9\", \"price\": \"0.44\", \"outcome\": \"Up\", \"asset_id\": \"55598909213399021321632159985071802901933471635502091907595118948537230110477\", \"order_id\": \"0x7eed6fa75cd49680b738e1563fc9e5dc0f7095c8a7dd3ee1a496c01f4ad2f610\", \"fee_rate_bps\": \"1000\", \"maker_address\": \"0xE29042f5D913DCC4015aaB3455C13C58514CA33F\", \"outcome_index\": 0, \"matched_amount\": \"15.25\"}, {\"side\": \"BUY\", \"owner\": \"520cb8f0-a71b-1c49-8dd6-751e682ee7f8\", \"price\": \"0.44\", \"outcome\": \"Up\", \"asset_id\": \"55598909213399021321632159985071802901933471635502091907595118948537230110477\", \"order_id\": \"0xf7c0a9e322fbf232dce6290f36bbe5e484ccec7fda599ddeb98867f241df6e37\", \"fee_rate_bps\": \"1000\", \"maker_address\": \"0x74a6364297292774c7f9a16B925207E77eEE262D\", \"outcome_index\": 0, \"matched_amount\": \"5\"}, {\"side\": \"BUY\", \"owner\": \"ae0f07ea-bcbe-3d54-6841-f220e89794ae\", \"price\": \"0.44\", \"outcome\": \"Up\", \"asset_id\": \"55598909213399021321632159985071802901933471635502091907595118948537230110477\", \"order_id\": \"0xe321494520de4737980a15160bfae94cb48791a2dc978aa843e7a8504e815771\", \"fee_rate_bps\": \"1000\", \"maker_address\": \"0xDba9C86F8d20ac73BcBf4dedaA6ADbd26A0a1303\", \"outcome_index\": 0, \"matched_amount\": \"5\"}, {\"side\": \"BUY\", \"owner\": \"00e5d36c-6c46-77e1-a436-0f0a4bfbfdd8\", \"price\": \"0.44\", \"outcome\": \"Up\", \"asset_id\": \"55598909213399021321632159985071802901933471635502091907595118948537230110477\", \"order_id\": \"0xaebd4053bd167eb7a7fc48ae29036829582787a73d8cc7b8b1afa7294c474972\", \"fee_rate_bps\": \"1000\", \"maker_address\": \"0xb2967A7e578E700E27611238B7F762BdADC72CcB\", \"outcome_index\": 0, \"matched_amount\": \"4.75\"}]}" ] }, { "cell_type": "code", "execution_count": 45, "id": "ae50f082", "metadata": {}, "outputs": [], "source": [ "USER_TRADES = [ut]\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, "id": "11c111eb", "metadata": {}, "outputs": [], "source": [ "for t in USER_TRADES:\n", " if t['trade_side']=='MAKER':\n", " pass\n", " elif t['taker_order_id'] == o[\"orderID\"]:\n", " pass\n" ] }, { "cell_type": "code", "execution_count": 46, "id": "de38feda", "metadata": {}, "outputs": [], "source": [ "user_trade" ] }, { "cell_type": "code", "execution_count": null, "id": "67b7b730", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "d15d92d3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "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 }