3100 lines
81 KiB
Plaintext
3100 lines
81 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"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",
|
|
"import modules.utils as utils\n",
|
|
"from decimal import Decimal, ROUND_DOWN\n",
|
|
"from typing import Any\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": 2,
|
|
"id": "c6151613",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"VAL_KEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d83c61e5",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"\n",
|
|
"config_update = {\n",
|
|
" # 'Config': {\n",
|
|
" # 'Price_Worsener_Aster': 0,\n",
|
|
" # 'Price_Worsener_Extend': -1\n",
|
|
" # 'Min_Time_To_Funding_Minutes': 60\n",
|
|
" # 'Min_Fund_Rate_Pct_To_Trade': 0.0\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': True,\n",
|
|
" # # 'Flatten_Open_Positions': False,\n",
|
|
" # # 'Flatten_Open_Positions_Opportunistic': False,\n",
|
|
" # },\n",
|
|
"}\n",
|
|
"VAL_KEY.publish('fr_orchestrator_input', json.dumps(config_update))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"id": "7e448690",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"### ALGO FLOW ###\n",
|
|
"best_symbol_by_exchange: dict = json.loads(s=VAL_KEY.get(name='fr_engine_best_fund_rate_output')) # ty:ignore[invalid-argument-type]\n",
|
|
"Aster = structs.Perpetual_Exchange(**best_symbol_by_exchange['ASTER'])\n",
|
|
"Extend = structs.Perpetual_Exchange(**best_symbol_by_exchange['EXTEND'])\n",
|
|
" \n",
|
|
" # await get_aster_exch_info(symbol_override=Open_Symbols[0])\n",
|
|
" # await get_extend_exch_info(symbol_override=Open_Symbols[0])\n",
|
|
"\n",
|
|
"with open('algo_config.json', mode='r', encoding='utf-8') as file:\n",
|
|
" Config = json.load(file)\n",
|
|
" Config = structs.Algo_Config(**Config)\n",
|
|
"\n",
|
|
"Config.Config.Max_Target_Notional = float(min([Aster.mult, Extend.mult]) * Config.Config.Target_Open_Cash_Position)\n",
|
|
"# logging.info(f'Initial Algo Config: {ALGO_CONFIG}')\n",
|
|
"\n",
|
|
"VAL_KEY.set(name='fr_orchestrator_output', value=json.dumps(obj=Config.model_dump()))\n",
|
|
"VAL_KEY.set(name='fr_algo_working_symbol', value=json.dumps(obj={'ASTER': asdict(obj=Aster), 'EXTEND': asdict(obj=Extend)}))\n",
|
|
"\n",
|
|
"aster_ticker_dict: Any = VAL_KEY.get('fut_ticker_aster')\n",
|
|
"aster_ticker_dict: dict = json.loads(s=aster_ticker_dict) if aster_ticker_dict is not None else {}\n",
|
|
"if ( aster_ticker_dict.get('symbol', None) != Aster.symbol ) and not(Config.Overrides.Flatten_Open_Positions):\n",
|
|
" VAL_KEY.set(name='fr_algo_working_symbol', value=json.dumps(obj={'ASTER': asdict(obj=Aster), 'EXTEND': asdict(obj=Extend)}))\n",
|
|
"\n",
|
|
" # raise ValueError(f'ASTER Symbol mismatch: {ASTER_TICKER_DICT}; expected symbol: {ASTER.symbol}')\n",
|
|
"\n",
|
|
"extend_ticker_dict: Any = VAL_KEY.get('fut_ticker_extended')\n",
|
|
"extend_ticker_dict: dict = json.loads(s=extend_ticker_dict) if extend_ticker_dict is not None else {}\n",
|
|
"if ( extend_ticker_dict.get('symbol', None) != Extend.symbol) and not(Config.Overrides.Flatten_Open_Positions):\n",
|
|
" VAL_KEY.set(name='fr_algo_working_symbol', value=json.dumps(obj={'ASTER': asdict(obj=Aster), 'EXTEND': asdict(obj=Extend)}))\n",
|
|
" # raise ValueError(f'EXTEND Symbol mismatch: {EXTENDED_TICKER_DICT}; expected symbol: {EXTEND.symbol}')\n",
|
|
"\n",
|
|
"### Load Local Notional Updates from WS ###\n",
|
|
"aster_ws_pos_updates: Any = VAL_KEY.get(name='fr_aster_user_positions')\n",
|
|
"aster_ws_pos_updates: list = json.loads(s=aster_ws_pos_updates) if aster_ws_pos_updates is not None else []\n",
|
|
"extend_ws_pos_updates: Any = VAL_KEY.get('fr_extended_user_positions')\n",
|
|
"extend_ws_pos_updates: list = json.loads(extend_ws_pos_updates) if extend_ws_pos_updates is not None else [] \n",
|
|
"\n",
|
|
"### Load Local Order Updates from WS ###\n",
|
|
"aster_ws_order_updates: Any = VAL_KEY.get('fr_aster_user_orders')\n",
|
|
"aster_ws_order_updates: list = json.loads(aster_ws_order_updates) if aster_ws_order_updates is not None else [] \n",
|
|
"extend_ws_order_updates: Any = VAL_KEY.get('fr_extended_user_orders')\n",
|
|
"extend_ws_order_updates: list = json.loads(extend_ws_order_updates) if extend_ws_order_updates is not None else [] "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bd57998f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "b1f9e445",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'ASTER': {'lh_asset': 'HYPE',\n",
|
|
" 'rh_asset': 'USDT',\n",
|
|
" 'symbol': 'HYPEUSDT',\n",
|
|
" 'symbol_asset_separator': '',\n",
|
|
" 'mult': 300,\n",
|
|
" 'initial_funding_rate': 5e-05,\n",
|
|
" 'min_price': 0.001,\n",
|
|
" 'min_order_size': 0.01,\n",
|
|
" 'min_lot_size': 0.01,\n",
|
|
" 'min_notional': 5.0,\n",
|
|
" 'buy_ratio': -7.932280984035422e-05,\n",
|
|
" 'notional_obj': {},\n",
|
|
" 'notional_position': 0,\n",
|
|
" 'unrealized_pnl': 0,\n",
|
|
" 'buy_ratio_std': 0.00032830394884566453,\n",
|
|
" 'just_rejected_count': 0},\n",
|
|
" 'EXTEND': {'lh_asset': 'HYPE',\n",
|
|
" 'rh_asset': 'USD',\n",
|
|
" 'symbol': 'HYPE-USD',\n",
|
|
" 'symbol_asset_separator': '-',\n",
|
|
" 'mult': 50,\n",
|
|
" 'initial_funding_rate': 1.3e-05,\n",
|
|
" 'min_price': 0.001,\n",
|
|
" 'min_order_size': 0.1,\n",
|
|
" 'min_lot_size': 0.01,\n",
|
|
" 'min_notional': 0.0,\n",
|
|
" 'buy_ratio': 7.932280984035422e-05,\n",
|
|
" 'notional_obj': {},\n",
|
|
" 'notional_position': 0,\n",
|
|
" 'unrealized_pnl': 0,\n",
|
|
" 'buy_ratio_std': 0.00032830394884566453,\n",
|
|
" 'just_rejected_count': 0}}"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"best_symbol_by_exchange"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "1d72da04",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'timestamp_arrival': 1778094603500,\n",
|
|
" 'timestamp_msg': 1778094603488,\n",
|
|
" 'timestamp_transaction': 1778094603450,\n",
|
|
" 'orderbook_update_id': 460270647968,\n",
|
|
" 'symbol': 'DOGEUSDT',\n",
|
|
" 'best_bid_px': '0.112900',\n",
|
|
" 'best_bid_qty': '11768',\n",
|
|
" 'best_ask_px': '0.112910',\n",
|
|
" 'best_ask_qty': '8626'}"
|
|
]
|
|
},
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"aster_ticker_dict"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 50,
|
|
"id": "2ef09dc6",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Decimal('1.00')"
|
|
]
|
|
},
|
|
"execution_count": 50,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"abs(Decimal('-1.00'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f45593f7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "0bcf9b05",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0"
|
|
]
|
|
},
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"Aster.notional_position\n",
|
|
"Extend.notional_position"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5934a164",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"@dataclass(kw_only=True)\n",
|
|
"class Signal:\n",
|
|
" signal: bool\n",
|
|
" exchange: str # ASTER | EXTEND\n",
|
|
" side: str # BUY | SELL\n",
|
|
" symbol: str # e.g. BTC-USD\n",
|
|
" expected_alpha: Decimal # e.g. BTC-USD\n",
|
|
" model_ratio: Decimal\n",
|
|
" current_ratio: Decimal\n",
|
|
"\n",
|
|
"@dataclass(kw_only=True)\n",
|
|
"class Target:\n",
|
|
" exchange: str # ASTER | EXTEND\n",
|
|
" side: str # BUY | SELL\n",
|
|
" symbol: str # e.g. BTC-USD\n",
|
|
" notional_tgt: Decimal\n",
|
|
" notional_tail: Decimal\n",
|
|
" base_tgt: Decimal\n",
|
|
" base_tail: Decimal"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"id": "27c193de",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def signal_alpha_over_taker(Aster: structs.Perpetual_Exchange, Extend: structs.Perpetual_Exchange, aster_ticker_dict: dict, extend_ticker_dict: dict) -> Signal:\n",
|
|
" aster_mid_px: Decimal = ( Decimal(str(aster_ticker_dict['best_ask_px'])) + Decimal(str(aster_ticker_dict['best_bid_px'])) ) / 2\n",
|
|
" extend_mid_px: Decimal = ( Decimal(str(extend_ticker_dict['best_ask_px'])) + Decimal(str(extend_ticker_dict['best_bid_px'])) ) / 2\n",
|
|
"\n",
|
|
" aster_buy_ratio: Decimal = (extend_mid_px / aster_mid_px) - 1\n",
|
|
" extend_buy_ratio: Decimal = aster_buy_ratio*-1\n",
|
|
"\n",
|
|
" extend_taker_fee: Decimal = Decimal(str(0.00025))\n",
|
|
"\n",
|
|
" aster_buy_ratio_min_taker = Decimal(str(aster_buy_ratio)) - extend_taker_fee\n",
|
|
" extend_buy_ratio_min_taker = Decimal(str(extend_buy_ratio)) - extend_taker_fee\n",
|
|
"\n",
|
|
" aster_buy_expected_alpha: Decimal = ( aster_buy_ratio_min_taker - Decimal(str(Aster.buy_ratio)) ).quantize(Decimal('0.0001'), rounding='ROUND_DOWN') # Decimal Price % Diff (x Qty = Alpha $)\n",
|
|
" extend_buy_expected_alpha: Decimal = ( extend_buy_ratio_min_taker - Decimal(str(Extend.buy_ratio)) ).quantize(Decimal('0.0001'), rounding='ROUND_DOWN') # Decimal Price % Diff (x Qty = Alpha $)\n",
|
|
" \n",
|
|
" if aster_buy_expected_alpha > 0:\n",
|
|
" signal: bool = True\n",
|
|
" exchange: str = 'ASTER'\n",
|
|
" side: str = 'BUY'\n",
|
|
" symbol: str = Extend.symbol # USING EXT SYMBOL AS DEFAULT\n",
|
|
" expected_alpha: Decimal = aster_buy_expected_alpha\n",
|
|
" model_ratio: Decimal = Decimal(str(Aster.buy_ratio))\n",
|
|
" current_ratio: Decimal = aster_buy_ratio_min_taker\n",
|
|
" elif extend_buy_expected_alpha > 0:\n",
|
|
" signal: bool = True\n",
|
|
" exchange: str = 'EXTEND'\n",
|
|
" side: str = 'BUY'\n",
|
|
" symbol: str = Extend.symbol\n",
|
|
" expected_alpha: Decimal = extend_buy_expected_alpha\n",
|
|
" model_ratio: Decimal = Decimal(str(Extend.buy_ratio))\n",
|
|
" current_ratio: Decimal = extend_buy_ratio_min_taker\n",
|
|
" else:\n",
|
|
" signal: bool = False\n",
|
|
" exchange: str = ''\n",
|
|
" side: str = ''\n",
|
|
" symbol: str = ''\n",
|
|
" expected_alpha: Decimal = Decimal('0.00')\n",
|
|
" model_ratio: Decimal = Decimal('0.00')\n",
|
|
" current_ratio: Decimal = Decimal('0.00')\n",
|
|
"\n",
|
|
" return Signal(\n",
|
|
" signal = signal,\n",
|
|
" exchange = exchange,\n",
|
|
" side = side,\n",
|
|
" symbol = symbol,\n",
|
|
" expected_alpha = expected_alpha,\n",
|
|
" model_ratio = model_ratio,\n",
|
|
" current_ratio = current_ratio,\n",
|
|
" )\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"id": "407919b8",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Signal(signal=True, exchange='ASTER', side='BUY', symbol='BTC-USD', expected_alpha=Decimal('0.0015'), mid_px=Decimal('0.0176660'))"
|
|
]
|
|
},
|
|
"execution_count": 31,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"signal_alpha_over_taker(Aster=Aster, Extend=Extend, aster_ticker_dict=aster_ticker_dict, extend_ticker_dict=extend_ticker_dict)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6e946c16",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"master_data = json.loads(s=VAL_KEY.get(name='fr_engine_best_fund_rate_master'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 27,
|
|
"id": "a5f57c5e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"df = pd.DataFrame(master_data)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"best_d = df.sort_values(by='max_leverage_ast', ascending=False).iloc[0].to_dict()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"id": "59ef536d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Aster = structs.Perpetual_Exchange(\n",
|
|
" mult = int(best_d['max_leverage_ast']),\n",
|
|
" lh_asset = best_d['lh_asset_ast'],\n",
|
|
" rh_asset = best_d['rh_asset_ast'],\n",
|
|
" symbol_asset_separator = '',\n",
|
|
" initial_funding_rate=float(best_d['funding_rate_ast']),\n",
|
|
" min_price=float(best_d['min_price_ast']),\n",
|
|
" min_order_size=float(best_d['min_order_size_ast']),\n",
|
|
" min_lot_size=float(best_d['min_lot_size_ast']),\n",
|
|
" min_notional=float(best_d['min_notional_ast']),\n",
|
|
" buy_ratio=float(best_d['buy_ratio_ast']),\n",
|
|
" # buy_ratio_std=float(best_d['buy_ratio_std']),\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 40,
|
|
"id": "011bf510",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'symbol_ast': 'HYPEUSDT',\n",
|
|
" 'max_leverage_ast': 300,\n",
|
|
" 'lh_asset_ast': 'HYPE',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': -0.00010404,\n",
|
|
" 'min_price_ast': '0.00100',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0001197311,\n",
|
|
" 'symbol_ext': 'HYPE-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'HYPE',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -2e-05,\n",
|
|
" 'min_price_ext': '0.001',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0001197311}"
|
|
]
|
|
},
|
|
"execution_count": 40,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"best_d"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "199fe99c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Timestamp('2026-05-06 12:40:45.883000')"
|
|
]
|
|
},
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"pd.to_datetime(1778071245883, unit='ms')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "581a8d07",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Timestamp('2026-05-06 12:40:46.880000')"
|
|
]
|
|
},
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"pd.to_datetime(1778071246880, unit='ms')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"id": "da1376d4",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'ASTER': {'lh_asset': 'HYPE',\n",
|
|
" 'rh_asset': 'USDT',\n",
|
|
" 'symbol': 'HYPEUSDT',\n",
|
|
" 'symbol_asset_separator': '',\n",
|
|
" 'mult': 300,\n",
|
|
" 'initial_funding_rate': -0.00010273,\n",
|
|
" 'min_price': 0.001,\n",
|
|
" 'min_order_size': 0.01,\n",
|
|
" 'min_lot_size': 0.01,\n",
|
|
" 'min_notional': 5.0,\n",
|
|
" 'buy_ratio': -0.00011925787527911069,\n",
|
|
" 'notional_obj': {},\n",
|
|
" 'notional_position': 0,\n",
|
|
" 'unrealized_pnl': 0},\n",
|
|
" 'EXTEND': {'lh_asset': 'HYPE',\n",
|
|
" 'rh_asset': 'USD',\n",
|
|
" 'symbol': 'HYPE-USD',\n",
|
|
" 'symbol_asset_separator': '-',\n",
|
|
" 'mult': 50,\n",
|
|
" 'initial_funding_rate': -2e-05,\n",
|
|
" 'min_price': 0.001,\n",
|
|
" 'min_order_size': 0.1,\n",
|
|
" 'min_lot_size': 0.01,\n",
|
|
" 'min_notional': 0.0,\n",
|
|
" 'buy_ratio': 0.00011925787527911069,\n",
|
|
" 'notional_obj': {},\n",
|
|
" 'notional_position': 0,\n",
|
|
" 'unrealized_pnl': 0}}"
|
|
]
|
|
},
|
|
"execution_count": 31,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"best"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0592f244",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "cd600e0e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from decimal import Decimal"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 33,
|
|
"id": "db52edf9",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0"
|
|
]
|
|
},
|
|
"execution_count": 33,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"int(Decimal(0.56))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"id": "7953fdfb",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Decimal('0.3136')"
|
|
]
|
|
},
|
|
"execution_count": 36,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"Decimal(str(0.56))*Decimal(str(0.56))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'{\"last_update_ts_ms\": 1778123362898, \"status\": \"WORKING\", \"expected_alpha\": -0.000225}'"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"VAL_KEY.get(name='algo_status')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0bb60f52",
|
|
"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": 7,
|
|
"id": "5f7535df",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[{'symbol_ast': 'ETHUSDT',\n",
|
|
" 'max_leverage_ast': 150,\n",
|
|
" 'lh_asset_ast': 'ETH',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 7.68e-05,\n",
|
|
" 'min_price_ast': '0.01',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0002467748,\n",
|
|
" 'symbol_ext': 'ETH-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'ETH',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -2.1e-05,\n",
|
|
" 'min_price_ext': '0.1',\n",
|
|
" 'min_order_size_ext': '0.01',\n",
|
|
" 'min_lot_size_ext': '0.001',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0002467748,\n",
|
|
" 'buy_ratio_std': 0.0001349023,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'HYPEUSDT',\n",
|
|
" 'max_leverage_ast': 300,\n",
|
|
" 'lh_asset_ast': 'HYPE',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 5e-05,\n",
|
|
" 'min_price_ast': '0.00100',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': 6.31401e-05,\n",
|
|
" 'symbol_ext': 'HYPE-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'HYPE',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.001',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': -6.31401e-05,\n",
|
|
" 'buy_ratio_std': 0.0003159488,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'LITUSDT',\n",
|
|
" 'max_leverage_ast': 50,\n",
|
|
" 'lh_asset_ast': 'LIT',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 4.51e-05,\n",
|
|
" 'min_price_ast': '0.0001000',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0005306307,\n",
|
|
" 'symbol_ext': 'LIT-USD',\n",
|
|
" 'max_leverage_ext': 25,\n",
|
|
" 'lh_asset_ext': 'LIT',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.0001',\n",
|
|
" 'min_order_size_ext': '10',\n",
|
|
" 'min_lot_size_ext': '1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0005306307,\n",
|
|
" 'buy_ratio_std': 0.0007812256,\n",
|
|
" 'next_funding_at_same_time': True},\n",
|
|
" {'symbol_ast': 'BNBUSDT',\n",
|
|
" 'max_leverage_ast': 100,\n",
|
|
" 'lh_asset_ast': 'BNB',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.0,\n",
|
|
" 'min_price_ast': '0.010',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0008859719,\n",
|
|
" 'symbol_ext': 'BNB-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'BNB',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.01',\n",
|
|
" 'min_order_size_ext': '0.01',\n",
|
|
" 'min_lot_size_ext': '0.001',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0008859719,\n",
|
|
" 'buy_ratio_std': 0.0002193807,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'SOLUSDT',\n",
|
|
" 'max_leverage_ast': 100,\n",
|
|
" 'lh_asset_ast': 'SOL',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 9.428e-05,\n",
|
|
" 'min_price_ast': '0.4200',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0001122271,\n",
|
|
" 'symbol_ext': 'SOL-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'SOL',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.01',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0001122271,\n",
|
|
" 'buy_ratio_std': 0.0002044953,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'XRPUSDT',\n",
|
|
" 'max_leverage_ast': 100,\n",
|
|
" 'lh_asset_ast': 'XRP',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 3.175e-05,\n",
|
|
" 'min_price_ast': '0.0143',\n",
|
|
" 'min_order_size_ast': '0.1',\n",
|
|
" 'min_lot_size_ast': '0.1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0001042321,\n",
|
|
" 'symbol_ext': 'XRP-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'XRP',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.0001',\n",
|
|
" 'min_order_size_ext': '10',\n",
|
|
" 'min_lot_size_ext': '1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0001042321,\n",
|
|
" 'buy_ratio_std': 0.0001123218,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'DOGEUSDT',\n",
|
|
" 'max_leverage_ast': 75,\n",
|
|
" 'lh_asset_ast': 'DOGE',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.0001,\n",
|
|
" 'min_price_ast': '0.002440',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': 0.0013930884,\n",
|
|
" 'symbol_ext': 'DOGE-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'DOGE',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.00001',\n",
|
|
" 'min_order_size_ext': '100',\n",
|
|
" 'min_lot_size_ext': '10',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': -0.0013930884,\n",
|
|
" 'buy_ratio_std': 0.0003880879,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'BTCUSDT',\n",
|
|
" 'max_leverage_ast': 150,\n",
|
|
" 'lh_asset_ast': 'BTC',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': -4.728e-05,\n",
|
|
" 'min_price_ast': '1',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0001633518,\n",
|
|
" 'symbol_ext': 'BTC-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'BTC',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -6e-06,\n",
|
|
" 'min_price_ext': '1',\n",
|
|
" 'min_order_size_ext': '0.0001',\n",
|
|
" 'min_lot_size_ext': '0.00001',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0001633518,\n",
|
|
" 'buy_ratio_std': 9.37709e-05,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'WLFIUSDT',\n",
|
|
" 'max_leverage_ast': 25,\n",
|
|
" 'lh_asset_ast': 'WLFI',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 5e-05,\n",
|
|
" 'min_price_ast': '0.0001000',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0014241811,\n",
|
|
" 'symbol_ext': 'WLFI-USD',\n",
|
|
" 'max_leverage_ext': 10,\n",
|
|
" 'lh_asset_ext': 'WLFI',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.00001',\n",
|
|
" 'min_order_size_ext': '100',\n",
|
|
" 'min_lot_size_ext': '10',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0014241811,\n",
|
|
" 'buy_ratio_std': 0.0010500062,\n",
|
|
" 'next_funding_at_same_time': False},\n",
|
|
" {'symbol_ast': 'ZECUSDT',\n",
|
|
" 'max_leverage_ast': 75,\n",
|
|
" 'lh_asset_ast': 'ZEC',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 1.25e-05,\n",
|
|
" 'min_price_ast': '0.0100',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': 0.0003491807,\n",
|
|
" 'symbol_ext': 'ZEC-USD',\n",
|
|
" 'max_leverage_ext': 10,\n",
|
|
" 'lh_asset_ext': 'ZEC',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.001',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': -0.0003491807,\n",
|
|
" 'buy_ratio_std': 0.0012735632,\n",
|
|
" 'next_funding_at_same_time': True}]"
|
|
]
|
|
},
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"json.loads(VAL_KEY.get('fr_engine_best_fund_rate_master'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"id": "b71bd50c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"min_lot = 10\n",
|
|
"order = 601"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"id": "56f77b83",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"600"
|
|
]
|
|
},
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"order - ( order % min_lot )"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"id": "7a566db7",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"c = 500\n",
|
|
"target = 400\n",
|
|
"order = 10"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 35,
|
|
"id": "c9d67074",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Should be selling, but its not - skipping\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if (target < c) and ((c + order) > c):\n",
|
|
" print('Should be selling, but its not - skipping')\n",
|
|
"else:\n",
|
|
" print('good')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "4328f2e9",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import plotly.express as px\n",
|
|
"import numpy as np\n",
|
|
"from decimal import Decimal"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "d1b91123",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def calc_fr_minutes_remaining_factor(\n",
|
|
" min_start_procedure: int = 30,\n",
|
|
" min_to_end_procedure: int = 7,\n",
|
|
" factor_exp_pct: float = 0.50\n",
|
|
"):\n",
|
|
" factors = [np.float64(0.00)]\n",
|
|
" for x in range(min_start_procedure+1,61-min_to_end_procedure):\n",
|
|
" y = (x)**(np.log(x)*factor_exp_pct)\n",
|
|
" factors.append(y)\n",
|
|
"\n",
|
|
" pcts = list( factors / np.max(factors) )\n",
|
|
" for x in range(61-min_to_end_procedure, 61):\n",
|
|
" pcts.append(1)\n",
|
|
"\n",
|
|
" pcts.reverse()\n",
|
|
"\n",
|
|
" return pcts\n",
|
|
"\n",
|
|
"def get_fr_factor_by_minute(min_left: int, factor_pcts: list) -> Decimal:\n",
|
|
" return Decimal(str(factor_pcts[min(len(factor_pcts) - 1, min_left)])).quantize(Decimal('0.0001'))\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"id": "b145959f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"pcts = calc_fr_minutes_remaining_factor()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Decimal('0.8590')"
|
|
]
|
|
},
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"get_fr_factor_by_minute(9, pcts)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9cd9213a",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "716fbef8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 216,
|
|
"id": "db91dfff",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.plotly.v1+json": {
|
|
"config": {
|
|
"plotlyServerURL": "https://plot.ly"
|
|
},
|
|
"data": [
|
|
{
|
|
"hovertemplate": "variable=0<br>index=%{x}<br>value=%{y}<extra></extra>",
|
|
"legendgroup": "0",
|
|
"line": {
|
|
"color": "#636efa",
|
|
"dash": "solid"
|
|
},
|
|
"marker": {
|
|
"symbol": "circle"
|
|
},
|
|
"mode": "lines",
|
|
"name": "0",
|
|
"orientation": "v",
|
|
"showlegend": true,
|
|
"type": "scatter",
|
|
"x": {
|
|
"bdata": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHg==",
|
|
"dtype": "i1"
|
|
},
|
|
"xaxis": "x",
|
|
"y": {
|
|
"bdata": "AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPxy3NpKwrO0/4gplc/R86z8UlYkfHm/pP1FhTy6Pgec/IzlJ9bey5T9RF5UrFwHkP4XT5I45a+I/NRnpibnv4D93gje4fRrfP3lOzYX8hNw/+S9ISHIc2j8O8etzet7XP1KS4X/IyNU/MVUvQyfZ0z+hHU1UeA3SPwaFT2uzY9A/F/5HjcuzzT9W8LAkY9zKP8i60aOaPcg/uwgamQbUxT8t6AL4YZzDP5cui/uMk8E/AAAAAAAAAAA=",
|
|
"dtype": "f8"
|
|
},
|
|
"yaxis": "y"
|
|
}
|
|
],
|
|
"layout": {
|
|
"legend": {
|
|
"title": {
|
|
"text": "variable"
|
|
},
|
|
"tracegroupgap": 0
|
|
},
|
|
"margin": {
|
|
"t": 60
|
|
},
|
|
"template": {
|
|
"data": {
|
|
"bar": [
|
|
{
|
|
"error_x": {
|
|
"color": "#2a3f5f"
|
|
},
|
|
"error_y": {
|
|
"color": "#2a3f5f"
|
|
},
|
|
"marker": {
|
|
"line": {
|
|
"color": "#E5ECF6",
|
|
"width": 0.5
|
|
},
|
|
"pattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
}
|
|
},
|
|
"type": "bar"
|
|
}
|
|
],
|
|
"barpolar": [
|
|
{
|
|
"marker": {
|
|
"line": {
|
|
"color": "#E5ECF6",
|
|
"width": 0.5
|
|
},
|
|
"pattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
}
|
|
},
|
|
"type": "barpolar"
|
|
}
|
|
],
|
|
"carpet": [
|
|
{
|
|
"aaxis": {
|
|
"endlinecolor": "#2a3f5f",
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"minorgridcolor": "white",
|
|
"startlinecolor": "#2a3f5f"
|
|
},
|
|
"baxis": {
|
|
"endlinecolor": "#2a3f5f",
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"minorgridcolor": "white",
|
|
"startlinecolor": "#2a3f5f"
|
|
},
|
|
"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": [
|
|
{
|
|
"fillpattern": {
|
|
"fillmode": "overlay",
|
|
"size": 10,
|
|
"solidity": 0.2
|
|
},
|
|
"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": {
|
|
"colorbar": {
|
|
"outlinewidth": 0,
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"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": "#EBF0F8"
|
|
},
|
|
"line": {
|
|
"color": "white"
|
|
}
|
|
},
|
|
"header": {
|
|
"fill": {
|
|
"color": "#C8D4E3"
|
|
},
|
|
"line": {
|
|
"color": "white"
|
|
}
|
|
},
|
|
"type": "table"
|
|
}
|
|
]
|
|
},
|
|
"layout": {
|
|
"annotationdefaults": {
|
|
"arrowcolor": "#2a3f5f",
|
|
"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": "#2a3f5f"
|
|
},
|
|
"geo": {
|
|
"bgcolor": "white",
|
|
"lakecolor": "white",
|
|
"landcolor": "#E5ECF6",
|
|
"showlakes": true,
|
|
"showland": true,
|
|
"subunitcolor": "white"
|
|
},
|
|
"hoverlabel": {
|
|
"align": "left"
|
|
},
|
|
"hovermode": "closest",
|
|
"mapbox": {
|
|
"style": "light"
|
|
},
|
|
"paper_bgcolor": "white",
|
|
"plot_bgcolor": "#E5ECF6",
|
|
"polar": {
|
|
"angularaxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
},
|
|
"bgcolor": "#E5ECF6",
|
|
"radialaxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"scene": {
|
|
"xaxis": {
|
|
"backgroundcolor": "#E5ECF6",
|
|
"gridcolor": "white",
|
|
"gridwidth": 2,
|
|
"linecolor": "white",
|
|
"showbackground": true,
|
|
"ticks": "",
|
|
"zerolinecolor": "white"
|
|
},
|
|
"yaxis": {
|
|
"backgroundcolor": "#E5ECF6",
|
|
"gridcolor": "white",
|
|
"gridwidth": 2,
|
|
"linecolor": "white",
|
|
"showbackground": true,
|
|
"ticks": "",
|
|
"zerolinecolor": "white"
|
|
},
|
|
"zaxis": {
|
|
"backgroundcolor": "#E5ECF6",
|
|
"gridcolor": "white",
|
|
"gridwidth": 2,
|
|
"linecolor": "white",
|
|
"showbackground": true,
|
|
"ticks": "",
|
|
"zerolinecolor": "white"
|
|
}
|
|
},
|
|
"shapedefaults": {
|
|
"line": {
|
|
"color": "#2a3f5f"
|
|
}
|
|
},
|
|
"ternary": {
|
|
"aaxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
},
|
|
"baxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
},
|
|
"bgcolor": "#E5ECF6",
|
|
"caxis": {
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": ""
|
|
}
|
|
},
|
|
"title": {
|
|
"x": 0.05
|
|
},
|
|
"xaxis": {
|
|
"automargin": true,
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": "",
|
|
"title": {
|
|
"standoff": 15
|
|
},
|
|
"zerolinecolor": "white",
|
|
"zerolinewidth": 2
|
|
},
|
|
"yaxis": {
|
|
"automargin": true,
|
|
"gridcolor": "white",
|
|
"linecolor": "white",
|
|
"ticks": "",
|
|
"title": {
|
|
"standoff": 15
|
|
},
|
|
"zerolinecolor": "white",
|
|
"zerolinewidth": 2
|
|
}
|
|
}
|
|
},
|
|
"xaxis": {
|
|
"anchor": "y",
|
|
"domain": [
|
|
0,
|
|
1
|
|
],
|
|
"title": {
|
|
"text": "index"
|
|
}
|
|
},
|
|
"yaxis": {
|
|
"anchor": "x",
|
|
"domain": [
|
|
0,
|
|
1
|
|
],
|
|
"title": {
|
|
"text": "value"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"px.line(pd.DataFrame(pcts))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b3b5fb75",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 208,
|
|
"id": "d11dec9e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"np.float64(0.9273302894341415)"
|
|
]
|
|
},
|
|
"execution_count": 208,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 201,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"41"
|
|
]
|
|
},
|
|
"execution_count": 201,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c77b418e",
|
|
"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": 41,
|
|
"id": "9eb7e9b5",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Timestamp('2026-05-03 15:00:00')"
|
|
]
|
|
},
|
|
"execution_count": 41,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"pd.to_datetime(1777820400000, unit='ms')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "101dbef1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"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": 35,
|
|
"id": "b417adad",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"best_symbol_by_exchange: dict = json.loads(s=VAL_KEY.get(name='fr_engine_best_fund_rate_output')) # ty:ignore[invalid-argument-type]\n",
|
|
"best_symbol_by_exchange_aster = structs.Perpetual_Exchange(**best_symbol_by_exchange['ASTER'])\n",
|
|
"best_symbol_by_exchange_extend = structs.Perpetual_Exchange(**best_symbol_by_exchange['EXTEND'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 36,
|
|
"id": "ba98754e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Perpetual_Exchange(lh_asset='HYPE', rh_asset='USDT', symbol='HYPEUSDT', symbol_asset_separator='', mult=300, initial_funding_rate=5e-05, min_price=0.001, min_order_size=0.01, min_lot_size=0.01, min_notional=5.0, buy_ratio=-6.770327912997143e-05, notional_obj={}, notional_position=0, unrealized_pnl=0, buy_ratio_std=0.0003294334756256642, just_rejected_count=0)"
|
|
]
|
|
},
|
|
"execution_count": 36,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"best_symbol_by_exchange_aster"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 37,
|
|
"id": "fa5a8e85",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Perpetual_Exchange(lh_asset='HYPE', rh_asset='USD', symbol='HYPE-USD', symbol_asset_separator='-', mult=50, initial_funding_rate=1.3e-05, min_price=0.001, min_order_size=0.1, min_lot_size=0.01, min_notional=0.0, buy_ratio=6.770327912997143e-05, notional_obj={}, notional_position=0, unrealized_pnl=0, buy_ratio_std=0.0003294334756256642, just_rejected_count=0)"
|
|
]
|
|
},
|
|
"execution_count": 37,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"best_symbol_by_exchange_extend"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 39,
|
|
"id": "d452385f",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0.005000%\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(f'{best_symbol_by_exchange_aster.initial_funding_rate:.6%}')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 41,
|
|
"id": "ff024b08",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0.001300%\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(f'{best_symbol_by_exchange_extend.initial_funding_rate:.6%}')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 33,
|
|
"id": "9431d9ff",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0.003700%\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(f'{r:.6%}')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0.00114737"
|
|
]
|
|
},
|
|
"execution_count": 29,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"0.00114737"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"id": "77124f29",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"r = max([best_symbol_by_exchange_aster.initial_funding_rate, best_symbol_by_exchange_extend.initial_funding_rate]) - min([best_symbol_by_exchange_aster.initial_funding_rate, best_symbol_by_exchange_extend.initial_funding_rate])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"id": "36ab3e79",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"0.0019584100000000003"
|
|
]
|
|
},
|
|
"execution_count": 34,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"0.0000195841000000000026465*100"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"[{'symbol_ast': 'XMRUSDT',\n",
|
|
" 'max_leverage_ast': 50,\n",
|
|
" 'lh_asset_ast': 'XMR',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 7.078e-05,\n",
|
|
" 'min_price_ast': '0.01',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0008651383,\n",
|
|
" 'symbol_ext': 'XMR-USD',\n",
|
|
" 'max_leverage_ext': 25,\n",
|
|
" 'lh_asset_ext': 'XMR',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.01',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0008651383,\n",
|
|
" 'buy_ratio_std': 0.0015525267},\n",
|
|
" {'symbol_ast': 'ETHUSDT',\n",
|
|
" 'max_leverage_ast': 150,\n",
|
|
" 'lh_asset_ast': 'ETH',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 7.304e-05,\n",
|
|
" 'min_price_ast': '0.01',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0002131019,\n",
|
|
" 'symbol_ext': 'ETH-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'ETH',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -2.1e-05,\n",
|
|
" 'min_price_ext': '0.1',\n",
|
|
" 'min_order_size_ext': '0.01',\n",
|
|
" 'min_lot_size_ext': '0.001',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0002131019,\n",
|
|
" 'buy_ratio_std': 0.0001224161},\n",
|
|
" {'symbol_ast': 'CHIPUSDT',\n",
|
|
" 'max_leverage_ast': 50,\n",
|
|
" 'lh_asset_ast': 'CHIP',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 1.25e-05,\n",
|
|
" 'min_price_ast': '0.0000100',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0007137488,\n",
|
|
" 'symbol_ext': 'CHIP-USD',\n",
|
|
" 'max_leverage_ext': 5,\n",
|
|
" 'lh_asset_ext': 'CHIP',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -0.000114,\n",
|
|
" 'min_price_ext': '0.000001',\n",
|
|
" 'min_order_size_ext': '100',\n",
|
|
" 'min_lot_size_ext': '10',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0007137488,\n",
|
|
" 'buy_ratio_std': 0.0019427015},\n",
|
|
" {'symbol_ast': 'HYPEUSDT',\n",
|
|
" 'max_leverage_ast': 300,\n",
|
|
" 'lh_asset_ast': 'HYPE',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 5e-05,\n",
|
|
" 'min_price_ast': '0.00100',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -3.96037e-05,\n",
|
|
" 'symbol_ext': 'HYPE-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'HYPE',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.001',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 3.96037e-05,\n",
|
|
" 'buy_ratio_std': 0.0003210041},\n",
|
|
" {'symbol_ast': 'BTCUSDT',\n",
|
|
" 'max_leverage_ast': 150,\n",
|
|
" 'lh_asset_ast': 'BTC',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': -4.842e-05,\n",
|
|
" 'min_price_ast': '1',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0001399255,\n",
|
|
" 'symbol_ext': 'BTC-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'BTC',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -1.3e-05,\n",
|
|
" 'min_price_ext': '1',\n",
|
|
" 'min_order_size_ext': '0.0001',\n",
|
|
" 'min_lot_size_ext': '0.00001',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0001399255,\n",
|
|
" 'buy_ratio_std': 0.0001040703},\n",
|
|
" {'symbol_ast': 'BNBUSDT',\n",
|
|
" 'max_leverage_ast': 100,\n",
|
|
" 'lh_asset_ast': 'BNB',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.00024508,\n",
|
|
" 'min_price_ast': '0.010',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0009917987,\n",
|
|
" 'symbol_ext': 'BNB-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'BNB',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.01',\n",
|
|
" 'min_order_size_ext': '0.01',\n",
|
|
" 'min_lot_size_ext': '0.001',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0009917987,\n",
|
|
" 'buy_ratio_std': 0.0002374105},\n",
|
|
" {'symbol_ast': 'DOGEUSDT',\n",
|
|
" 'max_leverage_ast': 75,\n",
|
|
" 'lh_asset_ast': 'DOGE',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.0001,\n",
|
|
" 'min_price_ast': '0.002440',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': 0.0014628375,\n",
|
|
" 'symbol_ext': 'DOGE-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'DOGE',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.00001',\n",
|
|
" 'min_order_size_ext': '100',\n",
|
|
" 'min_lot_size_ext': '10',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': -0.0014628375,\n",
|
|
" 'buy_ratio_std': 0.000329719},\n",
|
|
" {'symbol_ast': 'SUIUSDT',\n",
|
|
" 'max_leverage_ast': 75,\n",
|
|
" 'lh_asset_ast': 'SUI',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.0001,\n",
|
|
" 'min_price_ast': '0.000100',\n",
|
|
" 'min_order_size_ast': '0.1',\n",
|
|
" 'min_lot_size_ast': '0.1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0002565291,\n",
|
|
" 'symbol_ext': 'SUI-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'SUI',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.0001',\n",
|
|
" 'min_order_size_ext': '10',\n",
|
|
" 'min_lot_size_ext': '1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0002565291,\n",
|
|
" 'buy_ratio_std': 0.0007973698},\n",
|
|
" {'symbol_ast': 'ASTERUSDT',\n",
|
|
" 'max_leverage_ast': 75,\n",
|
|
" 'lh_asset_ast': 'ASTER',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 3.357e-05,\n",
|
|
" 'min_price_ast': '0.00010',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': 0.0008699898,\n",
|
|
" 'symbol_ext': 'ASTER-USD',\n",
|
|
" 'max_leverage_ext': 25,\n",
|
|
" 'lh_asset_ext': 'ASTER',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.00001',\n",
|
|
" 'min_order_size_ext': '10',\n",
|
|
" 'min_lot_size_ext': '1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': -0.0008699898,\n",
|
|
" 'buy_ratio_std': 0.0003556531},\n",
|
|
" {'symbol_ast': 'LITUSDT',\n",
|
|
" 'max_leverage_ast': 50,\n",
|
|
" 'lh_asset_ast': 'LIT',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 2.658e-05,\n",
|
|
" 'min_price_ast': '0.0001000',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0004211414,\n",
|
|
" 'symbol_ext': 'LIT-USD',\n",
|
|
" 'max_leverage_ext': 25,\n",
|
|
" 'lh_asset_ext': 'LIT',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.0001',\n",
|
|
" 'min_order_size_ext': '10',\n",
|
|
" 'min_lot_size_ext': '1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0004211414,\n",
|
|
" 'buy_ratio_std': 0.0008731903},\n",
|
|
" {'symbol_ast': 'AAVEUSDT',\n",
|
|
" 'max_leverage_ast': 10,\n",
|
|
" 'lh_asset_ast': 'AAVE',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.0001,\n",
|
|
" 'min_price_ast': '4.400',\n",
|
|
" 'min_order_size_ast': '0.1',\n",
|
|
" 'min_lot_size_ast': '0.1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0006699361,\n",
|
|
" 'symbol_ext': 'AAVE-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'AAVE',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.01',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0006699361,\n",
|
|
" 'buy_ratio_std': 0.0009790403},\n",
|
|
" {'symbol_ast': 'SOLUSDT',\n",
|
|
" 'max_leverage_ast': 100,\n",
|
|
" 'lh_asset_ast': 'SOL',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 0.0001,\n",
|
|
" 'min_price_ast': '0.4200',\n",
|
|
" 'min_order_size_ast': '0.01',\n",
|
|
" 'min_lot_size_ast': '0.01',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -5.76552e-05,\n",
|
|
" 'symbol_ext': 'SOL-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'SOL',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 3e-06,\n",
|
|
" 'min_price_ext': '0.01',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.01',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 5.76552e-05,\n",
|
|
" 'buy_ratio_std': 0.0002188433},\n",
|
|
" {'symbol_ast': 'XRPUSDT',\n",
|
|
" 'max_leverage_ast': 100,\n",
|
|
" 'lh_asset_ast': 'XRP',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 1.236e-05,\n",
|
|
" 'min_price_ast': '0.0143',\n",
|
|
" 'min_order_size_ast': '0.1',\n",
|
|
" 'min_lot_size_ast': '0.1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0001058929,\n",
|
|
" 'symbol_ext': 'XRP-USD',\n",
|
|
" 'max_leverage_ext': 50,\n",
|
|
" 'lh_asset_ext': 'XRP',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': -1e-06,\n",
|
|
" 'min_price_ext': '0.0001',\n",
|
|
" 'min_order_size_ext': '10',\n",
|
|
" 'min_lot_size_ext': '1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0001058929,\n",
|
|
" 'buy_ratio_std': 0.0001141525},\n",
|
|
" {'symbol_ast': 'ZECUSDT',\n",
|
|
" 'max_leverage_ast': 75,\n",
|
|
" 'lh_asset_ast': 'ZEC',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 1.25e-05,\n",
|
|
" 'min_price_ast': '0.0100',\n",
|
|
" 'min_order_size_ast': '0.001',\n",
|
|
" 'min_lot_size_ast': '0.001',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': 0.0002039566,\n",
|
|
" 'symbol_ext': 'ZEC-USD',\n",
|
|
" 'max_leverage_ext': 10,\n",
|
|
" 'lh_asset_ext': 'ZEC',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.001',\n",
|
|
" 'min_order_size_ext': '0.1',\n",
|
|
" 'min_lot_size_ext': '0.1',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': -0.0002039566,\n",
|
|
" 'buy_ratio_std': 0.0013384919},\n",
|
|
" {'symbol_ast': '4USDT',\n",
|
|
" 'max_leverage_ast': 50,\n",
|
|
" 'lh_asset_ast': '4',\n",
|
|
" 'rh_asset_ast': 'USDT',\n",
|
|
" 'funding_rate_ast': 1.25e-05,\n",
|
|
" 'min_price_ast': '0.0000010',\n",
|
|
" 'min_order_size_ast': '1',\n",
|
|
" 'min_lot_size_ast': '1',\n",
|
|
" 'min_notional_ast': '5',\n",
|
|
" 'buy_ratio_ast': -0.0061657033,\n",
|
|
" 'symbol_ext': '4-USD',\n",
|
|
" 'max_leverage_ext': 5,\n",
|
|
" 'lh_asset_ext': '4',\n",
|
|
" 'rh_asset_ext': 'USD',\n",
|
|
" 'funding_rate_ext': 1.3e-05,\n",
|
|
" 'min_price_ext': '0.00001',\n",
|
|
" 'min_order_size_ext': '100',\n",
|
|
" 'min_lot_size_ext': '10',\n",
|
|
" 'min_notional_ext': 0.0,\n",
|
|
" 'buy_ratio_ext': 0.0061657033,\n",
|
|
" 'buy_ratio_std': 0.0042234248}]"
|
|
]
|
|
},
|
|
"execution_count": 42,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"json.loads(s=VAL_KEY.get(name='fr_engine_best_fund_rate_master'))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "09571e38",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"Decimal('1.0')"
|
|
]
|
|
},
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"Decimal('1.0').quantize()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1.0"
|
|
]
|
|
},
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"x = 1.0\n",
|
|
"x"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "70b57870",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"f = ['b','a','z','e']"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"['b', 'a', 'z', 'e']"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"f"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "9fd60c6e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"f.sort()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"id": "cd8b41de",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"['a', 'b', 'e', 'z']"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"f"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 46,
|
|
"id": "4c566e14",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"price = float(0.9066)\n",
|
|
"min_price = float(0.0001)\n",
|
|
"\n",
|
|
"min_price = int(min_price) if min_price == int(min_price) else min_price\n",
|
|
"price: Decimal = Decimal(str(price)).quantize(Decimal(str(min_price)), rounding=ROUND_DOWN)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "57fac02c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"### Locked Values 🔒🔑 ###"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 124,
|
|
"id": "8c2d003f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from sqlalchemy.util.typing import Self\n",
|
|
"from typing import Any\n",
|
|
"from collections.abc import Sequence, Callable\n",
|
|
"\n",
|
|
"class Locked_Value(Sequence):\n",
|
|
" def __init__(self, initial_value: Any, unlock_func: Callable):\n",
|
|
" self._value: Any = initial_value\n",
|
|
" self._unlock_func: Callable = unlock_func\n",
|
|
" self._is_locked: bool = True\n",
|
|
"\n",
|
|
" def __repr__(self):\n",
|
|
" return str((self._value, self._is_locked, self._unlock_func))\n",
|
|
"\n",
|
|
" def __len__(self):\n",
|
|
" return len((self._value, self._is_locked, self._unlock_func))\n",
|
|
"\n",
|
|
" def __getitem__(self, index):\n",
|
|
" return (self._value, self._is_locked, self._unlock_func)[index]\n",
|
|
"\n",
|
|
" def __str__(self):\n",
|
|
" return str((self._value))\n",
|
|
"\n",
|
|
" def unlock(self) -> Self:\n",
|
|
" if self._unlock_func():\n",
|
|
" self._is_locked = False\n",
|
|
" return self\n",
|
|
"\n",
|
|
" @property\n",
|
|
" def is_locked(self):\n",
|
|
" return self._is_locked\n",
|
|
"\n",
|
|
" @property\n",
|
|
" def value(self):\n",
|
|
" return self._value\n",
|
|
"\n",
|
|
" @value.setter\n",
|
|
" def value(self, v):\n",
|
|
" if not(self._is_locked):\n",
|
|
" self._value = v\n",
|
|
" else:\n",
|
|
" raise ValueError(f'Failed to set value, item is locked: {str(self.__repr__)}')\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 155,
|
|
"id": "6fd6a46c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class Current_Previous_Value:\n",
|
|
" def __init__(self, value: Any = None, previous_value: Any = None):\n",
|
|
" self._value: Any = value\n",
|
|
" self._previous_value: Any = previous_value\n",
|
|
"\n",
|
|
" def __repr__(self):\n",
|
|
" return str((self._value, self._previous_value))\n",
|
|
"\n",
|
|
" def __len__(self):\n",
|
|
" return len((self._value, self._previous_value))\n",
|
|
"\n",
|
|
" def __getitem__(self, index):\n",
|
|
" return (self._value, self._previous_value)[index]\n",
|
|
"\n",
|
|
" def __str__(self):\n",
|
|
" return str(self._value)\n",
|
|
"\n",
|
|
" @property\n",
|
|
" def value(self):\n",
|
|
" return self._value\n",
|
|
"\n",
|
|
" @property\n",
|
|
" def previous_value(self):\n",
|
|
" return self._previous_value\n",
|
|
"\n",
|
|
" @value.setter\n",
|
|
" def value(self, v):\n",
|
|
" self._previous_value = self._value\n",
|
|
" self._value = v\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 156,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"vo = Current_Previous_Value()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 163,
|
|
"id": "b557d932",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"vo.value = 1\n",
|
|
"vo.value = 2"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ef1d4ce0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 131,
|
|
"id": "04efe6cc",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"v = 1"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 132,
|
|
"id": "36b56800",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"1"
|
|
]
|
|
},
|
|
"execution_count": 132,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"v"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 133,
|
|
"id": "e24ff466",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"v = 2"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 134,
|
|
"id": "b5ee5afa",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"2"
|
|
]
|
|
},
|
|
"execution_count": 134,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"v"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "74051e1d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def test():\n",
|
|
" return False"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 128,
|
|
"id": "38ee912d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"v = Locked_Value('locked', unlock_func=test)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 129,
|
|
"id": "bb703d87",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "ValueError",
|
|
"evalue": "Failed to set value, item is locked: <bound method Locked_Value.__repr__ of ('locked', True, <function test at 0x76725ff485e0>)>",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
|
"\u001b[31mValueError\u001b[39m Traceback (most recent call last)",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[129]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m v.unlock().value = \u001b[33m'unlocked'\u001b[39m\n",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[124]\u001b[39m\u001b[32m, line 41\u001b[39m, in \u001b[36mLocked_Value.value\u001b[39m\u001b[34m(self, v)\u001b[39m\n\u001b[32m 37\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m value(self, v):\n\u001b[32m 38\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28;01mnot\u001b[39;00m(self._is_locked):\n\u001b[32m 39\u001b[39m self._value = v\n\u001b[32m 40\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m41\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ValueError(f'Failed to set value, item is locked: {str(self.__repr__)}')\n",
|
|
"\u001b[31mValueError\u001b[39m: Failed to set value, item is locked: <bound method Locked_Value.__repr__ of ('locked', True, <function test at 0x76725ff485e0>)>"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"v.unlock().value = 'unlocked'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 123,
|
|
"id": "76c44d97",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"('locked', True, <function test at 0x767268132520>)"
|
|
]
|
|
},
|
|
"execution_count": 123,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"v"
|
|
]
|
|
},
|
|
{
|
|
"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": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 62,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"lv = Locked_Value(initial_value=999)\n",
|
|
"# lv.unlock()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 65,
|
|
"id": "76e21865",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"2"
|
|
]
|
|
},
|
|
"execution_count": 65,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"len(lv)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"id": "10258f5b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(999, False)"
|
|
]
|
|
},
|
|
"execution_count": 32,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"lv"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9270dd8d",
|
|
"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,
|
|
"id": "a938b2e0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "39667bd8",
|
|
"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
|
|
}
|