diff --git a/algo.ipynb b/algo.ipynb index 1b96ca9..e4bd3e9 100644 --- a/algo.ipynb +++ b/algo.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 17, + "execution_count": 7, "id": "d1eed397", "metadata": {}, "outputs": [], @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 8, "id": "c6151613", "metadata": {}, "outputs": [], @@ -32,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 9, "id": "d83c61e5", "metadata": {}, "outputs": [ @@ -42,7 +42,7 @@ "1" ] }, - "execution_count": 16, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -638,6 +638,34 @@ "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, @@ -668,139 +696,35 @@ }, { "cell_type": "code", - "execution_count": 170, + "execution_count": 7, "id": "5f7535df", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[{'symbol_ast': 'BTCUSDT',\n", - " 'max_leverage_ast': 150,\n", - " 'lh_asset_ast': 'BTC',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': -7.975e-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", - " 'symbol_ext': 'BTC-USD',\n", - " 'max_leverage_ext': 50,\n", - " 'lh_asset_ext': 'BTC',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': -3e-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", - " {'symbol_ast': 'ETHUSDT',\n", + "[{'symbol_ast': 'ETHUSDT',\n", " 'max_leverage_ast': 150,\n", " 'lh_asset_ast': 'ETH',\n", " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': -9.77e-06,\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': -1.3e-05,\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", - " {'symbol_ast': 'SOLUSDT',\n", - " 'max_leverage_ast': 100,\n", - " 'lh_asset_ast': 'SOL',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 2.399e-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", - " 'symbol_ext': 'SOL-USD',\n", - " 'max_leverage_ext': 50,\n", - " 'lh_asset_ext': 'SOL',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': -1.2e-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", - " {'symbol_ast': 'DOGEUSDT',\n", - " 'max_leverage_ast': 75,\n", - " 'lh_asset_ast': 'DOGE',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 9.699e-05,\n", - " 'min_price_ast': '0.002440',\n", - " 'min_order_size_ast': '1',\n", - " 'min_lot_size_ast': '1',\n", - " 'min_notional_ast': '5',\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", - " {'symbol_ast': 'BNBUSDT',\n", - " 'max_leverage_ast': 100,\n", - " 'lh_asset_ast': 'BNB',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 0.00011803,\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", - " '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", - " {'symbol_ast': 'XRPUSDT',\n", - " 'max_leverage_ast': 100,\n", - " 'lh_asset_ast': 'XRP',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 5.373e-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", - " 'symbol_ext': 'XRP-USD',\n", - " 'max_leverage_ext': 50,\n", - " 'lh_asset_ext': 'XRP',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': 6e-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", - " {'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", - " '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", + " '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", @@ -810,6 +734,7 @@ " '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", @@ -818,97 +743,142 @@ " '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", - " {'symbol_ast': 'ENAUSDT',\n", - " 'max_leverage_ast': 25,\n", - " 'lh_asset_ast': 'ENA',\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': 5e-05,\n", - " 'min_price_ast': '0.0000100',\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", - " 'symbol_ext': 'ENA-USD',\n", - " 'max_leverage_ext': 50,\n", - " 'lh_asset_ext': 'ENA',\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.00001',\n", - " 'min_order_size_ext': '100',\n", - " 'min_lot_size_ext': '10',\n", - " 'min_notional_ext': 0.0},\n", - " {'symbol_ast': 'AAVEUSDT',\n", - " 'max_leverage_ast': 10,\n", - " 'lh_asset_ast': 'AAVE',\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.0001,\n", - " 'min_price_ast': '4.400',\n", - " 'min_order_size_ast': '0.1',\n", - " 'min_lot_size_ast': '0.1',\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", - " 'symbol_ext': 'AAVE-USD',\n", + " 'buy_ratio_ast': -0.0008859719,\n", + " 'symbol_ext': 'BNB-USD',\n", " 'max_leverage_ext': 50,\n", - " 'lh_asset_ext': 'AAVE',\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", - " {'symbol_ast': 'TRUMPUSDT',\n", - " 'max_leverage_ast': 10,\n", - " 'lh_asset_ast': 'TRUMP',\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': 5e-05,\n", - " 'min_price_ast': '0.00100',\n", - " 'min_order_size_ast': '0.01',\n", - " 'min_lot_size_ast': '0.01',\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", - " 'symbol_ext': 'TRUMP-USD',\n", - " 'max_leverage_ext': 25,\n", - " 'lh_asset_ext': 'TRUMP',\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.001',\n", - " 'min_order_size_ext': '1',\n", - " 'min_lot_size_ext': '1',\n", - " 'min_notional_ext': 0.0},\n", - " {'symbol_ast': 'INITUSDT',\n", - " 'max_leverage_ast': 50,\n", - " 'lh_asset_ast': 'INIT',\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", - " 'symbol_ext': 'INIT-USD',\n", - " 'max_leverage_ext': 5,\n", - " 'lh_asset_ext': 'INIT',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': -1e-06,\n", - " 'min_price_ext': '0.00001',\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", - " {'symbol_ast': 'ZORAUSDT',\n", - " 'max_leverage_ast': 5,\n", - " 'lh_asset_ast': 'ZORA',\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': 5e-05,\n", - " 'min_price_ast': '0.0000100',\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", - " 'symbol_ext': 'ZORA-USD',\n", - " 'max_leverage_ext': 5,\n", - " 'lh_asset_ext': 'ZORA',\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.000001',\n", - " 'min_order_size_ext': '1000',\n", - " 'min_lot_size_ext': '100',\n", - " 'min_notional_ext': 0.0},\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", @@ -918,33 +888,19 @@ " '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", + " '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", - " {'symbol_ast': 'ASTERUSDT',\n", - " 'max_leverage_ast': 75,\n", - " 'lh_asset_ast': 'ASTER',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 5e-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", - " '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", + " '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", @@ -954,6 +910,7 @@ " '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", @@ -962,100 +919,13 @@ " '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", - " {'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", - " 'symbol_ext': '4-USD',\n", - " 'max_leverage_ext': 5,\n", - " 'lh_asset_ext': '4',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': 0.000179,\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", - " {'symbol_ast': 'LITUSDT',\n", - " 'max_leverage_ast': 50,\n", - " 'lh_asset_ast': 'LIT',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 2.475e-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", - " '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", - " {'symbol_ast': 'XMRUSDT',\n", - " 'max_leverage_ast': 50,\n", - " 'lh_asset_ast': 'XMR',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 1.25e-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", - " '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", - " {'symbol_ast': 'XPTUSDT',\n", - " 'max_leverage_ast': 3,\n", - " 'lh_asset_ast': 'XPT',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': 0.0,\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", - " 'symbol_ext': 'XPT-USD',\n", - " 'max_leverage_ext': 5,\n", - " 'lh_asset_ext': 'XPT',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': -3e-06,\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", - " {'symbol_ast': 'CHIPUSDT',\n", - " 'max_leverage_ast': 50,\n", - " 'lh_asset_ast': 'CHIP',\n", - " 'rh_asset_ast': 'USDT',\n", - " 'funding_rate_ast': -2.45e-06,\n", - " 'min_price_ast': '0.0000100',\n", - " 'min_order_size_ast': '1',\n", - " 'min_lot_size_ast': '1',\n", - " 'min_notional_ast': '5',\n", - " 'symbol_ext': 'CHIP-USD',\n", - " 'max_leverage_ext': 5,\n", - " 'lh_asset_ext': 'CHIP',\n", - " 'rh_asset_ext': 'USD',\n", - " 'funding_rate_ext': 1.3e-05,\n", - " 'min_price_ext': '0.000001',\n", - " 'min_order_size_ext': '100',\n", - " 'min_lot_size_ext': '10',\n", - " 'min_notional_ext': 0.0}]" + " '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": 170, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } diff --git a/algo_config.json b/algo_config.json index f9ff408..d967c42 100644 --- a/algo_config.json +++ b/algo_config.json @@ -1,5 +1,5 @@ { - "Updated_Timestamp": 1778095014766, + "Updated_Timestamp": 1778133411421, "Config": { "Loop_Sleep_Sec": 0.0, "Max_Order_Over_Notional_Ratio": 1.05, diff --git a/engine_best_funding_rate.ipynb b/engine_best_funding_rate.ipynb index 93c2fc7..a951b8f 100644 --- a/engine_best_funding_rate.ipynb +++ b/engine_best_funding_rate.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 155, + "execution_count": 1, "id": "0b5ca901", "metadata": {}, "outputs": [], @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 2, "id": "53647b40", "metadata": {}, "outputs": [], @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 3, "id": "1f3b65ee", "metadata": {}, "outputs": [], @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 4, "id": "5176d5b1", "metadata": {}, "outputs": [], @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 5, "id": "e33ec721", "metadata": {}, "outputs": [], @@ -116,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": 6, "id": "62815940", "metadata": {}, "outputs": [], @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": 7, "id": "271a67c1", "metadata": {}, "outputs": [], @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 162, + "execution_count": 8, "id": "1ce2fde4", "metadata": {}, "outputs": [], @@ -167,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": 9, "id": "ff88b413", "metadata": {}, "outputs": [], @@ -187,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 164, + "execution_count": 10, "id": "f5ade993", "metadata": {}, "outputs": [], @@ -199,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 165, + "execution_count": 11, "id": "84bbc5a8", "metadata": {}, "outputs": [], @@ -218,7 +218,7 @@ }, { "cell_type": "code", - "execution_count": 166, + "execution_count": 12, "id": "7bd849e4", "metadata": {}, "outputs": [], @@ -233,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 167, + "execution_count": 14, "id": "86549660", "metadata": {}, "outputs": [], @@ -241,7 +241,7 @@ "import modules.aster_auth as aster_auth\n", "import modules.utils as utils\n", "\n", - "async def get_candles(symbol: str) -> pd.DataFrame:\n", + "async def get_candles(symbol: str, limit: int = 1440) -> pd.DataFrame:\n", " ### Candles for Midpoint Dispersion ###\n", " # Aster\n", " symbol_ast = utils.symbol_to_aster_fmt(symbol)\n", @@ -251,7 +251,7 @@ " \"params\": {\n", " 'symbol': symbol_ast,\n", " 'interval': '1m',\n", - " 'limit':'1440'\n", + " 'limit': str(limit)\n", " }\n", " }\n", " j = await aster_auth.post_authenticated_url(aster_candles)\n", @@ -266,7 +266,7 @@ " symbol_ext = utils.symbol_to_extend_fmt(symbol)\n", " ext_params = {\n", " 'interval':'1m',\n", - " 'limit':1440,\n", + " 'limit':limit,\n", " }\n", " r = json.loads(requests.get(f'https://api.starknet.extended.exchange/api/v1/info/candles/{symbol_ext}/trades', params=ext_params).text)\n", " df_candles_extended = pd.DataFrame(r['data'])\n", @@ -284,7 +284,7 @@ }, { "cell_type": "code", - "execution_count": 168, + "execution_count": 15, "id": "3da1ef8c", "metadata": {}, "outputs": [], @@ -292,7 +292,7 @@ "candles_ratios = []\n", "\n", "for index, row in df_best_fr_rate.iterrows():\n", - " df = await get_candles(symbol=row['symbol_ext'])\n", + " df = await get_candles(symbol=row['symbol_ext'], limit=60)\n", " buy_ratio_ext = float(df['med_ratio_aster_over_extend'].median())\n", " buy_ratio_std = float(df['med_ratio_aster_over_extend'].std())\n", " candles_ratios.append({'symbol_ext':row['symbol_ext'], 'buy_ratio_std': buy_ratio_std, 'buy_ratio_ext':buy_ratio_ext,'buy_ratio_ast':buy_ratio_ext*-1})\n", @@ -302,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 169, + "execution_count": 16, "id": "617bdb3a", "metadata": {}, "outputs": [ @@ -326,77 +326,72 @@ "type": "float" } ], - "ref": "234d26fb-bae0-44d4-b286-7995c40f5493", + "ref": "41f1a58f-087e-48a8-9829-27de7bd3bd44", "rows": [ [ "0", - "-0.001181480884319741", - "-0.003622563394859446" + "0.00047961685177977387", + "0.00010676916506513479" ], [ "1", - "0.00029906773980648005", - "-0.0005162089613875986" + "0.00039197315461914073", + "0.007192868347553283" ], [ "2", - "0.00013074942172808246", - "-0.00015921393804296802" + "0.0002912986303861276", + "0.0005358432541993086" ], [ "3", - "0.0010505163053042832", - "0.0007245691963582157" + "0.0009604511021952256", + "0.0004019230471949964" ], [ "4", - "0.00011580440645486689", - "-0.0014865637507147644" + "0.00030683403068354487", + "0.00012883830792365103" ], [ "5", - "0.00021061518497555998", - "-0.001820204267367842" + "-0.001055302332891861", + "-0.0023480538246184457" ], [ "6", - "0.00021041337278360217", - "0.00016516325752768957" + "7.095469542717225e-05", + "-0.0004262271790863581" ], [ "7", - "0.00476737157079099", - "0.005802562170308834" + "0.00013706284207826158", + "-1.975479362426036e-05" ], [ "8", - "-0.0007417494377083833", - "-0.0027350527894597354" + "0.00016960651288999706", + "-0.00033863867253636215" ], [ "9", - "-9.917334996478733e-05", - "-3.6865000368702106e-05" + "0.0013806103592610697", + "0.002941176470588225" ], [ "10", - "0.00021180831354239427", - "-7.02444506883726e-05" + "-0.0005592593208220142", + "-0.00045253363649400136" ], [ "11", - "9.690676685325528e-05", - "3.815149836938758e-05" - ], - [ - "12", - "1.3323150701682884e-05", - "-0.0004138239160925705" + "-0.0015596592214837668", + "0.006847133757961643" ] ], "shape": { "columns": 2, - "rows": 13 + "rows": 12 } }, "text/html": [ @@ -425,68 +420,63 @@ "
\n", "13 rows × 35 columns
\n", + "12 rows × 35 columns
\n", "" ], "text/plain": [ " symbol_ext symbol_ast daily_volume_ext daily_volume_ast min_price_ext \\\n", - "0 DOGE-USD DOGEUSDT 6.750571e+06 2.321757e+07 0.00001 \n", - "1 LIT-USD LITUSDT 2.522778e+06 7.523452e+05 0.0001 \n", - "2 HYPE-USD HYPEUSDT 5.863991e+07 1.255636e+07 0.001 \n", - "3 BNB-USD BNBUSDT 9.050764e+06 1.487197e+07 0.01 \n", - "4 SOL-USD SOLUSDT 2.257412e+07 6.243654e+07 0.01 \n", - "5 SUI-USD SUIUSDT 5.872095e+06 2.857091e+05 0.0001 \n", - "6 ETH-USD ETHUSDT 6.121374e+07 4.044987e+08 0.1 \n", - "7 4-USD 4USDT 3.209672e+05 3.135862e+05 0.00001 \n", - "8 ASTER-USD ASTERUSDT 3.228248e+05 4.170694e+07 0.00001 \n", - "9 CHIP-USD CHIPUSDT 4.525915e+05 2.374932e+05 0.000001 \n", - "10 XRP-USD XRPUSDT 9.026962e+06 1.613476e+07 0.0001 \n", - "11 BTC-USD BTCUSDT 1.828855e+08 9.794189e+08 1 \n", - "12 ZEC-USD ZECUSDT 6.849535e+06 6.584711e+06 0.001 \n", + "0 LIT-USD LITUSDT 1.377303e+06 9.679359e+05 0.0001 \n", + "1 CHIP-USD CHIPUSDT 2.817108e+05 3.067199e+05 0.000001 \n", + "2 HYPE-USD HYPEUSDT 4.326806e+07 1.038774e+07 0.001 \n", + "3 BNB-USD BNBUSDT 8.459935e+06 3.597783e+07 0.01 \n", + "4 ETH-USD ETHUSDT 1.026497e+08 5.770904e+08 0.1 \n", + "5 DOGE-USD DOGEUSDT 7.132958e+06 4.141854e+07 0.00001 \n", + "6 XRP-USD XRPUSDT 1.056095e+07 1.776935e+07 0.0001 \n", + "7 BTC-USD BTCUSDT 2.331171e+08 1.009997e+09 1 \n", + "8 SOL-USD SOLUSDT 2.213780e+07 9.966792e+07 0.01 \n", + "9 WLFI-USD WLFIUSDT 2.719616e+05 1.499330e+06 0.00001 \n", + "10 ZEC-USD ZECUSDT 8.617919e+06 1.356894e+07 0.001 \n", + "11 4-USD 4USDT 1.821963e+05 1.286953e+05 0.00001 \n", "\n", " min_price_ast min_order_size_ext min_order_size_ast min_lot_size_ext \\\n", - "0 0.002440 100 1 10 \n", - "1 0.0001000 10 1 1 \n", + "0 0.0001000 10 1 1 \n", + "1 0.0000100 100 1 10 \n", "2 0.00100 0.1 0.01 0.01 \n", "3 0.010 0.01 0.01 0.001 \n", - "4 0.4200 0.1 0.01 0.01 \n", - "5 0.000100 10 0.1 1 \n", - "6 0.01 0.01 0.001 0.001 \n", - "7 0.0000010 100 1 10 \n", - "8 0.00010 10 0.01 1 \n", - "9 0.0000100 100 1 10 \n", - "10 0.0143 10 0.1 1 \n", - "11 1 0.0001 0.001 0.00001 \n", - "12 0.0100 0.1 0.001 0.1 \n", + "4 0.01 0.01 0.001 0.001 \n", + "5 0.002440 100 1 10 \n", + "6 0.0143 10 0.1 1 \n", + "7 1 0.0001 0.001 0.00001 \n", + "8 0.4200 0.1 0.01 0.01 \n", + "9 0.0001000 100 1 10 \n", + "10 0.0100 0.1 0.001 0.1 \n", + "11 0.0000010 100 1 10 \n", "\n", " min_lot_size_ast ... last_trade_px_ast hourly_dollars_per_1k \\\n", - "0 1 ... 0.115520 3.24 \n", - "1 1 ... 0.968100 2.01 \n", - "2 0.01 ... 43.959000 1.63 \n", - "3 0.01 ... 635.320000 0.87 \n", - "4 0.01 ... 87.320000 0.87 \n", - "5 0.1 ... 0.987100 0.78 \n", - "6 0.001 ... 2361.690000 0.68 \n", - "7 1 ... 0.013347 0.67 \n", - "8 0.01 ... 0.678200 0.49 \n", - "9 1 ... 0.054250 0.48 \n", - "10 0.1 ... 1.423500 0.27 \n", - "11 0.001 ... 81258.100000 0.22 \n", - "12 0.001 ... 545.900000 0.01 \n", + "0 1 ... 0.936700 1.81 \n", + "1 1 ... 0.052650 1.15 \n", + "2 0.01 ... 42.946000 1.11 \n", + "3 0.01 ... 647.150000 0.87 \n", + "4 0.001 ... 2328.800000 0.82 \n", + "5 1 ... 0.110470 0.78 \n", + "6 0.1 ... 1.407100 0.67 \n", + "7 0.001 ... 80991.400000 0.45 \n", + "8 0.01 ... 88.560000 0.27 \n", + "9 1 ... 0.068200 0.13 \n", + "10 0.001 ... 543.360000 0.01 \n", + "11 1 ... 0.012646 0.00 \n", "\n", " last_trade_ts_ext last_trade_px_ext current_ast_over_ext_ratio \\\n", - "0 1778047363102 0.115940 -0.003623 \n", - "1 1778047669181 0.968600 -0.000516 \n", - "2 1778047650011 43.966000 -0.000159 \n", - "3 1778047650009 634.860000 0.000725 \n", - "4 1778047602027 87.450000 -0.001487 \n", - "5 1778047576123 0.988900 -0.001820 \n", - "6 1778047670911 2361.300000 0.000165 \n", - "7 1778047526553 0.013270 0.005803 \n", - "8 1778047182945 0.680060 -0.002735 \n", - "9 1778047490911 0.054252 -0.000037 \n", - "10 1778047623101 1.423600 -0.000070 \n", - "11 1778047671637 81255.000000 0.000038 \n", - "12 1778047665513 546.126000 -0.000414 \n", + "0 1778133698241 0.936600 0.000107 \n", + "1 1778133309735 0.052274 0.007193 \n", + "2 1778133930025 42.923000 0.000536 \n", + "3 1778133707748 646.890000 0.000402 \n", + "4 1778133918939 2328.500000 0.000129 \n", + "5 1778133750010 0.110730 -0.002348 \n", + "6 1778133915802 1.407700 -0.000426 \n", + "7 1778133936053 80993.000000 -0.000020 \n", + "8 1778133917319 88.590000 -0.000339 \n", + "9 1778133657113 0.068000 0.002941 \n", + "10 1778133929212 543.606000 -0.000453 \n", + "11 1778133456831 0.012560 0.006847 \n", "\n", " last_trade_ts_dt_ast last_trade_ts_dt_ext buy_ratio_std \\\n", - "0 2026-05-06 06:07:47.600 2026-05-06 06:02:43.102 0.001433 \n", - "1 2026-05-06 06:07:21.000 2026-05-06 06:07:49.181 0.002622 \n", - "2 2026-05-06 06:07:47.153 2026-05-06 06:07:30.011 0.001804 \n", - "3 2026-05-06 06:07:47.495 2026-05-06 06:07:30.009 0.002553 \n", - "4 2026-05-06 06:07:47.855 2026-05-06 06:06:42.027 0.000776 \n", - "5 2026-05-06 06:07:46.700 2026-05-06 06:06:16.123 0.004226 \n", - "6 2026-05-06 06:07:48.250 2026-05-06 06:07:50.911 0.000685 \n", - "7 2026-05-06 06:06:17.183 2026-05-06 06:05:26.553 0.024450 \n", - "8 2026-05-06 06:07:48.250 2026-05-06 05:59:42.945 0.001276 \n", - "9 2026-05-06 06:06:17.697 2026-05-06 06:04:50.911 0.041605 \n", - "10 2026-05-06 06:07:45.356 2026-05-06 06:07:03.101 0.004379 \n", - "11 2026-05-06 06:07:46.657 2026-05-06 06:07:51.637 0.000999 \n", - "12 2026-05-06 06:07:46.530 2026-05-06 06:07:45.513 0.003199 \n", + "0 2026-05-07 06:05:11.550 2026-05-07 06:01:38.241 0.000535 \n", + "1 2026-05-07 06:02:49.370 2026-05-07 05:55:09.735 0.001171 \n", + "2 2026-05-07 06:05:36.887 2026-05-07 06:05:30.025 0.000131 \n", + "3 2026-05-07 06:05:37.113 2026-05-07 06:01:47.748 0.000072 \n", + "4 2026-05-07 06:05:36.351 2026-05-07 06:05:18.939 0.000063 \n", + "5 2026-05-07 06:05:35.896 2026-05-07 06:02:30.010 0.000081 \n", + "6 2026-05-07 06:05:35.776 2026-05-07 06:05:15.802 0.000073 \n", + "7 2026-05-07 06:05:36.703 2026-05-07 06:05:36.053 0.000082 \n", + "8 2026-05-07 06:05:36.390 2026-05-07 06:05:17.319 0.000088 \n", + "9 2026-05-07 06:05:09.230 2026-05-07 06:00:57.113 0.000833 \n", + "10 2026-05-07 06:05:35.200 2026-05-07 06:05:29.212 0.000227 \n", + "11 2026-05-07 06:05:01.400 2026-05-07 05:57:36.831 0.004118 \n", "\n", " buy_ratio_ext buy_ratio_ast \n", - "0 -0.001181 0.001181 \n", - "1 0.000299 -0.000299 \n", - "2 0.000131 -0.000131 \n", - "3 0.001051 -0.001051 \n", - "4 0.000116 -0.000116 \n", - "5 0.000211 -0.000211 \n", - "6 0.000210 -0.000210 \n", - "7 0.004767 -0.004767 \n", - "8 -0.000742 0.000742 \n", - "9 -0.000099 0.000099 \n", - "10 0.000212 -0.000212 \n", - "11 0.000097 -0.000097 \n", - "12 0.000013 -0.000013 \n", + "0 0.000480 -0.000480 \n", + "1 0.000392 -0.000392 \n", + "2 0.000291 -0.000291 \n", + "3 0.000960 -0.000960 \n", + "4 0.000307 -0.000307 \n", + "5 -0.001055 0.001055 \n", + "6 0.000071 -0.000071 \n", + "7 0.000137 -0.000137 \n", + "8 0.000170 -0.000170 \n", + "9 0.001381 -0.001381 \n", + "10 -0.000559 0.000559 \n", + "11 -0.001560 0.001560 \n", "\n", - "[13 rows x 35 columns]" + "[12 rows x 35 columns]" ] }, - "execution_count": 170, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -1675,7 +1596,7 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 21, "id": "bbad7d21", "metadata": {}, "outputs": [], @@ -1724,17 +1645,17 @@ }, { "cell_type": "code", - "execution_count": 172, + "execution_count": 22, "id": "799ffa9c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "np.float64(0.00013075388140060262)" + "np.float64(-3.456754155017894e-05)" ] }, - "execution_count": 172, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -1745,17 +1666,17 @@ }, { "cell_type": "code", - "execution_count": 184, + "execution_count": 30, "id": "75ac86aa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "np.float64(0.00015347678748833804)" + "np.float64(0.0002912986303861276)" ] }, - "execution_count": 184, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -1764,6 +1685,14 @@ "df_candles_comb.iloc[-60:]['med_ratio_aster_over_extend'].median()\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "b09eaab0", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, diff --git a/engine_best_funding_rate.py b/engine_best_funding_rate.py index e21c50c..0401888 100644 --- a/engine_best_funding_rate.py +++ b/engine_best_funding_rate.py @@ -32,6 +32,8 @@ LOOP_SLEEP_SEC: int = 5 REFRESH_MKT_INFO_EVERY_SEC: int = 90 REFRESH_MKT_VOLUME_EVERY_SEC: int = 30 +MINUTES_LOOKBACK: int = 60 + ### GLOBALS ### Mkt_Info_Last_Refresh_TS_ms: int = 0 Mkt_Volume_Last_Refresh_TS_ms: int = 0 @@ -116,7 +118,7 @@ def load_extend_current_fr(df_mkt_stats: pd.DataFrame) -> pd.DataFrame: return df -async def get_candles(symbol: str) -> pd.DataFrame: +async def get_candles(symbol: str, limit: int = MINUTES_LOOKBACK) -> pd.DataFrame: ### Candles for Midpoint Dispersion ### # Aster symbol_ast = utils.symbol_to_aster_fmt(symbol) @@ -126,7 +128,7 @@ async def get_candles(symbol: str) -> pd.DataFrame: "params": { 'symbol': symbol_ast, 'interval': '1m', - 'limit':'1440' + 'limit':str(limit) } } j = await aster_auth.post_authenticated_url(aster_candles) @@ -141,7 +143,7 @@ async def get_candles(symbol: str) -> pd.DataFrame: symbol_ext = utils.symbol_to_extend_fmt(symbol) ext_params = { 'interval':'1m', - 'limit':1440, + 'limit': limit, } r = json.loads(requests.get(f'https://api.starknet.extended.exchange/api/v1/info/candles/{symbol_ext}/trades', params=ext_params).text) df_candles_extended = pd.DataFrame(r['data']) @@ -157,7 +159,6 @@ async def get_candles(symbol: str) -> pd.DataFrame: return df_candles_comb - async def loop() -> None: global Mkt_Info_Last_Refresh_TS_ms try: @@ -264,7 +265,7 @@ async def loop() -> None: ].to_json(orient='records') VAL_KEY.set(name='fr_engine_best_fund_rate_master', value=str(master_data)) - print(df_best_fr_rate[['symbol_ext','max_leverage_ext','buy_ratio_ext','net_funding_rate','daily_volume_ast']].head(10)) + print(df_best_fr_rate[['symbol_ext','max_leverage_ext','buy_ratio_ext','net_funding_rate','daily_volume_ast','buy_ratio_ast']].head(10)) logging.info(f'BFR REFRESHED @ {datetime.now()}') time.sleep(LOOP_SLEEP_SEC) continue diff --git a/main.py b/main.py index 7e2078c..d8d54b5 100644 --- a/main.py +++ b/main.py @@ -61,7 +61,9 @@ Flags = structs.Flags() async def output_algo_status(status: str) -> None: global Algo_Status + Algo_Status.last_update_ts_ms = int(round(datetime.now().timestamp()*1000, 2)) 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]: @@ -497,7 +499,7 @@ async def post_extend_order( await kill_algo() ### OPEN ORDERS ### -async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open_orders: list[dict]) -> list[dict]: # exch = 'ASTER' | 'EXTEND' +async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open_orders: list[dict], ws_pos_updates: list[dict]) -> list[dict]: # exch = 'ASTER' | 'EXTEND' global Aster global Extend global Last_Aster_Fill_Time_Ts @@ -550,18 +552,18 @@ async def handle_order_updates(exch: str, local_open_orders: list[dict], ws_open logging.info(f'{exch} ORDER PARTIALLY FILLED: {order_id}') # await get_aster_collateral() if exch=='ASTER': - await get_aster_notional_position() + await get_aster_notional_position(resp=ws_pos_updates) Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000 else: - await get_extend_notional() + await get_extend_notional(resp=ws_pos_updates) utils.send_tg_alert(f'FR_ALGO - {exch} PARTIALLY FILLED ({order_id})') elif order_update_status in ['FILLED']: logging.info(f'{exch} ORDER FILLED: {order_id}') local_open_orders.pop(idx) # await get_aster_collateral() if exch=='ASTER': - await aster_cancel_all_orders() - await get_aster_notional_position() + # await aster_cancel_all_orders() + await get_aster_notional_position(resp=ws_pos_updates) Last_Aster_Fill_Time_Ts = datetime.now().timestamp()*1000 else: await extend_cancel_all_orders() @@ -939,8 +941,8 @@ async def run_algo(): extend_ws_order_updates: list = json.loads(extend_ws_order_updates) if extend_ws_order_updates is not None else [] ### Update Local Open Orders w Changes from WS ### - Aster_Open_Orders = await handle_order_updates(exch='ASTER', local_open_orders=Aster_Open_Orders, ws_open_orders=aster_ws_order_updates) - Extend_Open_Orders = await handle_order_updates(exch='EXTEND', local_open_orders=Extend_Open_Orders, ws_open_orders=extend_ws_order_updates) + Aster_Open_Orders = await handle_order_updates(exch='ASTER', local_open_orders=Aster_Open_Orders, ws_open_orders=aster_ws_order_updates, ws_pos_updates=aster_ws_pos_updates) + Extend_Open_Orders = await handle_order_updates(exch='EXTEND', local_open_orders=Extend_Open_Orders, ws_open_orders=extend_ws_order_updates, ws_pos_updates=extend_ws_pos_updates) ### CHECK NO MORE THAN 1 OPEN ORDER ON EITHER EXCHANGE ### if len(Aster_Open_Orders) > 1 or len(Extend_Open_Orders) > 1: @@ -968,6 +970,8 @@ async def run_algo(): alpha_hurdle_adj=Decimal(str(Config.Config.Min_Fund_Rate_Pct_To_Trade)), ) Algo_Status.expected_alpha = float(signal.expected_alpha) + Algo_Status.model_ratio = float(signal.model_ratio) + Algo_Status.current_ratio = float(signal.current_ratio) if signal.signal: ### True signal, standard target alpha_target_notional = Decimal(str(Config.Config.Max_Target_Notional)) @@ -1267,7 +1271,10 @@ async def main(): last_update_ts_ms = int(round(datetime.now().timestamp()*1000, 2)), status = 'WORKING', expected_alpha = 0.00, + model_ratio = 0.00, + current_ratio = 0.00, ) + await output_algo_status('WORKING') async with engine.connect() as CON: ### ASTER SETUP ### diff --git a/modules/structs.py b/modules/structs.py index 37ab3d7..e1c84e8 100644 --- a/modules/structs.py +++ b/modules/structs.py @@ -93,8 +93,8 @@ class Algo_Status(BaseModel): last_update_ts_ms: int status: str # 'WORKING' | 'STOPPED' expected_alpha: float - - + model_ratio: float + current_ratio: float # @dataclass(kw_only=True) diff --git a/ng.py b/ng.py index 792ac16..e96ae00 100644 --- a/ng.py +++ b/ng.py @@ -7,7 +7,8 @@ import json # import re import valkey import asyncio -# import datetime as dt +from datetime import datetime +from dataclasses import dataclass, field # from random import random # from nicegui_modules import data # from nicegui_modules import ui_components @@ -15,12 +16,100 @@ import asyncio ALLOW_BODY_SCROLL: bool = True LOOKBACK: int = 60 LOOKBACK_RT_TV_MAX_POINTS: int = 3000 -REFRESH_INTERVAL_SEC: float = 10 -REFRESH_INTERVAL_RT_SEC: float = 1/30 +# REFRESH_INTERVAL_SEC: float = 10 +REFRESH_INTERVAL_RT_SEC: float = 1/10 ENGINE = create_engine('mysql+pymysql://root:pwd@localhost/fund_rate') VALKEY = valkey.Valkey(host='localhost', port=6379, db=0, decode_responses=True) + +CHARTS = [ + { + 'type': 'AREA', + 'autoscaleInfoProvider': False, + 'data': [], + 'options': { + 'color': '#94fcdf', + 'priceScaleId': 'right', + 'topColor': '#94fcdf', + 'bottomColor': 'rgba(112, 249, 210, 0.28)', + 'invertFilledArea': True + } + }, + { + 'type': 'AREA', + 'autoscaleInfoProvider': False, + 'data': [], + 'options': { + 'color': '#dd7525', + 'priceScaleId': 'right', + 'topColor': '#94fcdf', + 'bottomColor': 'rgba(249, 167, 112, 0.28)', + 'invertFilledArea': False + }, + }, + { + 'type': 'LINE', + 'autoscaleInfoProvider': [-0.1, 0.1], + 'data': [], + 'options': { + 'color': '#ea0707', + 'priceScaleId': 'left', + }, + }, + { + 'type': 'LINE', + 'autoscaleInfoProvider': False, + 'data': [], + 'options': { + 'color': '#009b12', + 'priceScaleId': 'left', + }, + }, + { + 'type': 'LINE', + 'autoscaleInfoProvider': False, + 'data': [], + 'options': { + 'color': '#ffffff', + 'priceScaleId': 'left', + }, + }, +] + +CHARTS_OPTIONS = { + 'crosshair': 'NORMAL', + 'autoSize': True, + 'toolbox': True, + 'timeScale': { + 'timeVisible': True, # // Shows HH:mm on x-axis + 'secondsVisible': True # // Optional: show seconds + }, + 'rightPriceScale': { + 'visible': True, + 'autoScale': True + }, + 'leftPriceScale': { + 'visible': True + }, + 'layout': { + 'background': { 'type': 'solid', 'color': '#222' }, + 'textColor': '#DDD', + }, + 'grid': { + 'vertLines': { + 'color': '#e1e1e1', # // Set vertical line color + 'visible': True, + 'style': 2, # // 0: Solid, 1: Dashed, 2: Dotted, 3: LargeDashed, 4: SparseDotted + }, + 'horzLines': { + 'color': '#e1e1e1', # // Set horizontal line color + 'visible': True, + 'style': 2, + }, + } +} + ### Utils ### def update_body_scroll(e=None, bool_override=False): if e is None: @@ -40,26 +129,40 @@ async def update_tv(): 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) + timestamp_aster_tob = round( ( series_update_aster_tob['timestamp_transaction'] / 1000 ) , 2) + timestamp_extend_tob = round( ( series_update_extend_tob['timestamp_msg'] / 1000 ) , 2) + timestamp_algo_status = round( ( series_update_algo_status['last_update_ts_ms'] / 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']) + value_algo_model_ratio = float(series_update_algo_status['model_ratio'])*1_000 + value_algo_current_ratio = float(series_update_algo_status['current_ratio'])*1_000 + value_algo_expected_alpha = float(series_update_algo_status['expected_alpha'])*1_000 - data_dict = { - '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, - } + data_list = [ + { + 'timestamp': timestamp_aster_tob, + 'value': value_aster_tob, + }, + { + 'timestamp': timestamp_extend_tob, + 'value': value_extend_tob, + }, + { + 'timestamp': timestamp_algo_status, + 'value': value_algo_model_ratio, + }, + { + 'timestamp': timestamp_algo_status, + 'value': value_algo_current_ratio, + }, + { + 'timestamp': timestamp_algo_status, + 'value': value_algo_expected_alpha, + }, + ] - ui.run_javascript(f'await update_tv(data_dict={data_dict});') + ui.run_javascript(f'await update_tv(data_list={data_list}, lookback_max_points={LOOKBACK_RT_TV_MAX_POINTS});') ### Pages ### @@ -75,12 +178,12 @@ async def rt_chart_page(): with ui.column(): ui.switch('▶️', value=True).bind_value_to(timer, 'active') with ui.column().style('position: absolute; right: 20px; font-family: monospace; align-self: center;'): - ui.label('Atwater Trading: Orderbook') + ui.label('Atwater Trading - Funding Rate') with ui.grid(columns=16).classes('w-full gap-0 auto-fit'): with ui.card().tight().classes('w-full col-span-full no-shadow border border-black-200').style('overflow: auto;'): ui.html('', sanitize=False).classes('w-full') - ui.run_javascript('await create_tv();') + ui.run_javascript(f'await create_tv(charts_list={CHARTS}, create_chart_options={CHARTS_OPTIONS});') def root(): app.add_static_files(max_cache_age=0, url_path='/static', local_directory=os.path.join(os.path.dirname(__file__), 'nicegui_modules/static')) diff --git a/ng_modules/static/script.js b/ng_modules/static/script.js deleted file mode 100644 index aedf603..0000000 --- a/ng_modules/static/script.js +++ /dev/null @@ -1,223 +0,0 @@ -async function waitForVariable(variableName, timeout = 5000) { - const startTime = Date.now(); - while (typeof window[variableName] === 'undefined') { - if (Date.now() - startTime > timeout) { - throw new Error(`Variable '${variableName}' not defined within ${timeout}ms`); - } - await new Promise(resolve => setTimeout(resolve, 100)); - } - console.log(`Variable '${variableName}' is now defined.`); -} - -async function update_tv(data_dict) { - - window.data.push({ time: data_dict.timestamp, value: data_dict.value }); - window.data_b.push({ time: data_dict.timestamp_b, value: data_dict.value_b }); - window.data_c.push({ time: data_dict.timestamp_c, value: data_dict.value_c }); - window.data_tgt.push({ time: data_dict.timestamp_c, value: data_dict.target }); - window.lineSeries.update({ time: data_dict.timestamp, value: data_dict.value }); - window.lineSeries_b.update({ time: data_dict.timestamp_b, value: data_dict.value_b }); - window.lineSeries_c.update({ time: data_dict.timestamp_c, value: data_dict.value_c }); - window.lineSeries_tgt.update({ time: data_dict.timestamp_c, value: data_dict.target }); - - // midPriceLine.applyOptions({ - // price: data_dict.mid_px, - // color: '#c78228', - // lineWidth: 3, - // lineStyle: LightweightCharts.LineStyle.Dashed, - // axisLabelVisible: true, - // }); - - window.chart.timeScale().scrollToRealTime(); - // const currentRange = window.chart.timeScale().getVisibleLogicalRange(); - // window.chart.timeScale().fitContent(); - // window.chart.timeScale().setVisibleLogicalRange(currentRange); - - const MAX_DATA_POINTS = data_dict.LOOKBACK_RT_TV_MAX_POINTS; - if (window.lineSeries.data().length > MAX_DATA_POINTS) { - window.lineSeries.setData(lineSeries.data().slice(-MAX_DATA_POINTS)); - } - if (window.lineSeries_b.data().length > MAX_DATA_POINTS) { - window.lineSeries_b.setData(lineSeries_b.data().slice(-MAX_DATA_POINTS)); - } - if (window.lineSeries_c.data().length > MAX_DATA_POINTS) { - window.lineSeries_c.setData(lineSeries_c.data().slice(-MAX_DATA_POINTS)); - } - if (window.lineSeries_tgt.data().length > MAX_DATA_POINTS) { - window.lineSeries_tgt.setData(lineSeries_tgt.data().slice(-MAX_DATA_POINTS)); - } -}; - - -async function create_tv() { - window.chart = LightweightCharts.createChart(document.getElementById('tv'), - { - autoSize: true, - toolbox: true, - timeScale: { - timeVisible: true, // Shows HH:mm on x-axis - secondsVisible: true // Optional: show seconds - }, - rightPriceScale: { - visible: true, - autoScale: true - }, - leftPriceScale: { - visible: true - }, - - layout: { - background: { type: 'solid', color: '#222' }, - textColor: '#DDD', - }, - grid: { - vertLines: { - color: '#e1e1e1', // Set vertical line color - visible: true, - style: 2, // 0: Solid, 1: Dashed, 2: Dotted, 3: LargeDashed, 4: SparseDotted - }, - horzLines: { - color: '#e1e1e1', // Set horizontal line color - visible: true, - style: 2, - }, - }, - - crosshair: { mode: LightweightCharts.CrosshairMode.Normal }, - } - ); - window.lineSeries = chart.addSeries(LightweightCharts.LineSeries, { - color: '#94fcdf', - priceScaleId: 'right' - // topColor: '#94fcdf', - // bottomColor: 'rgba(112, 171, 249, 0.28)', - // invertFilledArea: false - }); - window.lineSeries_b = chart.addSeries(LightweightCharts.LineSeries, { - color: '#dd7525', - priceScaleId: 'right' - // topColor: '#94fcdf', - // bottomColor: 'rgba(112, 171, 249, 0.28)', - // invertFilledArea: false - }); - window.lineSeries_c = chart.addSeries(LightweightCharts.LineSeries, { - color: '#ea0707', - priceScaleId: 'left', - autoscaleInfoProvider: () => ({ - priceRange: { - minValue: 0.0, - maxValue: 1.0 - } - }) - // topColor: '#94fcdf', - // bottomColor: 'rgba(112, 171, 249, 0.28)', - // invertFilledArea: false - }); - window.lineSeries_tgt = chart.addSeries(LightweightCharts.LineSeries, { - color: '#ffffff', - priceScaleId: 'right', - lineStyle: LightweightCharts.LineStyle.Dashed - // topColor: '#94fcdf', - // bottomColor: 'rgba(112, 171, 249, 0.28)', - // invertFilledArea: false - }); - // window.midPriceLine_Config = { - // price: 0, - // color: '#c78228', - // lineWidth: 3, - // lineStyle: LightweightCharts.LineStyle.Dashed, - // axisLabelVisible: false, - // }; - // window.midPriceLine = window.lineSeries.createPriceLine(midPriceLine_Config); - window.data = []; - window.data_b = []; - window.data_c = []; - window.data_tgt = []; - window.lineSeries.setData(window.data); - window.lineSeries_b.setData(window.data_b); - window.lineSeries_c.setData(window.data_c); - window.lineSeries_tgt.setData(window.data_tgt); - - // Create and style the tooltip html element - const container = document.getElementById('tv'); - - window.toolTipWidth = 200; - - const toolTip = document.createElement('div'); - toolTip.style = `width: ${window.toolTipWidth}px; height: 100%; position: absolute; display: none; padding: 8px; box-sizing: border-box; font-size: 12px; text-align: left; z-index: 1000; top: 12px; left: 12px; pointer-events: none; border-radius: 4px 4px 0px 0px; border-bottom: none; box-shadow: 0 2px 5px 0 rgba(117, 134, 150, 0.45);font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;`; - toolTip.style.background = `rgba(${'0, 0, 0'}, 0.25)`; - toolTip.style.color = 'white'; - toolTip.style.borderColor = 'rgba( 239, 83, 80, 1)'; - container.appendChild(toolTip); - - // update tooltip - window.chart.subscribeCrosshairMove(async param => { - - if ( - param.point === undefined || - !param.time || - param.point.x < 0 || - param.point.x > container.clientWidth || - param.point.y < 0 || - param.point.y > container.clientHeight - ) { - toolTip.style.display = 'none'; - } else { - - // toolTip.style.height = '100%'; - toolTip.style.alignContent = 'center'; - - const dateStr = new Date(param.time*1000).toISOString(); - - let data = await param.seriesData.get(window.lineSeries); - if (data === undefined) { - data = {} - data.value = 0 - console.log('data is UNDEFINED, SETTING TO 0') - }; - - let data_b = await param.seriesData.get(window.lineSeries_b); - if (data_b === undefined) { - data_b = {} - data_b.value = 0 - console.log('data is UNDEFINED, SETTING TO 0') - }; - - const value_px = data.value - const value_px_b = window.data_b.value - const value_px_c = window.data_c.value - const value_px_tgt = window.data_tgt.value - - toolTip.style.display = 'block'; - //