Files
Funding_Rate/pnl.ipynb
2026-05-04 18:04:45 +00:00

1653 lines
43 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"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": 110,
"id": "527235c9",
"metadata": {},
"outputs": [],
"source": [
"start_ts = 1777498660*1000"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "d3206fe9",
"metadata": {},
"outputs": [],
"source": [
"start_ts = (round(datetime.now().timestamp()*1000)-(60*60*24*1000))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "9847869c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2026-05-01 22:56:30.744000')"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime(start_ts, unit='ms')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"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": 22,
"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": 23,
"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": 24,
"id": "0ebf54b3",
"metadata": {},
"outputs": [],
"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": 25,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "order_id_ast",
"rawType": "int64",
"type": "integer"
},
{
"name": "timestamp_ts_ast",
"rawType": "datetime64[ms]",
"type": "datetime"
},
{
"name": "status_ast",
"rawType": "str",
"type": "string"
},
{
"name": "side_ast",
"rawType": "str",
"type": "string"
},
{
"name": "filled_qty_ast",
"rawType": "float64",
"type": "float"
},
{
"name": "payed_fee_ast",
"rawType": "float64",
"type": "float"
},
{
"name": "price_ast",
"rawType": "float64",
"type": "float"
},
{
"name": "is_mkt_maker_ast",
"rawType": "bool",
"type": "boolean"
},
{
"name": "order_id_ext",
"rawType": "str",
"type": "string"
},
{
"name": "timestamp_ts_ext",
"rawType": "datetime64[ms]",
"type": "datetime"
},
{
"name": "status_ext",
"rawType": "str",
"type": "string"
},
{
"name": "side_ext",
"rawType": "str",
"type": "string"
},
{
"name": "filled_qty_ext",
"rawType": "float64",
"type": "float"
},
{
"name": "payed_fee_ext",
"rawType": "float64",
"type": "float"
},
{
"name": "price_ext",
"rawType": "float64",
"type": "float"
},
{
"name": "is_mkt_maker_ext",
"rawType": "bool",
"type": "boolean"
},
{
"name": "buy_price",
"rawType": "float64",
"type": "float"
},
{
"name": "sell_price",
"rawType": "float64",
"type": "float"
},
{
"name": "buy_qty",
"rawType": "float64",
"type": "float"
},
{
"name": "sell_qty",
"rawType": "float64",
"type": "float"
},
{
"name": "buy_side",
"rawType": "object",
"type": "string"
},
{
"name": "per_trade_pnl",
"rawType": "float64",
"type": "float"
},
{
"name": "per_trade_pnl_pct",
"rawType": "float64",
"type": "float"
}
],
"ref": "4fed1e21-7dd2-454b-b923-48d479d7aa72",
"rows": [
[
"0",
"328652716",
"2026-05-02 01:00:01.450000",
"FILLED",
"BUY",
"551.0",
"0.0",
"0.9059",
"True",
"2050627894673694720",
"2026-05-02 17:26:03.721000",
"FILLED",
"SELL",
"273.0",
"0.06208",
"0.8957",
"False",
"0.9059",
"0.8957",
"551.0",
"273.0",
"ASTER",
"-2.8466799999999965",
"-0.5101158787853532"
],
[
"1",
"329066650",
"2026-05-02 17:25:57.700000",
"FILLED",
"SELL",
"277.0",
"0.1007726",
"0.9095",
"False",
"2050627894673694720",
"2026-05-02 17:26:03.721000",
"FILLED",
"SELL",
"273.0",
"0.06208",
"0.8957",
"False",
"0.8957",
"0.9095",
"273.0",
"277.0",
"EXTEND",
"3.659747399999979",
"0.030284701714868006"
],
[
"2",
"329183551",
"2026-05-02 21:42:27.900000",
"FILLED",
"SELL",
"273.0",
"0.0",
"0.9126",
"True",
"2050694154048565248",
"2026-05-02 21:49:21.186000",
"FILLED",
"BUY",
"273.0",
"0.062319",
"0.9131",
"False",
"0.9131",
"0.9126",
"273.0",
"273.0",
"EXTEND",
"-0.1988190000000153",
"-0.0005475851494907951"
],
[
"3",
"329195229",
"2026-05-02 22:08:49.450000",
"FILLED",
"BUY",
"273.0",
"0.0",
"0.9136",
"True",
"2050699055663546368",
"2026-05-02 22:08:49.823000",
"FILLED",
"SELL",
"272.0",
"0.062056",
"0.9123",
"False",
"0.9136",
"0.9123",
"273.0",
"272.0",
"ASTER",
"-0.41565599999999125",
"-0.005080733627143444"
],
[
"4",
"329206619",
"2026-05-02 22:33:28.550000",
"FILLED",
"SELL",
"274.0",
"0.0",
"0.9106",
"True",
"2050705268467499008",
"2026-05-02 22:33:52.752000",
"FILLED",
"BUY",
"274.0",
"0.0",
"0.9105",
"True",
"0.9105",
"0.9106",
"274.0",
"274.0",
"EXTEND",
"0.027399999999996982",
"0.00010982976386600805"
],
[
"5",
"329210143",
"2026-05-02 22:41:58.300000",
"FILLED",
"SELL",
"274.0",
"0.0",
"0.912",
"True",
"2050707405608058880",
"2026-05-02 22:42:05.138000",
"FILLED",
"BUY",
"274.0",
"0.0",
"0.9117",
"True",
"0.9117",
"0.912",
"274.0",
"274.0",
"EXTEND",
"0.08220000000002137",
"0.0003290556103982722"
]
],
"shape": {
"columns": 23,
"rows": 6
}
},
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>order_id_ast</th>\n",
" <th>timestamp_ts_ast</th>\n",
" <th>status_ast</th>\n",
" <th>side_ast</th>\n",
" <th>filled_qty_ast</th>\n",
" <th>payed_fee_ast</th>\n",
" <th>price_ast</th>\n",
" <th>is_mkt_maker_ast</th>\n",
" <th>order_id_ext</th>\n",
" <th>timestamp_ts_ext</th>\n",
" <th>...</th>\n",
" <th>payed_fee_ext</th>\n",
" <th>price_ext</th>\n",
" <th>is_mkt_maker_ext</th>\n",
" <th>buy_price</th>\n",
" <th>sell_price</th>\n",
" <th>buy_qty</th>\n",
" <th>sell_qty</th>\n",
" <th>buy_side</th>\n",
" <th>per_trade_pnl</th>\n",
" <th>per_trade_pnl_pct</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>328652716</td>\n",
" <td>2026-05-02 01:00:01.450</td>\n",
" <td>FILLED</td>\n",
" <td>BUY</td>\n",
" <td>551.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.9059</td>\n",
" <td>True</td>\n",
" <td>2050627894673694720</td>\n",
" <td>2026-05-02 17:26:03.721</td>\n",
" <td>...</td>\n",
" <td>0.062080</td>\n",
" <td>0.8957</td>\n",
" <td>False</td>\n",
" <td>0.9059</td>\n",
" <td>0.8957</td>\n",
" <td>551.0</td>\n",
" <td>273.0</td>\n",
" <td>ASTER</td>\n",
" <td>-2.846680</td>\n",
" <td>-0.510116</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>329066650</td>\n",
" <td>2026-05-02 17:25:57.700</td>\n",
" <td>FILLED</td>\n",
" <td>SELL</td>\n",
" <td>277.0</td>\n",
" <td>0.100773</td>\n",
" <td>0.9095</td>\n",
" <td>False</td>\n",
" <td>2050627894673694720</td>\n",
" <td>2026-05-02 17:26:03.721</td>\n",
" <td>...</td>\n",
" <td>0.062080</td>\n",
" <td>0.8957</td>\n",
" <td>False</td>\n",
" <td>0.8957</td>\n",
" <td>0.9095</td>\n",
" <td>273.0</td>\n",
" <td>277.0</td>\n",
" <td>EXTEND</td>\n",
" <td>3.659747</td>\n",
" <td>0.030285</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>329183551</td>\n",
" <td>2026-05-02 21:42:27.900</td>\n",
" <td>FILLED</td>\n",
" <td>SELL</td>\n",
" <td>273.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.9126</td>\n",
" <td>True</td>\n",
" <td>2050694154048565248</td>\n",
" <td>2026-05-02 21:49:21.186</td>\n",
" <td>...</td>\n",
" <td>0.062319</td>\n",
" <td>0.9131</td>\n",
" <td>False</td>\n",
" <td>0.9131</td>\n",
" <td>0.9126</td>\n",
" <td>273.0</td>\n",
" <td>273.0</td>\n",
" <td>EXTEND</td>\n",
" <td>-0.198819</td>\n",
" <td>-0.000548</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>329195229</td>\n",
" <td>2026-05-02 22:08:49.450</td>\n",
" <td>FILLED</td>\n",
" <td>BUY</td>\n",
" <td>273.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.9136</td>\n",
" <td>True</td>\n",
" <td>2050699055663546368</td>\n",
" <td>2026-05-02 22:08:49.823</td>\n",
" <td>...</td>\n",
" <td>0.062056</td>\n",
" <td>0.9123</td>\n",
" <td>False</td>\n",
" <td>0.9136</td>\n",
" <td>0.9123</td>\n",
" <td>273.0</td>\n",
" <td>272.0</td>\n",
" <td>ASTER</td>\n",
" <td>-0.415656</td>\n",
" <td>-0.005081</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>329206619</td>\n",
" <td>2026-05-02 22:33:28.550</td>\n",
" <td>FILLED</td>\n",
" <td>SELL</td>\n",
" <td>274.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.9106</td>\n",
" <td>True</td>\n",
" <td>2050705268467499008</td>\n",
" <td>2026-05-02 22:33:52.752</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>0.9105</td>\n",
" <td>True</td>\n",
" <td>0.9105</td>\n",
" <td>0.9106</td>\n",
" <td>274.0</td>\n",
" <td>274.0</td>\n",
" <td>EXTEND</td>\n",
" <td>0.027400</td>\n",
" <td>0.000110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>329210143</td>\n",
" <td>2026-05-02 22:41:58.300</td>\n",
" <td>FILLED</td>\n",
" <td>SELL</td>\n",
" <td>274.0</td>\n",
" <td>0.000000</td>\n",
" <td>0.9120</td>\n",
" <td>True</td>\n",
" <td>2050707405608058880</td>\n",
" <td>2026-05-02 22:42:05.138</td>\n",
" <td>...</td>\n",
" <td>0.000000</td>\n",
" <td>0.9117</td>\n",
" <td>True</td>\n",
" <td>0.9117</td>\n",
" <td>0.9120</td>\n",
" <td>274.0</td>\n",
" <td>274.0</td>\n",
" <td>EXTEND</td>\n",
" <td>0.082200</td>\n",
" <td>0.000329</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>6 rows × 23 columns</p>\n",
"</div>"
],
"text/plain": [
" order_id_ast timestamp_ts_ast status_ast side_ast filled_qty_ast \\\n",
"0 328652716 2026-05-02 01:00:01.450 FILLED BUY 551.0 \n",
"1 329066650 2026-05-02 17:25:57.700 FILLED SELL 277.0 \n",
"2 329183551 2026-05-02 21:42:27.900 FILLED SELL 273.0 \n",
"3 329195229 2026-05-02 22:08:49.450 FILLED BUY 273.0 \n",
"4 329206619 2026-05-02 22:33:28.550 FILLED SELL 274.0 \n",
"5 329210143 2026-05-02 22:41:58.300 FILLED SELL 274.0 \n",
"\n",
" payed_fee_ast price_ast is_mkt_maker_ast order_id_ext \\\n",
"0 0.000000 0.9059 True 2050627894673694720 \n",
"1 0.100773 0.9095 False 2050627894673694720 \n",
"2 0.000000 0.9126 True 2050694154048565248 \n",
"3 0.000000 0.9136 True 2050699055663546368 \n",
"4 0.000000 0.9106 True 2050705268467499008 \n",
"5 0.000000 0.9120 True 2050707405608058880 \n",
"\n",
" timestamp_ts_ext ... payed_fee_ext price_ext is_mkt_maker_ext \\\n",
"0 2026-05-02 17:26:03.721 ... 0.062080 0.8957 False \n",
"1 2026-05-02 17:26:03.721 ... 0.062080 0.8957 False \n",
"2 2026-05-02 21:49:21.186 ... 0.062319 0.9131 False \n",
"3 2026-05-02 22:08:49.823 ... 0.062056 0.9123 False \n",
"4 2026-05-02 22:33:52.752 ... 0.000000 0.9105 True \n",
"5 2026-05-02 22:42:05.138 ... 0.000000 0.9117 True \n",
"\n",
" buy_price sell_price buy_qty sell_qty buy_side per_trade_pnl \\\n",
"0 0.9059 0.8957 551.0 273.0 ASTER -2.846680 \n",
"1 0.8957 0.9095 273.0 277.0 EXTEND 3.659747 \n",
"2 0.9131 0.9126 273.0 273.0 EXTEND -0.198819 \n",
"3 0.9136 0.9123 273.0 272.0 ASTER -0.415656 \n",
"4 0.9105 0.9106 274.0 274.0 EXTEND 0.027400 \n",
"5 0.9117 0.9120 274.0 274.0 EXTEND 0.082200 \n",
"\n",
" per_trade_pnl_pct \n",
"0 -0.510116 \n",
"1 0.030285 \n",
"2 -0.000548 \n",
"3 -0.005081 \n",
"4 0.000110 \n",
"5 0.000329 \n",
"\n",
"[6 rows x 23 columns]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_comb_trades"
]
},
{
"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}<br>per_trade_pnl=%{y}<extra></extra>",
"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
}