{ "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
order_id_asttimestamp_ts_aststatus_astside_astfilled_qty_astpayed_fee_astprice_astis_mkt_maker_astorder_id_exttimestamp_ts_ext...payed_fee_extprice_extis_mkt_maker_extbuy_pricesell_pricebuy_qtysell_qtybuy_sideper_trade_pnlper_trade_pnl_pct
03286527162026-05-02 01:00:01.450FILLEDBUY551.00.0000000.9059True20506278946736947202026-05-02 17:26:03.721...0.0620800.8957False0.90590.8957551.0273.0ASTER-2.846680-0.510116
13290666502026-05-02 17:25:57.700FILLEDSELL277.00.1007730.9095False20506278946736947202026-05-02 17:26:03.721...0.0620800.8957False0.89570.9095273.0277.0EXTEND3.6597470.030285
23291835512026-05-02 21:42:27.900FILLEDSELL273.00.0000000.9126True20506941540485652482026-05-02 21:49:21.186...0.0623190.9131False0.91310.9126273.0273.0EXTEND-0.198819-0.000548
33291952292026-05-02 22:08:49.450FILLEDBUY273.00.0000000.9136True20506990556635463682026-05-02 22:08:49.823...0.0620560.9123False0.91360.9123273.0272.0ASTER-0.415656-0.005081
43292066192026-05-02 22:33:28.550FILLEDSELL274.00.0000000.9106True20507052684674990082026-05-02 22:33:52.752...0.0000000.9105True0.91050.9106274.0274.0EXTEND0.0274000.000110
53292101432026-05-02 22:41:58.300FILLEDSELL274.00.0000000.9120True20507074056080588802026-05-02 22:42:05.138...0.0000000.9117True0.91170.9120274.0274.0EXTEND0.0822000.000329
\n", "

6 rows × 23 columns

\n", "
" ], "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}
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 }