saving for japan
This commit is contained in:
153
algo.ipynb
153
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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
239
extended.ipynb
239
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": [
|
||||
"<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>0</th>\n",
|
||||
" <th>1</th>\n",
|
||||
" <th>2</th>\n",
|
||||
" <th>3</th>\n",
|
||||
" <th>4</th>\n",
|
||||
" <th>5</th>\n",
|
||||
" <th>6</th>\n",
|
||||
" <th>7</th>\n",
|
||||
" <th>8</th>\n",
|
||||
" <th>9</th>\n",
|
||||
" <th>10</th>\n",
|
||||
" <th>11</th>\n",
|
||||
" <th>12</th>\n",
|
||||
" <th>13</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>(id, 2047947640758337536)</td>\n",
|
||||
" <td>(account_id, 270571)</td>\n",
|
||||
" <td>(market, ETH-USD)</td>\n",
|
||||
" <td>(side, SHORT)</td>\n",
|
||||
" <td>(size, 0.2160000000000000)</td>\n",
|
||||
" <td>(max_position_size, 0.2160000000000000)</td>\n",
|
||||
" <td>(leverage, 50.0000000000000000)</td>\n",
|
||||
" <td>(open_price, 2315.5000000000000000)</td>\n",
|
||||
" <td>(exit_price, 2308.6000000000000000)</td>\n",
|
||||
" <td>(realised_pnl, 1.4249250000000000)</td>\n",
|
||||
" <td>(realised_pnl_breakdown, trade_pnl=Decimal('1....</td>\n",
|
||||
" <td>(created_time, 1777103741241)</td>\n",
|
||||
" <td>(exit_type, TRADE)</td>\n",
|
||||
" <td>(closed_time, 1777133049026)</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>(id, 2047512381621272576)</td>\n",
|
||||
" <td>(account_id, 270571)</td>\n",
|
||||
" <td>(market, ETH-USD)</td>\n",
|
||||
" <td>(side, LONG)</td>\n",
|
||||
" <td>(size, 0.2150000000000000)</td>\n",
|
||||
" <td>(max_position_size, 0.2150000000000000)</td>\n",
|
||||
" <td>(leverage, 50.0000000000000000)</td>\n",
|
||||
" <td>(open_price, 2316.6000000000000000)</td>\n",
|
||||
" <td>(exit_price, 2315.5000000000000000)</td>\n",
|
||||
" <td>(realised_pnl, 0.0720660000000000)</td>\n",
|
||||
" <td>(realised_pnl_breakdown, trade_pnl=Decimal('-0...</td>\n",
|
||||
" <td>(created_time, 1776999967376)</td>\n",
|
||||
" <td>(exit_type, TRADE)</td>\n",
|
||||
" <td>(closed_time, 1777103741241)</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>(id, 2047419314696355840)</td>\n",
|
||||
" <td>(account_id, 270571)</td>\n",
|
||||
" <td>(market, ETH-USD)</td>\n",
|
||||
" <td>(side, LONG)</td>\n",
|
||||
" <td>(size, 0.2150000000000000)</td>\n",
|
||||
" <td>(max_position_size, 0.2150000000000000)</td>\n",
|
||||
" <td>(leverage, 50.0000000000000000)</td>\n",
|
||||
" <td>(open_price, 2321.7000000000000000)</td>\n",
|
||||
" <td>(exit_price, 2327.3000000000000000)</td>\n",
|
||||
" <td>(realised_pnl, 1.3196460000000000)</td>\n",
|
||||
" <td>(realised_pnl_breakdown, trade_pnl=Decimal('1....</td>\n",
|
||||
" <td>(created_time, 1776977778492)</td>\n",
|
||||
" <td>(exit_type, TRADE)</td>\n",
|
||||
" <td>(closed_time, 1776996621824)</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"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')"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
2
main.py
2
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()
|
||||
|
||||
|
||||
Binary file not shown.
@@ -16,6 +16,8 @@ class Algo_Config:
|
||||
Price_Worsener_Aster: float
|
||||
Price_Worsener_Extend: float
|
||||
Target_Open_Cash_Position: int
|
||||
|
||||
Print_Summary_Each_Loop: bool = False
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Flags:
|
||||
|
||||
Reference in New Issue
Block a user