diff --git a/algo.ipynb b/algo.ipynb index b00ebe6..1b96ca9 100644 --- a/algo.ipynb +++ b/algo.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, + "execution_count": 17, "id": "d1eed397", "metadata": {}, "outputs": [], @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "id": "c6151613", "metadata": {}, "outputs": [], @@ -32,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "d83c61e5", "metadata": {}, "outputs": [ @@ -42,7 +42,7 @@ "1" ] }, - "execution_count": 42, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 19, "id": "7e448690", "metadata": {}, "outputs": [], @@ -123,25 +123,85 @@ }, { "cell_type": "code", - "execution_count": 6, + "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': 1777965341650,\n", - " 'timestamp_msg': 1777965341629,\n", - " 'timestamp_transaction': 1777965341600,\n", - " 'orderbook_update_id': 459659132993,\n", - " 'symbol': '4USDT',\n", - " 'best_bid_px': '0.0176320',\n", - " 'best_bid_qty': '8160',\n", - " 'best_ask_px': '0.0177000',\n", - " 'best_ask_qty': '388'}" + "{'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": 6, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -2157,7 +2217,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 35, "id": "b417adad", "metadata": {}, "outputs": [], @@ -2169,17 +2229,17 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 36, "id": "ba98754e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Perpetual_Exchange(lh_asset='WLFI', rh_asset='USDT', symbol='WLFIUSDT', symbol_asset_separator='', mult=25, initial_funding_rate=0.00087322, min_price=0.0001, min_order_size=1.0)" + "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": 16, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -2190,17 +2250,17 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 37, "id": "fa5a8e85", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Perpetual_Exchange(lh_asset='WLFI', rh_asset='USD', symbol='WLFI-USD', symbol_asset_separator='-', mult=10, initial_funding_rate=4e-06, min_price=1e-05, min_order_size=100.0)" + "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": 17, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -2211,11 +2271,442 @@ }, { "cell_type": "code", - "execution_count": null, + "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": [] + "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", diff --git a/algo_config.json b/algo_config.json index 6e9f0d8..f9ff408 100644 --- a/algo_config.json +++ b/algo_config.json @@ -1,5 +1,5 @@ { - "Updated_Timestamp": 1778048640336, + "Updated_Timestamp": 1778095014766, "Config": { "Loop_Sleep_Sec": 0.0, "Max_Order_Over_Notional_Ratio": 1.05, diff --git a/engine_best_funding_rate.py b/engine_best_funding_rate.py index da1b933..e21c50c 100644 --- a/engine_best_funding_rate.py +++ b/engine_best_funding_rate.py @@ -229,6 +229,7 @@ async def loop() -> None: rh_asset = df_best_fr_rate['rh_asset_ast'].iloc[0], symbol_asset_separator = '', initial_funding_rate=float(df_best_fr_rate['funding_rate_ast'].iloc[0]), + fund_rate_at_same_time=bool(df_best_fr_rate['next_funding_at_same_time'].iloc[0]), min_price=float(df_best_fr_rate['min_price_ast'].iloc[0]), min_order_size=float(df_best_fr_rate['min_order_size_ast'].iloc[0]), min_lot_size=float(df_best_fr_rate['min_lot_size_ast'].iloc[0]), @@ -242,6 +243,7 @@ async def loop() -> None: rh_asset = df_best_fr_rate['rh_asset_ext'].iloc[0], symbol_asset_separator = '-', initial_funding_rate=float(df_best_fr_rate['funding_rate_ext'].iloc[0]), + fund_rate_at_same_time=bool(df_best_fr_rate['next_funding_at_same_time'].iloc[0]), min_price=float(df_best_fr_rate['min_price_ext'].iloc[0]), min_order_size=float(df_best_fr_rate['min_order_size_ext'].iloc[0]), min_lot_size=float(df_best_fr_rate['min_lot_size_ext'].iloc[0]), @@ -258,7 +260,7 @@ async def loop() -> None: master_data = df_best_fr_rate[ ['symbol_ast','max_leverage_ast','lh_asset_ast','rh_asset_ast','funding_rate_ast','min_price_ast','min_order_size_ast','min_lot_size_ast','min_notional_ast','buy_ratio_ast', - 'symbol_ext','max_leverage_ext','lh_asset_ext','rh_asset_ext','funding_rate_ext','min_price_ext','min_order_size_ext','min_lot_size_ext','min_notional_ext','buy_ratio_ext', 'buy_ratio_std'] + 'symbol_ext','max_leverage_ext','lh_asset_ext','rh_asset_ext','funding_rate_ext','min_price_ext','min_order_size_ext','min_lot_size_ext','min_notional_ext','buy_ratio_ext', 'buy_ratio_std','next_funding_at_same_time'] ].to_json(orient='records') VAL_KEY.set(name='fr_engine_best_fund_rate_master', value=str(master_data)) diff --git a/main.py b/main.py index a04f5a5..7e2078c 100644 --- a/main.py +++ b/main.py @@ -39,6 +39,7 @@ LOG_FILEPATH: str = f'{os.getenv(key="LOGS_PATH")}/Fund_Rate_Algo.log' ### Algo Config ### Config: structs.Algo_Config +Algo_Status: structs.Algo_Status ### Exchanges ### Aster: structs.Perpetual_Exchange @@ -57,6 +58,12 @@ Flags = structs.Flags() ### Algo ### +async def output_algo_status(status: str) -> None: + global Algo_Status + + Algo_Status.status = status + VAL_KEY.set('algo_status', json.dumps(Algo_Status.model_dump())) + def create_exchange_objs_from_dict(exchanges_dict: dict) -> tuple[structs.Perpetual_Exchange, structs.Perpetual_Exchange]: Aster = structs.Perpetual_Exchange( mult = int(exchanges_dict['max_leverage_ast']), @@ -64,6 +71,7 @@ def create_exchange_objs_from_dict(exchanges_dict: dict) -> tuple[structs.Perpet rh_asset = exchanges_dict['rh_asset_ast'], symbol_asset_separator = '', initial_funding_rate=float(exchanges_dict['funding_rate_ast']), + fund_rate_at_same_time=bool(exchanges_dict['next_funding_at_same_time']), min_price=float(exchanges_dict['min_price_ast']), min_order_size=float(exchanges_dict['min_order_size_ast']), min_lot_size=float(exchanges_dict['min_lot_size_ast']), @@ -77,6 +85,7 @@ def create_exchange_objs_from_dict(exchanges_dict: dict) -> tuple[structs.Perpet rh_asset = exchanges_dict['rh_asset_ext'], symbol_asset_separator = '-', initial_funding_rate=float(exchanges_dict['funding_rate_ext']), + fund_rate_at_same_time=bool(exchanges_dict['next_funding_at_same_time']), min_price=float(exchanges_dict['min_price_ext']), min_order_size=float(exchanges_dict['min_order_size_ext']), min_lot_size=float(exchanges_dict['min_lot_size_ext']), @@ -102,6 +111,10 @@ async def symbol_switch(best_symbol_by_exchange_aster: structs.Perpetual_Exchang logging.info('Balances Flattened - Updating to Trade New Symbols:') logging.info(f' ASTER.symbol -> {best_symbol_by_exchange_aster.symbol}') logging.info(f' EXTEND.symbol -> {best_symbol_by_exchange_extend.symbol}') + + await aster_cancel_all_orders() + await extend_cancel_all_orders() + Config.Overrides.Flatten_Open_Positions_Opportunistic = False if Open_Symbols: logging.info(f'OPEN SYMBOLS: {Open_Symbols}') @@ -122,9 +135,9 @@ async def symbol_switch(best_symbol_by_exchange_aster: structs.Perpetual_Exchang VAL_KEY.set(name='fr_algo_working_symbol', value=json.dumps(obj={'ASTER': asdict(obj=Aster), 'EXTEND': asdict(obj=Extend)})) def calc_fr_minutes_remaining_factor( - min_start_procedure: int = 30, - min_to_end_procedure: int = 7, - factor_exp_pct: float = 0.50 + min_start_procedure: int = 15, + min_to_end_procedure: int = 15, + factor_exp_pct: float = 0.25 ): factors = [np.float64(0.00)] for x in range(min_start_procedure+1,61-min_to_end_procedure): @@ -229,24 +242,38 @@ def signal_alpha_over_taker( funding_rate_exch: str, funding_rate_side: str, funding_rate: Decimal = Decimal('0.00'), + funding_rate_switch: Decimal = Decimal('0.00'), taker_fee: Decimal = Decimal(str(0.00025)), alpha_hurdle_adj: Decimal = Decimal('0.00'), ) -> Signal: - - if funding_rate_exch == 'ASTER': - if funding_rate_side == 'BUY': - aster_buy_fund_rate_return = funding_rate*-1 - extend_buy_fund_rate_return = funding_rate - else: - aster_buy_fund_rate_return = funding_rate - extend_buy_fund_rate_return = funding_rate*-1 + + if Config.Overrides.Flatten_Open_Positions_Opportunistic: + if Decimal(str(Aster.notional_position)) > 0: + aster_buy_fund_rate_return = abs(funding_rate_switch) * -1 + extend_buy_fund_rate_return = abs(funding_rate_switch) + # funding_rate_exch = 'EXTEND' + # funding_rate_side = 'BUY' + else: # Decimal(str(Aster.notional_position)) < 0: + aster_buy_fund_rate_return = abs(funding_rate_switch) + extend_buy_fund_rate_return = abs(funding_rate_switch) * -1 + # funding_rate_exch = 'ASTER' + # funding_rate_side = 'BUY' else: - if funding_rate_side == 'BUY': - aster_buy_fund_rate_return = funding_rate - extend_buy_fund_rate_return = funding_rate*-1 - else: - aster_buy_fund_rate_return = funding_rate*-1 - extend_buy_fund_rate_return = funding_rate + if funding_rate_exch == 'ASTER': + if funding_rate_side == 'BUY': + aster_buy_fund_rate_return = abs(funding_rate) + extend_buy_fund_rate_return = abs(funding_rate) * -1 + else: + aster_buy_fund_rate_return = abs(funding_rate) * -1 + extend_buy_fund_rate_return = abs(funding_rate) + else: # funding_rate_exch == 'EXTEND': + if funding_rate_side == 'BUY': + aster_buy_fund_rate_return = abs(funding_rate) * -1 + extend_buy_fund_rate_return = abs(funding_rate) + else: + aster_buy_fund_rate_return = abs(funding_rate) + extend_buy_fund_rate_return = abs(funding_rate) * -1 + aster_mid_px: Decimal = ( Decimal(str(aster_ticker_dict['best_ask_px'])) + Decimal(str(aster_ticker_dict['best_bid_px'])) ) / 2 extend_mid_px: Decimal = ( Decimal(str(extend_ticker_dict['best_ask_px'])) + Decimal(str(extend_ticker_dict['best_bid_px'])) ) / 2 @@ -257,9 +284,19 @@ def signal_alpha_over_taker( aster_buy_ratio_min_taker_hurdle = ( aster_buy_ratio + aster_buy_fund_rate_return ) - taker_fee - alpha_hurdle_adj extend_buy_ratio_min_taker_hurdle = ( extend_buy_ratio + extend_buy_fund_rate_return ) - taker_fee - alpha_hurdle_adj - aster_buy_expected_alpha: Decimal = ( aster_buy_ratio_min_taker_hurdle - Decimal(str(Aster.buy_ratio)) ).quantize(Decimal('0.0001'), rounding='ROUND_DOWN') # Decimal Price % Diff (x Qty = Alpha $) - extend_buy_expected_alpha: Decimal = ( extend_buy_ratio_min_taker_hurdle - Decimal(str(Extend.buy_ratio)) ).quantize(Decimal('0.0001'), rounding='ROUND_DOWN') # Decimal Price % Diff (x Qty = Alpha $) + aster_buy_expected_alpha: Decimal = ( aster_buy_ratio_min_taker_hurdle - Decimal(str(Aster.buy_ratio)) ).quantize(Decimal('0.000001'), rounding='ROUND_DOWN') # Decimal Price % Diff (x Qty = Alpha $) + extend_buy_expected_alpha: Decimal = ( extend_buy_ratio_min_taker_hurdle - Decimal(str(Extend.buy_ratio)) ).quantize(Decimal('0.000001'), rounding='ROUND_DOWN') # Decimal Price % Diff (x Qty = Alpha $) + # logging.info(f'aster_buy_ratio_min_taker_hurdle: ( {aster_buy_ratio} - {aster_buy_fund_rate_return} ) - {taker_fee} - {alpha_hurdle_adj} = {aster_buy_ratio_min_taker_hurdle}') + # logging.info(f'extend_buy_ratio_min_taker_hurdle: ( {extend_buy_ratio} - {extend_buy_fund_rate_return} ) - {taker_fee} - {alpha_hurdle_adj} = {extend_buy_ratio_min_taker_hurdle}') + # logging.info(f'aster_buy_expected_alpha: {aster_buy_ratio_min_taker_hurdle} - {Decimal(str(Aster.buy_ratio))} = {aster_buy_expected_alpha}') + # logging.info(f'extend_buy_expected_alpha: {extend_buy_ratio_min_taker_hurdle} - {Decimal(str(Extend.buy_ratio))} = {extend_buy_expected_alpha}') + + # aster_buy_ratio_min_taker_hurdle : ( 0.000886878630659394261895260 + 0.000037000000000000005 ) - 0.00025 - 0.0 = 0.000673878630659394266895260 + # extend_buy_ratio_min_taker_hurdle : ( -0.000886878630659394261895260 + -0.000037000000000000005 ) - 0.00025 - 0.0 = -0.001173878630659394266895260 + # aster_buy_expected_alpha : 0.000673878630659394266895260 - 0.0014628375 = -0.0007 + # extend_buy_expected_alpha : -0.001173878630659394266895260 - -0.0014628375 = 0.0002 + if aster_buy_expected_alpha > 0: signal: bool = True exchange: str = 'ASTER' @@ -523,9 +560,11 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open local_open_orders.pop(idx) # await get_aster_collateral() if exch=='ASTER': + await aster_cancel_all_orders() await get_aster_notional_position() Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000 else: + await extend_cancel_all_orders() await get_extend_notional() utils.send_tg_alert(f'FR_ALGO - {exch} FILLED ({order_id})') else: @@ -772,11 +811,13 @@ async def kill_algo(): await aster_cancel_all_orders() await extend_cancel_all_orders() logging.info('ALGO KILL FLAG ACTIVATED; CANCELLING OPEN ORDERS AND SHUTTING DOWN') + await output_algo_status('STOPPED') raise ValueError('KILL FLAG ACTIVATED') ### ALGO LOOP ### async def run_algo(): global Config + global Algo_Status global Aster global Extend @@ -846,18 +887,18 @@ async def run_algo(): min_between_fundings = round((abs(aster_fund_rate_time - extend_fund_rate_time) / 1000 / 60)) next_funding_at_same_time = min_between_fundings < 5 - def calc_next_net_fund_rate(next_funding_at_same_time: bool) -> tuple[float, str, str]: + def calc_next_net_fund_rate(next_funding_at_same_time: bool, fund_rate_ast: float, fund_rate_ext: float) -> tuple[float, str, str]: if next_funding_at_same_time: - net_fr = max([aster_fund_rate, extend_fund_rate]) - min([aster_fund_rate, extend_fund_rate]) - fr_best_exch = 'ASTER' if max([abs(aster_fund_rate), abs(extend_fund_rate)]) == abs(aster_fund_rate) else 'EXTEND' + net_fr = max([fund_rate_ast, fund_rate_ext]) - min([fund_rate_ast, fund_rate_ext]) + fr_best_exch = 'ASTER' if max([abs(fund_rate_ast), abs(fund_rate_ext)]) == abs(fund_rate_ast) else 'EXTEND' fr_best_side = 'BUY' if net_fr < 0 else 'SELL' return net_fr, fr_best_exch, fr_best_side else: fr_best_exch = 'EXTEND' - fr_best_side = 'BUY' if extend_fund_rate < 0 else 'SELL' - return extend_fund_rate, fr_best_exch, fr_best_side + fr_best_side = 'BUY' if fund_rate_ext < 0 else 'SELL' + return fund_rate_ext, fr_best_exch, fr_best_side - next_net_funding_rate, fr_best_exch, fr_best_side = calc_next_net_fund_rate(next_funding_at_same_time) + next_net_funding_rate, fr_best_exch, fr_best_side = calc_next_net_fund_rate(next_funding_at_same_time, fund_rate_ast=aster_fund_rate, fund_rate_ext=extend_fund_rate) Flags.NET_FUNDING_IS_ZERO = ( next_net_funding_rate >= ( (Config.Config.Min_Fund_Rate_Pct_To_Trade*-1) / 100) ) and ( next_net_funding_rate <= ( Config.Config.Min_Fund_Rate_Pct_To_Trade / 100 ) ) # Tickers @@ -910,6 +951,11 @@ async def run_algo(): ### Decisions ### fr_factor: Decimal = get_fr_factor_by_minute(time_to_funding_minutes, Funding_Rates_Min_Remaining_Factor_Pcts) funding_rate_factored = Decimal(str(next_net_funding_rate)) * fr_factor + + funding_rate_switch_net, _, _ = calc_next_net_fund_rate(best_symbol_by_exchange_aster.fund_rate_at_same_time, fund_rate_ast=float(best_symbol_by_exchange_aster.initial_funding_rate), fund_rate_ext=float(best_symbol_by_exchange_extend.initial_funding_rate)) + funding_rate_switch_net_factored = Decimal(str(funding_rate_switch_net)) * fr_factor + # funding_rate_switch_net_factored = Decimal(str(funding_rate_switch_net)) * Decimal('15') + signal: Signal = signal_alpha_over_taker( Aster=Aster, Extend=Extend, @@ -918,8 +964,10 @@ async def run_algo(): funding_rate_exch=fr_best_exch, funding_rate_side=fr_best_side, funding_rate=funding_rate_factored, + funding_rate_switch=funding_rate_switch_net_factored, alpha_hurdle_adj=Decimal(str(Config.Config.Min_Fund_Rate_Pct_To_Trade)), ) + Algo_Status.expected_alpha = float(signal.expected_alpha) if signal.signal: ### True signal, standard target alpha_target_notional = Decimal(str(Config.Config.Max_Target_Notional)) @@ -930,7 +978,6 @@ async def run_algo(): else: alpha_target_notional = Decimal(str(Aster.notional_position*-1)) - ### Apply Overrides ### if signal.exchange == 'ASTER': aster_tgt = alpha_target_notional @@ -969,7 +1016,8 @@ async def run_algo(): OUT(f''' FLIP SIDES FOR TESTING?: {Config.Overrides.Flip_Side_For_Testing}; ASTER ORDER ENABLED? {Config.Overrides.Allow_Ordering_Aster}; EXTEND ORDER ENABLED? {Config.Overrides.Allow_Ordering_Extend} - MKT : Aster: {Aster.symbol:<10} (best: {best_symbol_by_exchange_aster.symbol}) | Extend: {Extend.symbol:<10} (best: {best_symbol_by_exchange_extend.symbol}) + MKT : Aster: {Aster.symbol:<10} (best: {best_symbol_by_exchange_aster.symbol}) | Extend: {Extend.symbol:<10} (best: {best_symbol_by_exchange_extend.symbol}) + FR SWITCH : {funding_rate_switch_net:.6%} [{funding_rate_switch_net*10_000:.2f}bps] [{funding_rate_switch_net*1_000_000:.0f}pips] {pd.to_datetime(aster_fund_rate_time, unit='ms')} ({(pd.to_datetime(aster_fund_rate_time, unit='ms')-datetime.now()):}) | {pd.to_datetime(extend_fund_rate_time, unit='ms')} ({(pd.to_datetime(extend_fund_rate_time, unit='ms')-datetime.now()):}) ASTER: {aster_fund_rate:.6%} [{aster_fund_rate*10_000:.2f}bps] [{aster_fund_rate*1_000_000:.0f}pips] | EXTEND: {extend_fund_rate:.6%} [{extend_fund_rate*10_000:.2f}bps] [{extend_fund_rate*1_000_000:.0f}pips] @@ -982,7 +1030,7 @@ async def run_algo(): ALPHA SIDE : {signal.side:<5} at {signal.exchange} - ALPHA ALPHA : {signal.expected_alpha: .4f} [{signal.expected_alpha*100:.2f}bps] [{signal.expected_alpha*10_000:.2f}pips]; Current {signal.current_ratio:.4f} [{signal.current_ratio*10_000:.2f}scl] {">" if signal.side=='BUY' else "<"} Model {signal.model_ratio:.4f} [{signal.model_ratio*10_000:.2f}scl] + ALPHA ALPHA : {signal.expected_alpha: .6f} [{signal.expected_alpha*100:.2f}bps] [{signal.expected_alpha*10_000:.2f}pips]; Current {signal.current_ratio:.6f} [{signal.current_ratio*10_000:.2f}scl] {">" if signal.side=='BUY' else "<"} Model {signal.model_ratio:.6f} [{signal.model_ratio*10_000:.2f}scl] ALPHA St.Dev: Buy Ratio Std: {Aster.buy_ratio_std:.4%} *** ALPHA SIGNAL: {signal.signal} *** @@ -1131,6 +1179,9 @@ async def run_algo(): cxl_prev_order_id=open_order_id ) + ### Output Algo Status ### + await output_algo_status('WORKING') + ### CHECK TIME TO FUNDING AND WHETHER TO BE ACTIVE ### if ( time_to_funding_ms > min_time_to_funding ) and (not Aster_Open_Orders) and (not Extend_Open_Orders): logging.info(f'Outside action window (minutes) and no active order (sleeping for 5 sec): {pd.to_datetime(time_to_funding_ms, unit='ms').minute} > {pd.to_datetime(min_time_to_funding, unit='ms').minute}') @@ -1149,11 +1200,13 @@ async def run_algo(): time.sleep(Config.Config.Loop_Sleep_Sec) except KeyboardInterrupt: logging.info('CANCELLING OPEN ORDERS') + await output_algo_status('STOPPING') await kill_algo() except Exception as e: logging.error(traceback.format_exc()) logging.critical(f'*** ALGO ENGINE CRASHED: {e}') logging.info('CANCELLING OPEN ORDERS') + await output_algo_status('STOPPING') utils.send_tg_alert(f'FR_ALGO_CRASHED: {str(e)}') await kill_algo() @@ -1163,12 +1216,12 @@ async def main(): global VAL_KEY global CON global Config + global Algo_Status global Aster global Extend global Open_Symbols global Funding_Rates_Min_Remaining_Factor_Pcts - _, EXTEND_CLIENT = await extend_auth.create_auth_account_and_trading_client() VAL_KEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True) engine = create_async_engine('mysql+asyncmy://root:pwd@localhost/fund_rate') @@ -1210,6 +1263,12 @@ async def main(): factor_exp_pct = 0.50 ) + Algo_Status = structs.Algo_Status( + last_update_ts_ms = int(round(datetime.now().timestamp()*1000, 2)), + status = 'WORKING', + expected_alpha = 0.00, + ) + async with engine.connect() as CON: ### ASTER SETUP ### # await get_aster_collateral() diff --git a/modules/structs.py b/modules/structs.py index bb29db0..37ab3d7 100644 --- a/modules/structs.py +++ b/modules/structs.py @@ -89,6 +89,11 @@ class Current_Previous_Value: self._value = v +class Algo_Status(BaseModel): + last_update_ts_ms: int + status: str # 'WORKING' | 'STOPPED' + expected_alpha: float + @@ -253,6 +258,7 @@ class Perpetual_Exchange: symbol_asset_separator: str = '' mult: int initial_funding_rate: float = 0 + fund_rate_at_same_time: bool = False min_price: float = 0 min_order_size: float = 0 min_lot_size: float = 0 diff --git a/ng.py b/ng.py index 8c4f358..792ac16 100644 --- a/ng.py +++ b/ng.py @@ -6,19 +6,12 @@ import json # import time # import re import valkey -# import asyncio +import asyncio # import datetime as dt # from random import random # from nicegui_modules import data # from nicegui_modules import ui_components -# from glide import GlideClient, NodeAddress, GlideClientConfiguration - -LISTENING_CLIENT = None -LH_PAIR = 'BTC' -RH_PAIR = 'USD' - -DEFAULT_TO_DARKMODE: bool = True ALLOW_BODY_SCROLL: bool = True LOOKBACK: int = 60 LOOKBACK_RT_TV_MAX_POINTS: int = 3000 @@ -26,7 +19,7 @@ REFRESH_INTERVAL_SEC: float = 10 REFRESH_INTERVAL_RT_SEC: float = 1/30 ENGINE = create_engine('mysql+pymysql://root:pwd@localhost/fund_rate') -VALKEY_R = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True) +VALKEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True) ### Utils ### def update_body_scroll(e=None, bool_override=False): @@ -43,24 +36,26 @@ def update_body_scroll(e=None, bool_override=False): ### Callbacks ### async def update_tv(): - series_update = json.loads(VALKEY_R.get('poly_rtds_cl_btcusd')) # ty:ignore[invalid-argument-type] - series_update_b = json.loads(VALKEY_R.get('poly_binance_btcusd')) # ty:ignore[invalid-argument-type] - series_update_c = json.loads(VALKEY_R.get('poly_5min_btcusd')) # ty:ignore[invalid-argument-type] - timestamp = round( ( series_update['timestamp_arrival'] / 1000 ) , 2) - timestamp_b = round( ( series_update_b['timestamp_arrival'] / 1000 ) , 2) - timestamp_c = round( ( series_update_c['timestamp_arrival'] / 1000 ) , 2) - value = float(series_update['value']) - value_b = float(series_update_b['value']) - value_c = float(series_update_c['price']) + series_update_aster_tob = json.loads(VALKEY.get('fut_ticker_aster')) # ty:ignore[invalid-argument-type] + series_update_extend_tob = json.loads(VALKEY.get('fut_ticker_extended')) # ty:ignore[invalid-argument-type] + series_update_algo_status = json.loads(VALKEY.get('algo_status')) # ty:ignore[invalid-argument-type] + + timestamp_aster_tob = round( ( series_update_aster_tob['timestamp_arrival'] / 1000 ) , 2) + timestamp_extend_tob = round( ( series_update_extend_tob['timestamp_arrival'] / 1000 ) , 2) + timestamp_algo_status = round( ( series_update_algo_status['timestamp_arrival'] / 1000 ) , 2) + + value_aster_tob = ( float(series_update_aster_tob['best_ask_px']) + float(series_update_aster_tob['best_bid_px']) ) / 2 + value_extend_tob = ( float(series_update_extend_tob['best_ask_px']) + float(series_update_extend_tob['best_bid_px']) ) / 2 + value_algo_expected_alpha = float(series_update_algo_status['price']) data_dict = { - 'timestamp': timestamp, - 'timestamp_b': timestamp_b, - 'timestamp_c': timestamp_c, - 'value': value, - 'value_b': value_b, - 'value_c': value_c, - 'target': series_update_c['target_price'], + 'timestamp': timestamp_aster_tob, + 'timestamp_b': timestamp_extend_tob, + 'timestamp_c': timestamp_algo_status, + 'value': value_aster_tob, + 'value_b': value_extend_tob, + 'value_c': value_algo_expected_alpha, + 'target': series_update_algo_status['target_price'], 'LOOKBACK_RT_TV_MAX_POINTS': LOOKBACK_RT_TV_MAX_POINTS, }