From 73c4eb1bf89c14ffacebcec9e25121804a359b5e Mon Sep 17 00:00:00 2001 From: stevekeyharvey Date: Sat, 25 Apr 2026 23:47:07 +0000 Subject: [PATCH] saving for japan --- algo.ipynb | 153 +++++-------- algo_config.json | 3 +- extended.ipynb | 239 +++++++++++++++----- main.py | 2 +- modules/__pycache__/structs.cpython-313.pyc | Bin 9372 -> 9428 bytes modules/structs.py | 2 + 6 files changed, 240 insertions(+), 159 deletions(-) diff --git a/algo.ipynb b/algo.ipynb index 118f65b..023d012 100644 --- a/algo.ipynb +++ b/algo.ipynb @@ -2,152 +2,101 @@ "cells": [ { "cell_type": "code", - "execution_count": 28, - "id": "ac27075d", - "metadata": {}, - "outputs": [], - "source": [ - "import json\n", - "from dataclasses import dataclass, asdict\n", - "\n", - "@dataclass(kw_only=True)\n", - "class Algo_Config:\n", - " Allow_Ordering_Aster: bool\n", - " Allow_Ordering_Extend: bool\n", - " Loop_Sleep_Sec: int\n", - " Min_Time_To_Funding_Minutes: int\n", - " Price_Worsener_Aster: float\n", - " Price_Worsener_Extend: float\n", - " Target_Open_Cash_Position: int" - ] - }, - { - "cell_type": "code", - "execution_count": 29, + "execution_count": 1, "id": "d1eed397", "metadata": {}, "outputs": [], "source": [ + "import modules.structs as structs\n", + "import json\n", + "from dataclasses import dataclass, asdict\n", + "import valkey\n", + "\n", "with open('algo_config.json', 'r', encoding='utf-8') as file:\n", - " ALGO_CONFIG = json.load(file, object_hook=lambda d: Algo_Config(**d))" + " ALGO_CONFIG = json.load(file, object_hook=lambda d: structs.Algo_Config(**d))" ] }, { "cell_type": "code", - "execution_count": 30, - "id": "286bf2d2", + "execution_count": 2, + "id": "c6151613", + "metadata": {}, + "outputs": [], + "source": [ + "VAL_KEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d83c61e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Algo_Config(Allow_Ordering_Aster=True, Allow_Ordering_Extend=True, Loop_Sleep_Sec=1, Min_Time_To_Funding_Minutes=7, Price_Worsener_Aster=0.0, Price_Worsener_Extend=0.0, Target_Open_Cash_Position=10)" + "1" ] }, - "execution_count": 30, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ALGO_CONFIG" + "config_update = {'Min_Time_To_Funding_Minutes': 7}\n", + "VAL_KEY.publish('fr_orchestrator_input', json.dumps(config_update))" ] }, { "cell_type": "code", - "execution_count": 35, - "id": "0cbed6d4", - "metadata": {}, - "outputs": [], - "source": [ - "d = asdict(ALGO_CONFIG)" - ] - }, - { - "cell_type": "code", - "execution_count": 41, - "id": "daa47980", - "metadata": {}, - "outputs": [], - "source": [ - "d_update = {'Allow_Ordering_Aster': False}" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "id": "aba7797b", + "execution_count": 11, + "id": "45fae761", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'Allow_Ordering_Aster': True,\n", + "Algo_Config(Config_Updated_Timestamp=1777151524162, Allow_Ordering_Aster=True, Allow_Ordering_Extend=True, Loop_Sleep_Sec=1, Max_Target_Notional=0.0, Min_Time_To_Funding_Minutes=60, Price_Worsener_Aster=0.0, Price_Worsener_Extend=0.0, Target_Open_Cash_Position=10)" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "json.loads(VAL_KEY.get('fr_orchestrator_output'), object_hook=lambda d: structs.Algo_Config(**d))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Config_Updated_Timestamp': 1777098091913,\n", + " 'Allow_Ordering_Aster': True,\n", " 'Allow_Ordering_Extend': True,\n", " 'Loop_Sleep_Sec': 1,\n", - " 'Min_Time_To_Funding_Minutes': 7,\n", + " 'Max_Target_Notional': 0.0,\n", + " 'Min_Time_To_Funding_Minutes': 60,\n", " 'Price_Worsener_Aster': 0.0,\n", " 'Price_Worsener_Extend': 0.0,\n", " 'Target_Open_Cash_Position': 10}" ] }, - "execution_count": 42, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "d" + "asdict(ALGO_CONFIG)" ] }, - { - "cell_type": "code", - "execution_count": 43, - "id": "3250cb84", - "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "expected ':' (3324129842.py, line 1)", - "output_type": "error", - "traceback": [ - " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[43]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mif d.get(d_update)\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m expected ':'\n" - ] - } - ], - "source": [ - "if d.get(d_update)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e283b819", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "dict_keys(['Allow_Ordering_Aster'])" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list(d_update.keys())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6f067c02", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": null, diff --git a/algo_config.json b/algo_config.json index e0d945f..acee321 100644 --- a/algo_config.json +++ b/algo_config.json @@ -7,5 +7,6 @@ "Min_Time_To_Funding_Minutes": 60, "Price_Worsener_Aster": 0.0, "Price_Worsener_Extend": 0.0, - "Target_Open_Cash_Position": 10 + "Target_Open_Cash_Position": 10, + "Print_Summary_Each_Loop" : false } \ No newline at end of file diff --git a/extended.ipynb b/extended.ipynb index ad23069..f6e77b6 100644 --- a/extended.ipynb +++ b/extended.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "6c70a8c3", "metadata": {}, "outputs": [], @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "ff971ca9", "metadata": {}, "outputs": [], @@ -49,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "fc2c6d2b", "metadata": {}, "outputs": [], @@ -97,78 +97,207 @@ }, { "cell_type": "code", - "execution_count": 59, - "id": "1e0cc529", + "execution_count": null, + "id": "03913674", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "8dd8aa73", "metadata": {}, "outputs": [], "source": [ - "d = dict(placed_order)\n", - "d = d['data']" + "d = await trading_client.account.get_positions_history()" ] }, { "cell_type": "code", - "execution_count": 61, - "id": "c6e2570b", + "execution_count": 12, + "id": "5f74f7cc", "metadata": {}, "outputs": [ { "data": { + "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", + "
012345678910111213
0(id, 2047947640758337536)(account_id, 270571)(market, ETH-USD)(side, SHORT)(size, 0.2160000000000000)(max_position_size, 0.2160000000000000)(leverage, 50.0000000000000000)(open_price, 2315.5000000000000000)(exit_price, 2308.6000000000000000)(realised_pnl, 1.4249250000000000)(realised_pnl_breakdown, trade_pnl=Decimal('1....(created_time, 1777103741241)(exit_type, TRADE)(closed_time, 1777133049026)
1(id, 2047512381621272576)(account_id, 270571)(market, ETH-USD)(side, LONG)(size, 0.2150000000000000)(max_position_size, 0.2150000000000000)(leverage, 50.0000000000000000)(open_price, 2316.6000000000000000)(exit_price, 2315.5000000000000000)(realised_pnl, 0.0720660000000000)(realised_pnl_breakdown, trade_pnl=Decimal('-0...(created_time, 1776999967376)(exit_type, TRADE)(closed_time, 1777103741241)
2(id, 2047419314696355840)(account_id, 270571)(market, ETH-USD)(side, LONG)(size, 0.2150000000000000)(max_position_size, 0.2150000000000000)(leverage, 50.0000000000000000)(open_price, 2321.7000000000000000)(exit_price, 2327.3000000000000000)(realised_pnl, 1.3196460000000000)(realised_pnl_breakdown, trade_pnl=Decimal('1....(created_time, 1776977778492)(exit_type, TRADE)(closed_time, 1776996621824)
\n", + "
" + ], "text/plain": [ - "{'id': 2047411567531950080,\n", - " 'external_id': '970778360519119766032805910949664642915982435081116578514332451865869879614'}" + " 0 1 2 \\\n", + "0 (id, 2047947640758337536) (account_id, 270571) (market, ETH-USD) \n", + "1 (id, 2047512381621272576) (account_id, 270571) (market, ETH-USD) \n", + "2 (id, 2047419314696355840) (account_id, 270571) (market, ETH-USD) \n", + "\n", + " 3 4 \\\n", + "0 (side, SHORT) (size, 0.2160000000000000) \n", + "1 (side, LONG) (size, 0.2150000000000000) \n", + "2 (side, LONG) (size, 0.2150000000000000) \n", + "\n", + " 5 6 \\\n", + "0 (max_position_size, 0.2160000000000000) (leverage, 50.0000000000000000) \n", + "1 (max_position_size, 0.2150000000000000) (leverage, 50.0000000000000000) \n", + "2 (max_position_size, 0.2150000000000000) (leverage, 50.0000000000000000) \n", + "\n", + " 7 8 \\\n", + "0 (open_price, 2315.5000000000000000) (exit_price, 2308.6000000000000000) \n", + "1 (open_price, 2316.6000000000000000) (exit_price, 2315.5000000000000000) \n", + "2 (open_price, 2321.7000000000000000) (exit_price, 2327.3000000000000000) \n", + "\n", + " 9 \\\n", + "0 (realised_pnl, 1.4249250000000000) \n", + "1 (realised_pnl, 0.0720660000000000) \n", + "2 (realised_pnl, 1.3196460000000000) \n", + "\n", + " 10 \\\n", + "0 (realised_pnl_breakdown, trade_pnl=Decimal('1.... \n", + "1 (realised_pnl_breakdown, trade_pnl=Decimal('-0... \n", + "2 (realised_pnl_breakdown, trade_pnl=Decimal('1.... \n", + "\n", + " 11 12 \\\n", + "0 (created_time, 1777103741241) (exit_type, TRADE) \n", + "1 (created_time, 1776999967376) (exit_type, TRADE) \n", + "2 (created_time, 1776977778492) (exit_type, TRADE) \n", + "\n", + " 13 \n", + "0 (closed_time, 1777133049026) \n", + "1 (closed_time, 1777103741241) \n", + "2 (closed_time, 1776996621824) " ] }, - "execution_count": 61, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dict(d)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3e4cedd1", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'OK'" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dict(placed_order).get('status' \\\n", - "'')" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Timestamp('2026-04-23 23:55:13.704000')" - ] - }, - "execution_count": 4, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", - "pd.to_datetime(1776988513704, unit='ms')" + "pd.DataFrame(list(dict(d)['data']))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e119aaac", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Timestamp('2026-04-25 16:04:09.026000')" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pandas as pd\n", + "pd.to_datetime(1777133049026, unit='ms')" ] }, { diff --git a/main.py b/main.py index 9b55f9f..e00d1d7 100644 --- a/main.py +++ b/main.py @@ -442,7 +442,7 @@ async def run_algo(): --- EXTEND OPEN ORDERS --- {EXTEND_OPEN_ORDERS} ''') - if ALGO_CONFIG.print_summary_each_loop: + if ALGO_CONFIG.Print_Summary_Each_Loop: print_summary() # print_summary() diff --git a/modules/__pycache__/structs.cpython-313.pyc b/modules/__pycache__/structs.cpython-313.pyc index 5b7fd84664a4549f185ca05bee8b3e1252374dae..248e47fa4cf57b3f6858a0b95cca163d00696360 100644 GIT binary patch delta 2759 zcmbuBZERCj7{`0p+tRIT_ttf5H@bB!lZ(QF;9vovOa_i^Ww1>}7O&lQfeT$b&b=cp zBy^_ATr`1r)QCa|;!7HhL5W}VgYwzLmw>ojK8PVC`oS>67h_aB|L2atu$v|>>942f zJm)#j^FQY~XD2%@b@*@kd_@lN_vMaX^hm`={;vz9Bm4`0gkKF-@DgXNe84^6>Mg!c znDqKs;ab6)_JxouTYVX*{NP>;4?TMj%YF9cvnsdaJBEC+3BEl-fEUQvg z4KrctLu$e_nLapXYKE$^0RKSVAw9zXlGj#VlpC%#D&NR8ulHS+6&4ZGn1@FTLwuJj zCI$H$uJ!SN=!`3ctP+DkpbDr4mH;(C7-$3*1DIsHt3xY#8$sUaj=E``D6KQ>J|xxh zEABs9mkJxpxmPopf|k7BNT)1UGMyMU*!`HlOh75HWJ62tu_R^`h~M?~td5s@qS6xn zpeLRo6JNeiE%%{B@_;sOxgVo%3fOWQCL_Phg%xO-RcPf)q6q^)t@s$Qopf9+Eak*&b3RnwzkXcS*E5(-~2?*_|n{V`n zrPcgN@49`k%N1B|rkP_b6<3P$Momgk)UvR*Qdo>*Fgw8n>nC zA!*k7ioG#0ZmZG8xBH&2fj(>tuvK8LEH`|?40>4yunp)0x&;1{GAs`B#{r6RUSaxS z0>s3}Xb?aSp^Gwq&Odvi`bnqH{U_a6p6%p`l2Z%T<~>J?sx;rR-VJv^7w;B56*QJnvSgVFw^I0|$E2LE+;L zsp8)UR@qySo~?`4hYw@MP65j|qNmg}8`hY5&>UZ&CTI$9n4hi;+71tkJ;l8q;6GKi zWS)i7HaK0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