{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "44ff5c50",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from pprint import pprint\n",
"from sqlalchemy import create_engine, text\n",
"import plotly.express as px\n",
"import requests\n",
"import json\n",
"import time\n",
"from datetime import datetime\n",
"import plotly.graph_objects as go\n",
"from plotly.subplots import make_subplots\n",
"import numpy as np\n",
"from sqlalchemy.sql.elements import TextClause"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d3206fe9",
"metadata": {},
"outputs": [],
"source": [
"start_ts = (round(datetime.now().timestamp()*1000)-(60*60*24*1000))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9847869c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2026-05-12 17:05:35.474000')"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime(start_ts, unit='ms')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ca48e11c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Connection successful\n"
]
}
],
"source": [
"### MYSQL ###\n",
"ENGINE = create_engine('mysql+pymysql://root:pwd@localhost/fund_rate')\n",
"try:\n",
" with ENGINE.connect() as conn:\n",
" print(\"Connection successful\")\n",
"except Exception as e:\n",
" print(f\"Connection failed: {e}\") "
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "ec8f5d67",
"metadata": {},
"outputs": [],
"source": [
"### ASTER ###\n",
"aster_orders = text(f'''\n",
" SELECT *\n",
" FROM fr_aster_user_order_trade\n",
" WHERE timestamp_arrival > {start_ts}\n",
"''')\n",
"df_aster_orders = pd.read_sql(aster_orders, con=ENGINE)\n",
"df_aster_orders['timestamp_dt'] = pd.to_datetime(df_aster_orders['timestamp_transaction'], unit='ms')\n",
"df_aster_orders_fill = df_aster_orders.loc[df_aster_orders['execution_type']=='TRADE',:]\n",
"df_aster_orders_fill = df_aster_orders_fill[['timestamp_transaction','order_trade_time_ts','timestamp_dt','order_id','trade_id','client_order_id','order_status','side','last_filled_qty','filled_accumulated_qty','commission','last_filled_price','realized_profit']].reset_index(drop=True)\n",
"\n",
"df_aster_trades = df_aster_orders_fill.groupby('order_id').agg({'timestamp_transaction': 'first','order_trade_time_ts':'last','order_status':'last','side':'last','last_filled_qty':'sum','filled_accumulated_qty':'last','commission':'sum','last_filled_price':'mean','realized_profit':'sum'}).reset_index()\n",
"df_aster_trades['is_mkt_maker'] = df_aster_trades['commission'] == 0.00\n",
"df_aster_trades['timestamp_ts'] = pd.to_datetime(df_aster_trades['order_trade_time_ts'], unit='ms')\n",
"\n",
"df_aster_trades = df_aster_trades.rename({'order_status':'status','filled_accumulated_qty':'filled_qty','commission':'payed_fee','last_filled_price':'price'}, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "1cb4869a",
"metadata": {},
"outputs": [],
"source": [
"### EXTEND ###\n",
"# Load and Transform Orders\n",
"extend_orders = text(f'''\n",
" SELECT *\n",
" FROM fr_extended_user_order\n",
" WHERE timestamp_arrival > {start_ts}\n",
"''')\n",
"df_extend_orders = pd.read_sql(extend_orders, con=ENGINE)\n",
"df_extend_orders['timestamp_dt'] = pd.to_datetime(df_extend_orders['updated_time_ts'], unit='ms')\n",
"df_extend_orders_fill = df_extend_orders.loc[df_extend_orders['status'].isin(['FILLED','PARTIALLY_FILLED']),:]\n",
"df_extend_orders_fill = df_extend_orders_fill[['created_time_ts','updated_time_ts','timestamp_dt','order_id','external_id','status','side','qty','filled_qty','payed_fee','price','averagePrice']].reset_index(drop=True)\n",
"\n",
"# Trades\n",
"df_extend_trades = df_extend_orders_fill.groupby('order_id').agg({'created_time_ts':'first','updated_time_ts':'last','status': 'last','side': 'last', 'filled_qty':'last','payed_fee':'sum','price':'last'}).reset_index()\n",
"df_extend_trades['duration_sec_ast'] = ( df_extend_trades['updated_time_ts'] - df_extend_trades['created_time_ts'] ) / 1000\n",
"df_extend_trades['is_mkt_maker'] = df_extend_trades['payed_fee'] == 0.00\n",
"df_extend_trades['timestamp_ts'] = pd.to_datetime(df_extend_trades['updated_time_ts'], unit='ms')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7b971099",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "order_id",
"rawType": "int64",
"type": "integer"
},
{
"name": "timestamp_transaction",
"rawType": "int64",
"type": "integer"
},
{
"name": "order_trade_time_ts",
"rawType": "int64",
"type": "integer"
},
{
"name": "status",
"rawType": "str",
"type": "string"
},
{
"name": "side",
"rawType": "str",
"type": "string"
},
{
"name": "last_filled_qty",
"rawType": "float64",
"type": "float"
},
{
"name": "filled_qty",
"rawType": "float64",
"type": "float"
},
{
"name": "payed_fee",
"rawType": "float64",
"type": "float"
},
{
"name": "price",
"rawType": "float64",
"type": "float"
},
{
"name": "realized_profit",
"rawType": "float64",
"type": "float"
},
{
"name": "is_mkt_maker",
"rawType": "bool",
"type": "boolean"
},
{
"name": "timestamp_ts",
"rawType": "datetime64[ms]",
"type": "datetime"
}
],
"ref": "9162fd1f-299b-4a19-b0ad-a9ab5dfb6720",
"rows": [
[
"0",
"26752383",
"1778635832800",
"1778635832800",
"FILLED",
"SELL",
"757.0",
"757.0",
"0.0",
"0.06608",
"0.0",
"True",
"2026-05-13 01:30:32.800000"
],
[
"1",
"26826240",
"1778640143050",
"1778640143050",
"FILLED",
"BUY",
"759.0",
"759.0",
"0.0",
"0.06837",
"-1.73353",
"True",
"2026-05-13 02:42:23.050000"
],
[
"2",
"26827279",
"1778640195500",
"1778640195500",
"FILLED",
"SELL",
"735.0",
"735.0",
"0.0",
"0.06818",
"-0.00038",
"True",
"2026-05-13 02:43:15.500000"
],
[
"3",
"27256985",
"1778689283150",
"1778689283150",
"PARTIALLY_FILLED",
"SELL",
"84.0",
"84.0",
"0.0",
"0.06058",
"0.0",
"True",
"2026-05-13 16:21:23.150000"
],
[
"4",
"27258243",
"1778689494600",
"1778689494600",
"FILLED",
"BUY",
"84.0",
"84.0",
"0.0",
"0.06063",
"0.56856279",
"True",
"2026-05-13 16:24:54.600000"
],
[
"5",
"1915182537",
"1778630633200",
"1778630633200",
"FILLED",
"BUY",
"12.46",
"12.46",
"0.0",
"40.126",
"0.0",
"True",
"2026-05-13 00:03:53.200000"
],
[
"6",
"1915208930",
"1778632110150",
"1778632110150",
"PARTIALLY_FILLED",
"SELL",
"0.24",
"0.24",
"0.0",
"40.118",
"-0.00192",
"True",
"2026-05-13 00:28:30.150000"
],
[
"7",
"1915211107",
"1778632239250",
"1778632239250",
"FILLED",
"BUY",
"0.25",
"0.25",
"0.0",
"40.07",
"0.0",
"True",
"2026-05-13 00:30:39.250000"
],
[
"8",
"1915255902",
"1778634754950",
"1778634754950",
"FILLED",
"SELL",
"12.46",
"12.46",
"0.0",
"40.415",
"3.61492877",
"True",
"2026-05-13 01:12:34.950000"
],
[
"9",
"1915281164",
"1778635792250",
"1778635792250",
"FILLED",
"BUY",
"12.3",
"12.3",
"0.0",
"40.628",
"0.0",
"True",
"2026-05-13 01:29:52.250000"
],
[
"10",
"1915281571",
"1778635805550",
"1778635805550",
"FILLED",
"SELL",
"12.3",
"12.3",
"0.0",
"40.654",
"0.32482713",
"True",
"2026-05-13 01:30:05.550000"
],
[
"11",
"1915282188",
"1778635827200",
"1778635827200",
"FILLED",
"SELL",
"0.01",
"0.01",
"0.0",
"40.665",
"0.00037408",
"True",
"2026-05-13 01:30:27.200000"
]
],
"shape": {
"columns": 12,
"rows": 12
}
},
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" order_id | \n",
" timestamp_transaction | \n",
" order_trade_time_ts | \n",
" status | \n",
" side | \n",
" last_filled_qty | \n",
" filled_qty | \n",
" payed_fee | \n",
" price | \n",
" realized_profit | \n",
" is_mkt_maker | \n",
" timestamp_ts | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 26752383 | \n",
" 1778635832800 | \n",
" 1778635832800 | \n",
" FILLED | \n",
" SELL | \n",
" 757.00 | \n",
" 757.00 | \n",
" 0.0 | \n",
" 0.06608 | \n",
" 0.000000 | \n",
" True | \n",
" 2026-05-13 01:30:32.800 | \n",
"
\n",
" \n",
" | 1 | \n",
" 26826240 | \n",
" 1778640143050 | \n",
" 1778640143050 | \n",
" FILLED | \n",
" BUY | \n",
" 759.00 | \n",
" 759.00 | \n",
" 0.0 | \n",
" 0.06837 | \n",
" -1.733530 | \n",
" True | \n",
" 2026-05-13 02:42:23.050 | \n",
"
\n",
" \n",
" | 2 | \n",
" 26827279 | \n",
" 1778640195500 | \n",
" 1778640195500 | \n",
" FILLED | \n",
" SELL | \n",
" 735.00 | \n",
" 735.00 | \n",
" 0.0 | \n",
" 0.06818 | \n",
" -0.000380 | \n",
" True | \n",
" 2026-05-13 02:43:15.500 | \n",
"
\n",
" \n",
" | 3 | \n",
" 27256985 | \n",
" 1778689283150 | \n",
" 1778689283150 | \n",
" PARTIALLY_FILLED | \n",
" SELL | \n",
" 84.00 | \n",
" 84.00 | \n",
" 0.0 | \n",
" 0.06058 | \n",
" 0.000000 | \n",
" True | \n",
" 2026-05-13 16:21:23.150 | \n",
"
\n",
" \n",
" | 4 | \n",
" 27258243 | \n",
" 1778689494600 | \n",
" 1778689494600 | \n",
" FILLED | \n",
" BUY | \n",
" 84.00 | \n",
" 84.00 | \n",
" 0.0 | \n",
" 0.06063 | \n",
" 0.568563 | \n",
" True | \n",
" 2026-05-13 16:24:54.600 | \n",
"
\n",
" \n",
" | 5 | \n",
" 1915182537 | \n",
" 1778630633200 | \n",
" 1778630633200 | \n",
" FILLED | \n",
" BUY | \n",
" 12.46 | \n",
" 12.46 | \n",
" 0.0 | \n",
" 40.12600 | \n",
" 0.000000 | \n",
" True | \n",
" 2026-05-13 00:03:53.200 | \n",
"
\n",
" \n",
" | 6 | \n",
" 1915208930 | \n",
" 1778632110150 | \n",
" 1778632110150 | \n",
" PARTIALLY_FILLED | \n",
" SELL | \n",
" 0.24 | \n",
" 0.24 | \n",
" 0.0 | \n",
" 40.11800 | \n",
" -0.001920 | \n",
" True | \n",
" 2026-05-13 00:28:30.150 | \n",
"
\n",
" \n",
" | 7 | \n",
" 1915211107 | \n",
" 1778632239250 | \n",
" 1778632239250 | \n",
" FILLED | \n",
" BUY | \n",
" 0.25 | \n",
" 0.25 | \n",
" 0.0 | \n",
" 40.07000 | \n",
" 0.000000 | \n",
" True | \n",
" 2026-05-13 00:30:39.250 | \n",
"
\n",
" \n",
" | 8 | \n",
" 1915255902 | \n",
" 1778634754950 | \n",
" 1778634754950 | \n",
" FILLED | \n",
" SELL | \n",
" 12.46 | \n",
" 12.46 | \n",
" 0.0 | \n",
" 40.41500 | \n",
" 3.614929 | \n",
" True | \n",
" 2026-05-13 01:12:34.950 | \n",
"
\n",
" \n",
" | 9 | \n",
" 1915281164 | \n",
" 1778635792250 | \n",
" 1778635792250 | \n",
" FILLED | \n",
" BUY | \n",
" 12.30 | \n",
" 12.30 | \n",
" 0.0 | \n",
" 40.62800 | \n",
" 0.000000 | \n",
" True | \n",
" 2026-05-13 01:29:52.250 | \n",
"
\n",
" \n",
" | 10 | \n",
" 1915281571 | \n",
" 1778635805550 | \n",
" 1778635805550 | \n",
" FILLED | \n",
" SELL | \n",
" 12.30 | \n",
" 12.30 | \n",
" 0.0 | \n",
" 40.65400 | \n",
" 0.324827 | \n",
" True | \n",
" 2026-05-13 01:30:05.550 | \n",
"
\n",
" \n",
" | 11 | \n",
" 1915282188 | \n",
" 1778635827200 | \n",
" 1778635827200 | \n",
" FILLED | \n",
" SELL | \n",
" 0.01 | \n",
" 0.01 | \n",
" 0.0 | \n",
" 40.66500 | \n",
" 0.000374 | \n",
" True | \n",
" 2026-05-13 01:30:27.200 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" order_id timestamp_transaction order_trade_time_ts status \\\n",
"0 26752383 1778635832800 1778635832800 FILLED \n",
"1 26826240 1778640143050 1778640143050 FILLED \n",
"2 26827279 1778640195500 1778640195500 FILLED \n",
"3 27256985 1778689283150 1778689283150 PARTIALLY_FILLED \n",
"4 27258243 1778689494600 1778689494600 FILLED \n",
"5 1915182537 1778630633200 1778630633200 FILLED \n",
"6 1915208930 1778632110150 1778632110150 PARTIALLY_FILLED \n",
"7 1915211107 1778632239250 1778632239250 FILLED \n",
"8 1915255902 1778634754950 1778634754950 FILLED \n",
"9 1915281164 1778635792250 1778635792250 FILLED \n",
"10 1915281571 1778635805550 1778635805550 FILLED \n",
"11 1915282188 1778635827200 1778635827200 FILLED \n",
"\n",
" side last_filled_qty filled_qty payed_fee price realized_profit \\\n",
"0 SELL 757.00 757.00 0.0 0.06608 0.000000 \n",
"1 BUY 759.00 759.00 0.0 0.06837 -1.733530 \n",
"2 SELL 735.00 735.00 0.0 0.06818 -0.000380 \n",
"3 SELL 84.00 84.00 0.0 0.06058 0.000000 \n",
"4 BUY 84.00 84.00 0.0 0.06063 0.568563 \n",
"5 BUY 12.46 12.46 0.0 40.12600 0.000000 \n",
"6 SELL 0.24 0.24 0.0 40.11800 -0.001920 \n",
"7 BUY 0.25 0.25 0.0 40.07000 0.000000 \n",
"8 SELL 12.46 12.46 0.0 40.41500 3.614929 \n",
"9 BUY 12.30 12.30 0.0 40.62800 0.000000 \n",
"10 SELL 12.30 12.30 0.0 40.65400 0.324827 \n",
"11 SELL 0.01 0.01 0.0 40.66500 0.000374 \n",
"\n",
" is_mkt_maker timestamp_ts \n",
"0 True 2026-05-13 01:30:32.800 \n",
"1 True 2026-05-13 02:42:23.050 \n",
"2 True 2026-05-13 02:43:15.500 \n",
"3 True 2026-05-13 16:21:23.150 \n",
"4 True 2026-05-13 16:24:54.600 \n",
"5 True 2026-05-13 00:03:53.200 \n",
"6 True 2026-05-13 00:28:30.150 \n",
"7 True 2026-05-13 00:30:39.250 \n",
"8 True 2026-05-13 01:12:34.950 \n",
"9 True 2026-05-13 01:29:52.250 \n",
"10 True 2026-05-13 01:30:05.550 \n",
"11 True 2026-05-13 01:30:27.200 "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_aster_trades"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "bfde4665",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "order_id",
"rawType": "str",
"type": "string"
},
{
"name": "created_time_ts",
"rawType": "int64",
"type": "integer"
},
{
"name": "updated_time_ts",
"rawType": "int64",
"type": "integer"
},
{
"name": "status",
"rawType": "str",
"type": "string"
},
{
"name": "side",
"rawType": "str",
"type": "string"
},
{
"name": "filled_qty",
"rawType": "float64",
"type": "float"
},
{
"name": "payed_fee",
"rawType": "float64",
"type": "float"
},
{
"name": "price",
"rawType": "float64",
"type": "float"
},
{
"name": "duration_sec_ast",
"rawType": "float64",
"type": "float"
},
{
"name": "is_mkt_maker",
"rawType": "bool",
"type": "boolean"
},
{
"name": "timestamp_ts",
"rawType": "datetime64[ms]",
"type": "datetime"
}
],
"ref": "781309d0-aa71-431d-8e13-b89fdfc6e58e",
"rows": [
[
"0",
"2054351907031711744",
"1778630637304",
"1778630637456",
"FILLED",
"SELL",
"12.5",
"0.125309",
"40.099",
"0.152",
"False",
"2026-05-13 00:03:57.456000"
],
[
"1",
"2054358098285522944",
"1778632113413",
"1778632113566",
"FILLED",
"BUY",
"0.3",
"0.003005",
"40.084",
"0.153",
"False",
"2026-05-13 00:28:33.566000"
],
[
"2",
"2054358642072932352",
"1778632243063",
"1778632243215",
"FILLED",
"SELL",
"0.3",
"0.003003",
"40.05",
"0.152",
"False",
"2026-05-13 00:30:43.215000"
],
[
"3",
"2054366966772473856",
"1778634227826",
"1778634227978",
"FILLED",
"SELL",
"0.1",
"0.001008",
"40.341",
"0.152",
"False",
"2026-05-13 01:03:47.978000"
],
[
"4",
"2054369195076259840",
"1778634759095",
"1778634759248",
"FILLED",
"BUY",
"12.5",
"0.126239",
"40.397",
"0.153",
"False",
"2026-05-13 01:12:39.248000"
],
[
"5",
"2054369204056076288",
"1778634761235",
"1778634761388",
"FILLED",
"BUY",
"0.1",
"0.001009",
"40.389",
"0.153",
"False",
"2026-05-13 01:12:41.388000"
],
[
"6",
"2054373534490554368",
"1778635793692",
"1778635793845",
"FILLED",
"SELL",
"12.3",
"0.124838",
"40.598",
"0.153",
"False",
"2026-05-13 01:29:53.845000"
],
[
"7",
"2054373594473218048",
"1778635807993",
"1778635808762",
"FILLED",
"BUY",
"12.3",
"0.0",
"40.627",
"0.769",
"True",
"2026-05-13 01:30:08.762000"
],
[
"8",
"2054373724560035840",
"1778635839007",
"1778635839160",
"FILLED",
"BUY",
"750.0",
"0.012374",
"0.066033",
"0.153",
"False",
"2026-05-13 01:30:39.160000"
],
[
"9",
"2054391807521476608",
"1778640150321",
"1778640150474",
"FILLED",
"SELL",
"720.0",
"0.01231",
"0.068383",
"0.153",
"False",
"2026-05-13 02:42:30.474000"
],
[
"10",
"2054392042100424704",
"1778640206249",
"1778640206402",
"FILLED",
"BUY",
"700.0",
"0.011938",
"0.068218",
"0.153",
"False",
"2026-05-13 02:43:26.402000"
]
],
"shape": {
"columns": 11,
"rows": 11
}
},
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" order_id | \n",
" created_time_ts | \n",
" updated_time_ts | \n",
" status | \n",
" side | \n",
" filled_qty | \n",
" payed_fee | \n",
" price | \n",
" duration_sec_ast | \n",
" is_mkt_maker | \n",
" timestamp_ts | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" 2054351907031711744 | \n",
" 1778630637304 | \n",
" 1778630637456 | \n",
" FILLED | \n",
" SELL | \n",
" 12.5 | \n",
" 0.125309 | \n",
" 40.099000 | \n",
" 0.152 | \n",
" False | \n",
" 2026-05-13 00:03:57.456 | \n",
"
\n",
" \n",
" | 1 | \n",
" 2054358098285522944 | \n",
" 1778632113413 | \n",
" 1778632113566 | \n",
" FILLED | \n",
" BUY | \n",
" 0.3 | \n",
" 0.003005 | \n",
" 40.084000 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 00:28:33.566 | \n",
"
\n",
" \n",
" | 2 | \n",
" 2054358642072932352 | \n",
" 1778632243063 | \n",
" 1778632243215 | \n",
" FILLED | \n",
" SELL | \n",
" 0.3 | \n",
" 0.003003 | \n",
" 40.050000 | \n",
" 0.152 | \n",
" False | \n",
" 2026-05-13 00:30:43.215 | \n",
"
\n",
" \n",
" | 3 | \n",
" 2054366966772473856 | \n",
" 1778634227826 | \n",
" 1778634227978 | \n",
" FILLED | \n",
" SELL | \n",
" 0.1 | \n",
" 0.001008 | \n",
" 40.341000 | \n",
" 0.152 | \n",
" False | \n",
" 2026-05-13 01:03:47.978 | \n",
"
\n",
" \n",
" | 4 | \n",
" 2054369195076259840 | \n",
" 1778634759095 | \n",
" 1778634759248 | \n",
" FILLED | \n",
" BUY | \n",
" 12.5 | \n",
" 0.126239 | \n",
" 40.397000 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 01:12:39.248 | \n",
"
\n",
" \n",
" | 5 | \n",
" 2054369204056076288 | \n",
" 1778634761235 | \n",
" 1778634761388 | \n",
" FILLED | \n",
" BUY | \n",
" 0.1 | \n",
" 0.001009 | \n",
" 40.389000 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 01:12:41.388 | \n",
"
\n",
" \n",
" | 6 | \n",
" 2054373534490554368 | \n",
" 1778635793692 | \n",
" 1778635793845 | \n",
" FILLED | \n",
" SELL | \n",
" 12.3 | \n",
" 0.124838 | \n",
" 40.598000 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 01:29:53.845 | \n",
"
\n",
" \n",
" | 7 | \n",
" 2054373594473218048 | \n",
" 1778635807993 | \n",
" 1778635808762 | \n",
" FILLED | \n",
" BUY | \n",
" 12.3 | \n",
" 0.000000 | \n",
" 40.627000 | \n",
" 0.769 | \n",
" True | \n",
" 2026-05-13 01:30:08.762 | \n",
"
\n",
" \n",
" | 8 | \n",
" 2054373724560035840 | \n",
" 1778635839007 | \n",
" 1778635839160 | \n",
" FILLED | \n",
" BUY | \n",
" 750.0 | \n",
" 0.012374 | \n",
" 0.066033 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 01:30:39.160 | \n",
"
\n",
" \n",
" | 9 | \n",
" 2054391807521476608 | \n",
" 1778640150321 | \n",
" 1778640150474 | \n",
" FILLED | \n",
" SELL | \n",
" 720.0 | \n",
" 0.012310 | \n",
" 0.068383 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 02:42:30.474 | \n",
"
\n",
" \n",
" | 10 | \n",
" 2054392042100424704 | \n",
" 1778640206249 | \n",
" 1778640206402 | \n",
" FILLED | \n",
" BUY | \n",
" 700.0 | \n",
" 0.011938 | \n",
" 0.068218 | \n",
" 0.153 | \n",
" False | \n",
" 2026-05-13 02:43:26.402 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" order_id created_time_ts updated_time_ts status side \\\n",
"0 2054351907031711744 1778630637304 1778630637456 FILLED SELL \n",
"1 2054358098285522944 1778632113413 1778632113566 FILLED BUY \n",
"2 2054358642072932352 1778632243063 1778632243215 FILLED SELL \n",
"3 2054366966772473856 1778634227826 1778634227978 FILLED SELL \n",
"4 2054369195076259840 1778634759095 1778634759248 FILLED BUY \n",
"5 2054369204056076288 1778634761235 1778634761388 FILLED BUY \n",
"6 2054373534490554368 1778635793692 1778635793845 FILLED SELL \n",
"7 2054373594473218048 1778635807993 1778635808762 FILLED BUY \n",
"8 2054373724560035840 1778635839007 1778635839160 FILLED BUY \n",
"9 2054391807521476608 1778640150321 1778640150474 FILLED SELL \n",
"10 2054392042100424704 1778640206249 1778640206402 FILLED BUY \n",
"\n",
" filled_qty payed_fee price duration_sec_ast is_mkt_maker \\\n",
"0 12.5 0.125309 40.099000 0.152 False \n",
"1 0.3 0.003005 40.084000 0.153 False \n",
"2 0.3 0.003003 40.050000 0.152 False \n",
"3 0.1 0.001008 40.341000 0.152 False \n",
"4 12.5 0.126239 40.397000 0.153 False \n",
"5 0.1 0.001009 40.389000 0.153 False \n",
"6 12.3 0.124838 40.598000 0.153 False \n",
"7 12.3 0.000000 40.627000 0.769 True \n",
"8 750.0 0.012374 0.066033 0.153 False \n",
"9 720.0 0.012310 0.068383 0.153 False \n",
"10 700.0 0.011938 0.068218 0.153 False \n",
"\n",
" timestamp_ts \n",
"0 2026-05-13 00:03:57.456 \n",
"1 2026-05-13 00:28:33.566 \n",
"2 2026-05-13 00:30:43.215 \n",
"3 2026-05-13 01:03:47.978 \n",
"4 2026-05-13 01:12:39.248 \n",
"5 2026-05-13 01:12:41.388 \n",
"6 2026-05-13 01:29:53.845 \n",
"7 2026-05-13 01:30:08.762 \n",
"8 2026-05-13 01:30:39.160 \n",
"9 2026-05-13 02:42:30.474 \n",
"10 2026-05-13 02:43:26.402 "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_extend_trades"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ebf54b3",
"metadata": {},
"outputs": [
{
"ename": "IndexError",
"evalue": "single positional indexer is out-of-bounds",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mIndexError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[32m 9\u001b[39m return_row = row.merge(extend_row, left_index=\u001b[38;5;28;01mTrue\u001b[39;00m, right_index=\u001b[38;5;28;01mTrue\u001b[39;00m, suffixes=(\u001b[33m'_ast'\u001b[39m,\u001b[33m'_ext'\u001b[39m))\n\u001b[32m 10\u001b[39m \n\u001b[32m 11\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m return_row.iloc[\u001b[32m0\u001b[39m]\n\u001b[32m 12\u001b[39m \n\u001b[32m---> \u001b[39m\u001b[32m13\u001b[39m df_comb_trades = df_aster_trades[[\u001b[33m'order_id'\u001b[39m,\u001b[33m'timestamp_ts'\u001b[39m,\u001b[33m'status'\u001b[39m,\u001b[33m'side'\u001b[39m,\u001b[33m'filled_qty'\u001b[39m,\u001b[33m'payed_fee'\u001b[39m,\u001b[33m'price'\u001b[39m,\u001b[33m'is_mkt_maker'\u001b[39m]].apply(tie_trades_together_get_extend_from_aster, axis=\u001b[32m1\u001b[39m)\n\u001b[32m 14\u001b[39m \u001b[38;5;66;03m# df_comb_trades['buy_price'] = df_comb_trades['price_ast'].where(df_comb_trades['side_ast']=='BUY', df_comb_trades['price_ext'])\u001b[39;00m\n\u001b[32m 15\u001b[39m \u001b[38;5;66;03m# df_comb_trades['sell_price'] = df_comb_trades['price_ast'].where(df_comb_trades['side_ast']=='SELL', df_comb_trades['price_ext'])\u001b[39;00m\n\u001b[32m 16\u001b[39m \u001b[38;5;66;03m# df_comb_trades['buy_qty'] = df_comb_trades['filled_qty_ast'].where(df_comb_trades['side_ast']=='BUY', df_comb_trades['filled_qty_ext'])\u001b[39;00m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/frame.py:12423\u001b[39m, in \u001b[36mDataFrame.apply\u001b[39m\u001b[34m(self, func, axis, raw, result_type, args, by_row, engine, engine_kwargs, **kwargs)\u001b[39m\n\u001b[32m 12419\u001b[39m engine_kwargs=engine_kwargs,\n\u001b[32m 12420\u001b[39m args=args,\n\u001b[32m 12421\u001b[39m kwargs=kwargs,\n\u001b[32m 12422\u001b[39m )\n\u001b[32m> \u001b[39m\u001b[32m12423\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m op.apply().__finalize__(self, method=\u001b[33m\"apply\"\u001b[39m)\n\u001b[32m 12424\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m hasattr(engine, \u001b[33m\"__pandas_udf__\"\u001b[39m):\n\u001b[32m 12425\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m result_type \u001b[38;5;28;01mis\u001b[39;00m \u001b[38;5;28;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m 12426\u001b[39m raise NotImplementedError(\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/apply.py:1015\u001b[39m, in \u001b[36mFrameApply.apply\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 1012\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.raw:\n\u001b[32m 1013\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.apply_raw(engine=\u001b[38;5;28mself\u001b[39m.engine, engine_kwargs=\u001b[38;5;28mself\u001b[39m.engine_kwargs)\n\u001b[32m-> \u001b[39m\u001b[32m1015\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mapply_standard\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/apply.py:1167\u001b[39m, in \u001b[36mFrameApply.apply_standard\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 1165\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mapply_standard\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[32m 1166\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.engine == \u001b[33m\"\u001b[39m\u001b[33mpython\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m-> \u001b[39m\u001b[32m1167\u001b[39m results, res_index = \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mapply_series_generator\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 1168\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 1169\u001b[39m results, res_index = \u001b[38;5;28mself\u001b[39m.apply_series_numba()\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/apply.py:1183\u001b[39m, in \u001b[36mFrameApply.apply_series_generator\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 1180\u001b[39m results = {}\n\u001b[32m 1182\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m i, v \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(series_gen):\n\u001b[32m-> \u001b[39m\u001b[32m1183\u001b[39m results[i] = \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mfunc\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43mv\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 1184\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(results[i], ABCSeries):\n\u001b[32m 1185\u001b[39m \u001b[38;5;66;03m# If we have a view on v, we need to make a copy because\u001b[39;00m\n\u001b[32m 1186\u001b[39m \u001b[38;5;66;03m# series_generator will swap out the underlying data\u001b[39;00m\n\u001b[32m 1187\u001b[39m results[i] = results[i].copy(deep=\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 5\u001b[39m, in \u001b[36mtie_trades_together_get_extend_from_aster\u001b[39m\u001b[34m(row)\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m tie_trades_together_get_extend_from_aster(row):\n\u001b[32m 2\u001b[39m row = row.to_frame().T\n\u001b[32m 3\u001b[39m row.index=[\u001b[32m1\u001b[39m]\n\u001b[32m 4\u001b[39m \n\u001b[32m----> \u001b[39m\u001b[32m5\u001b[39m extend_row = df_extend_trades[[\u001b[33m'order_id'\u001b[39m,\u001b[33m'timestamp_ts'\u001b[39m,\u001b[33m'status'\u001b[39m,\u001b[33m'side'\u001b[39m,\u001b[33m'filled_qty'\u001b[39m,\u001b[33m'payed_fee'\u001b[39m,\u001b[33m'price'\u001b[39m,\u001b[33m'is_mkt_maker'\u001b[39m]].loc[df_extend_trades[\u001b[33m'timestamp_ts'\u001b[39m]>row[\u001b[33m'timestamp_ts'\u001b[39m].iloc[\u001b[32m0\u001b[39m],:].iloc[\u001b[32m0\u001b[39m]\n\u001b[32m 6\u001b[39m extend_row = extend_row.to_frame().T\n\u001b[32m 7\u001b[39m extend_row.index=[\u001b[32m1\u001b[39m]\n\u001b[32m 8\u001b[39m \n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/indexing.py:1207\u001b[39m, in \u001b[36m_LocationIndexer.__getitem__\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 1205\u001b[39m maybe_callable = com.apply_if_callable(key, \u001b[38;5;28mself\u001b[39m.obj)\n\u001b[32m 1206\u001b[39m maybe_callable = \u001b[38;5;28mself\u001b[39m._raise_callable_usage(key, maybe_callable)\n\u001b[32m-> \u001b[39m\u001b[32m1207\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43m_getitem_axis\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43mmaybe_callable\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43maxis\u001b[39;49m\u001b[30;43m=\u001b[39;49m\u001b[30;43maxis\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/indexing.py:1773\u001b[39m, in \u001b[36m_iLocIndexer._getitem_axis\u001b[39m\u001b[34m(self, key, axis)\u001b[39m\n\u001b[32m 1770\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[33m\"\u001b[39m\u001b[33mCannot index by location index with a non-integer key\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 1772\u001b[39m \u001b[38;5;66;03m# validate the location\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m1773\u001b[39m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43m_validate_integer\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43mkey\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43maxis\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 1775\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.obj._ixs(key, axis=axis)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda3/envs/py_313/lib/python3.13/site-packages/pandas/core/indexing.py:1706\u001b[39m, in \u001b[36m_iLocIndexer._validate_integer\u001b[39m\u001b[34m(self, key, axis)\u001b[39m\n\u001b[32m 1704\u001b[39m len_axis = \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m.obj._get_axis(axis))\n\u001b[32m 1705\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m key >= len_axis \u001b[38;5;129;01mor\u001b[39;00m key < -len_axis:\n\u001b[32m-> \u001b[39m\u001b[32m1706\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mIndexError\u001b[39;00m(\u001b[33m\"\u001b[39m\u001b[33msingle positional indexer is out-of-bounds\u001b[39m\u001b[33m\"\u001b[39m)\n",
"\u001b[31mIndexError\u001b[39m: single positional indexer is out-of-bounds"
]
}
],
"source": [
"def tie_trades_together_get_extend_from_aster(row):\n",
" row = row.to_frame().T\n",
" row.index=[1]\n",
"\n",
" extend_row = df_extend_trades[['order_id','timestamp_ts','status','side','filled_qty','payed_fee','price','is_mkt_maker']].loc[df_extend_trades['timestamp_ts']>row['timestamp_ts'].iloc[0],:].iloc[0]\n",
" extend_row = extend_row.to_frame().T\n",
" extend_row.index=[1]\n",
"\n",
" return_row = row.merge(extend_row, left_index=True, right_index=True, suffixes=('_ast','_ext'))\n",
"\n",
" return return_row.iloc[0]\n",
"\n",
"df_comb_trades = df_aster_trades[['order_id','timestamp_ts','status','side','filled_qty','payed_fee','price','is_mkt_maker']].apply(tie_trades_together_get_extend_from_aster, axis=1)\n",
"# df_comb_trades['buy_price'] = df_comb_trades['price_ast'].where(df_comb_trades['side_ast']=='BUY', df_comb_trades['price_ext'])\n",
"# df_comb_trades['sell_price'] = df_comb_trades['price_ast'].where(df_comb_trades['side_ast']=='SELL', df_comb_trades['price_ext'])\n",
"# df_comb_trades['buy_qty'] = df_comb_trades['filled_qty_ast'].where(df_comb_trades['side_ast']=='BUY', df_comb_trades['filled_qty_ext'])\n",
"# df_comb_trades['sell_qty'] = df_comb_trades['filled_qty_ast'].where(df_comb_trades['side_ast']=='SELL', df_comb_trades['filled_qty_ext'])\n",
"# df_comb_trades['buy_side'] = df_comb_trades['order_id_ast'].where(df_comb_trades['side_ast']=='BUY', df_comb_trades['order_id_ext'])\n",
"# df_comb_trades['buy_side'] = df_comb_trades['order_id_ast'] == df_comb_trades['buy_side']\n",
"# df_comb_trades['buy_side'] = df_comb_trades['buy_side'].replace(True, 'ASTER').replace(False,'EXTEND')\n",
"\n",
"# df_comb_trades['per_trade_pnl'] = ( ( df_comb_trades['sell_price'] - df_comb_trades['buy_price'] ) * df_comb_trades['sell_qty'] ) - df_comb_trades['payed_fee_ast'] - df_comb_trades['payed_fee_ext']\n",
"# df_comb_trades['per_trade_pnl_pct'] = ( (df_comb_trades['sell_price']*df_comb_trades['sell_qty']) - (df_comb_trades['buy_price']*df_comb_trades['buy_qty']) ) / (df_comb_trades['buy_price']*df_comb_trades['buy_qty'])"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'df_comb_trades' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[14]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m df_comb_trades\n",
"\u001b[31mNameError\u001b[39m: name 'df_comb_trades' is not defined"
]
}
],
"source": [
"df_comb_trades"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d09782a8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"hovertemplate": "timestamp_ts_ext=%{x}
per_trade_pnl=%{y}",
"legendgroup": "",
"line": {
"color": "#636efa",
"dash": "solid"
},
"marker": {
"symbol": "circle"
},
"mode": "lines",
"name": "",
"orientation": "v",
"showlegend": false,
"type": "scatter",
"x": [
"2026-05-02T22:08:49.823000",
"2026-05-02T22:33:52.752000",
"2026-05-02T22:42:05.138000"
],
"xaxis": "x",
"y": {
"bdata": "fraYnxua2r+APKTfvg6cP/A1uycPC7U/",
"dtype": "f8"
},
"yaxis": "y"
}
],
"layout": {
"legend": {
"tracegroupgap": 0
},
"margin": {
"t": 60
},
"template": {
"data": {
"bar": [
{
"error_x": {
"color": "#f2f5fa"
},
"error_y": {
"color": "#f2f5fa"
},
"marker": {
"line": {
"color": "rgb(17,17,17)",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "bar"
}
],
"barpolar": [
{
"marker": {
"line": {
"color": "rgb(17,17,17)",
"width": 0.5
},
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "barpolar"
}
],
"carpet": [
{
"aaxis": {
"endlinecolor": "#A2B1C6",
"gridcolor": "#506784",
"linecolor": "#506784",
"minorgridcolor": "#506784",
"startlinecolor": "#A2B1C6"
},
"baxis": {
"endlinecolor": "#A2B1C6",
"gridcolor": "#506784",
"linecolor": "#506784",
"minorgridcolor": "#506784",
"startlinecolor": "#A2B1C6"
},
"type": "carpet"
}
],
"choropleth": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "choropleth"
}
],
"contour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "contour"
}
],
"contourcarpet": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "contourcarpet"
}
],
"heatmap": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "heatmap"
}
],
"histogram": [
{
"marker": {
"pattern": {
"fillmode": "overlay",
"size": 10,
"solidity": 0.2
}
},
"type": "histogram"
}
],
"histogram2d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2d"
}
],
"histogram2dcontour": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "histogram2dcontour"
}
],
"mesh3d": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"type": "mesh3d"
}
],
"parcoords": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "parcoords"
}
],
"pie": [
{
"automargin": true,
"type": "pie"
}
],
"scatter": [
{
"marker": {
"line": {
"color": "#283442"
}
},
"type": "scatter"
}
],
"scatter3d": [
{
"line": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatter3d"
}
],
"scattercarpet": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattercarpet"
}
],
"scattergeo": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattergeo"
}
],
"scattergl": [
{
"marker": {
"line": {
"color": "#283442"
}
},
"type": "scattergl"
}
],
"scattermap": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermap"
}
],
"scattermapbox": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scattermapbox"
}
],
"scatterpolar": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolar"
}
],
"scatterpolargl": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterpolargl"
}
],
"scatterternary": [
{
"marker": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"type": "scatterternary"
}
],
"surface": [
{
"colorbar": {
"outlinewidth": 0,
"ticks": ""
},
"colorscale": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"type": "surface"
}
],
"table": [
{
"cells": {
"fill": {
"color": "#506784"
},
"line": {
"color": "rgb(17,17,17)"
}
},
"header": {
"fill": {
"color": "#2a3f5f"
},
"line": {
"color": "rgb(17,17,17)"
}
},
"type": "table"
}
]
},
"layout": {
"annotationdefaults": {
"arrowcolor": "#f2f5fa",
"arrowhead": 0,
"arrowwidth": 1
},
"autotypenumbers": "strict",
"coloraxis": {
"colorbar": {
"outlinewidth": 0,
"ticks": ""
}
},
"colorscale": {
"diverging": [
[
0,
"#8e0152"
],
[
0.1,
"#c51b7d"
],
[
0.2,
"#de77ae"
],
[
0.3,
"#f1b6da"
],
[
0.4,
"#fde0ef"
],
[
0.5,
"#f7f7f7"
],
[
0.6,
"#e6f5d0"
],
[
0.7,
"#b8e186"
],
[
0.8,
"#7fbc41"
],
[
0.9,
"#4d9221"
],
[
1,
"#276419"
]
],
"sequential": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
],
"sequentialminus": [
[
0,
"#0d0887"
],
[
0.1111111111111111,
"#46039f"
],
[
0.2222222222222222,
"#7201a8"
],
[
0.3333333333333333,
"#9c179e"
],
[
0.4444444444444444,
"#bd3786"
],
[
0.5555555555555556,
"#d8576b"
],
[
0.6666666666666666,
"#ed7953"
],
[
0.7777777777777778,
"#fb9f3a"
],
[
0.8888888888888888,
"#fdca26"
],
[
1,
"#f0f921"
]
]
},
"colorway": [
"#636efa",
"#EF553B",
"#00cc96",
"#ab63fa",
"#FFA15A",
"#19d3f3",
"#FF6692",
"#B6E880",
"#FF97FF",
"#FECB52"
],
"font": {
"color": "#f2f5fa"
},
"geo": {
"bgcolor": "rgb(17,17,17)",
"lakecolor": "rgb(17,17,17)",
"landcolor": "rgb(17,17,17)",
"showlakes": true,
"showland": true,
"subunitcolor": "#506784"
},
"hoverlabel": {
"align": "left"
},
"hovermode": "closest",
"mapbox": {
"style": "dark"
},
"paper_bgcolor": "rgb(17,17,17)",
"plot_bgcolor": "rgb(17,17,17)",
"polar": {
"angularaxis": {
"gridcolor": "#506784",
"linecolor": "#506784",
"ticks": ""
},
"bgcolor": "rgb(17,17,17)",
"radialaxis": {
"gridcolor": "#506784",
"linecolor": "#506784",
"ticks": ""
}
},
"scene": {
"xaxis": {
"backgroundcolor": "rgb(17,17,17)",
"gridcolor": "#506784",
"gridwidth": 2,
"linecolor": "#506784",
"showbackground": true,
"ticks": "",
"zerolinecolor": "#C8D4E3"
},
"yaxis": {
"backgroundcolor": "rgb(17,17,17)",
"gridcolor": "#506784",
"gridwidth": 2,
"linecolor": "#506784",
"showbackground": true,
"ticks": "",
"zerolinecolor": "#C8D4E3"
},
"zaxis": {
"backgroundcolor": "rgb(17,17,17)",
"gridcolor": "#506784",
"gridwidth": 2,
"linecolor": "#506784",
"showbackground": true,
"ticks": "",
"zerolinecolor": "#C8D4E3"
}
},
"shapedefaults": {
"line": {
"color": "#f2f5fa"
}
},
"sliderdefaults": {
"bgcolor": "#C8D4E3",
"bordercolor": "rgb(17,17,17)",
"borderwidth": 1,
"tickwidth": 0
},
"ternary": {
"aaxis": {
"gridcolor": "#506784",
"linecolor": "#506784",
"ticks": ""
},
"baxis": {
"gridcolor": "#506784",
"linecolor": "#506784",
"ticks": ""
},
"bgcolor": "rgb(17,17,17)",
"caxis": {
"gridcolor": "#506784",
"linecolor": "#506784",
"ticks": ""
}
},
"title": {
"x": 0.05
},
"updatemenudefaults": {
"bgcolor": "#506784",
"borderwidth": 0
},
"xaxis": {
"automargin": true,
"gridcolor": "#283442",
"linecolor": "#506784",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "#283442",
"zerolinewidth": 2
},
"yaxis": {
"automargin": true,
"gridcolor": "#283442",
"linecolor": "#506784",
"ticks": "",
"title": {
"standoff": 15
},
"zerolinecolor": "#283442",
"zerolinewidth": 2
}
}
},
"xaxis": {
"anchor": "y",
"domain": [
0,
1
],
"title": {
"text": "timestamp_ts_ext"
}
},
"yaxis": {
"anchor": "x",
"domain": [
0,
1
],
"title": {
"text": "per_trade_pnl"
}
}
}
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"px.line(df_comb_trades, x='timestamp_ts_ext', y='per_trade_pnl', template='plotly_dark')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 27,
"id": "1827a1ca",
"metadata": {},
"outputs": [],
"source": [
"j = \"[{'timestamp_arrival': 1777762804677, 'timestamp_msg': 1777762804673, 'timestamp_transaction': 1777762804650, 'event_reason_type': 'ORDER', 'symbol': 'LITUSDT', 'position_amount': 0.0, 'entry_price': 0.0, 'accumulated_realized_pre_fees': 2.0749, 'unrealized_pnl': 0.0, 'margin_type': 'cross', 'isolated_wallet': 0.0, 'position_side': 'BOTH'}]\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "77f27d2f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6bd8f38d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1a0e1a1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf5e2eaa",
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}