Files
Funding_Rate/algo.ipynb

296 lines
6.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "d1eed397",
"metadata": {},
"outputs": [],
"source": [
"import modules.structs as structs\n",
"import json\n",
"from dataclasses import dataclass, asdict\n",
"import valkey\n",
"import modules.utils as utils\n",
"\n",
"with open('algo_config.json', 'r', encoding='utf-8') as file:\n",
" ALGO_CONFIG = json.load(file)\n",
" ALGO_CONFIG = structs.Algo_Config(**ALGO_CONFIG)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c6151613",
"metadata": {},
"outputs": [],
"source": [
"VAL_KEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "d83c61e5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"config_update = {\n",
" 'Config': {\n",
" # 'Loop_Sleep_Sec': 0.00,\n",
" # 'Min_Time_To_Funding_Minutes': 60,\n",
" # 'Min_Fund_Rate_Pct_To_Trade': 0.0002,\n",
" # 'Price_Worsener_Extend': 0.0,\n",
" # 'Price_Worsener_Aster': 0.0,\n",
" # 'Switch_To_Taker_Seconds': 1,\n",
" },\n",
" 'Logging': {\n",
" # 'Log_Summary_Each_Loop': False,\n",
" 'Print_Summary_Each_Loop': False,\n",
" },\n",
" # 'Overrides': {\n",
" # # 'Allow_Ordering_Aster': True,\n",
" # # 'Allow_Ordering_Extend': True,\n",
" # # 'Allow_Symbol_Change': False,\n",
" # # 'Flip_Side_For_Testing': False,\n",
" # # 'Flatten_Open_Positions': False,\n",
" # },\n",
"}\n",
"VAL_KEY.publish('fr_orchestrator_input', json.dumps(config_update))"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "f5260342",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"order = {'order_id':'test_1'}\n",
"VAL_KEY.publish('fr_engine_orders_input', json.dumps(order))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "940586bb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd600e0e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "db52edf9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2026-04-27 15:20:58.950000')"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"pd.to_datetime(1777303258950, unit='ms')"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "5f7535df",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'{\"ASTER\": {\"mult\": 150, \"lh_asset\": \"ETH\", \"rh_asset\": \"USD\", \"symbol_asset_separator\": \"\"}, \"EXTEND\": {\"mult\": 50, \"lh_asset\": \"ETH\", \"rh_asset\": \"USD\", \"symbol_asset_separator\": \"-\"}}'"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"VAL_KEY.get('fr_algo_working_symbol')"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "3acaa8cd",
"metadata": {},
"outputs": [],
"source": [
"ASTER = structs.Perpetual_Exchange(\n",
" mult = 150,\n",
" lh_asset = 'ETH',\n",
" rh_asset = 'USD',\n",
" symbol_asset_separator = '',\n",
")\n",
"EXTEND = structs.Perpetual_Exchange(\n",
" mult = 50,\n",
" lh_asset = 'ETH',\n",
" rh_asset = 'USD',\n",
" symbol_asset_separator = '-',\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "b417adad",
"metadata": {},
"outputs": [],
"source": [
"best_symbol_by_exchange: dict = json.loads(s=VAL_KEY.get(name='fr_algo_working_symbol')) # ty:ignore[invalid-argument-type]\n",
"best_symbol_by_exchange_aster = structs.Perpetual_Exchange(**asdict(ASTER))\n",
"best_symbol_by_exchange_extend = structs.Perpetual_Exchange(**asdict(EXTEND))"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "fa5a8e85",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Perpetual_Exchange(mult=50, lh_asset='ETH', rh_asset='USD', symbol_asset_separator='-')"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"best_symbol_by_exchange_extend"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "fb81441a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"VAL_KEY.set('fr_algo_working_symbol', json.dumps({'ASTER': asdict(best_symbol_by_exchange_aster), 'EXTEND': asdict(best_symbol_by_exchange_extend)}))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09571e38",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"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
}