nicegui initial

This commit is contained in:
2026-05-07 06:13:43 +00:00
parent f45c035ebb
commit 1bbb4797ce
10 changed files with 1221 additions and 1377 deletions

View File

@@ -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"
}

View File

@@ -1,5 +1,5 @@
{
"Updated_Timestamp": 1778095014766,
"Updated_Timestamp": 1778133411421,
"Config": {
"Loop_Sleep_Sec": 0.0,
"Max_Order_Over_Notional_Ratio": 1.05,

File diff suppressed because it is too large Load Diff

View File

@@ -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

21
main.py
View File

@@ -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 ###

View File

@@ -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)

143
ng.py
View File

@@ -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('<div id="tv" style="width:100%; height:800px;"></div>', 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'))

View File

@@ -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';
// <div style="color: ${'rgba( 239, 83, 80, 1)'}">
// Atwater Trading
// </div>
toolTip.innerHTML = `
<div style="font-size: 24px; margin: 4px 0px; color: ${'white'}">
Chainlink: ${Math.round(100 * value_px) / 100}
Binance: ${Math.round(100 * value_px_b) / 100}
</div>
<div style="color: ${'white'}">
${dateStr}
</div>
`;
let left = param.point.x; // relative to timeScale
const timeScaleWidth = chart.timeScale().width();
const priceScaleWidth = chart.priceScale('left').width();
const halfTooltipWidth = toolTipWidth / 2;
left += priceScaleWidth - halfTooltipWidth;
left = Math.min(left, priceScaleWidth + timeScaleWidth - toolTipWidth);
left = Math.max(left, priceScaleWidth);
toolTip.style.left = left + 'px';
toolTip.style.top = 0 + 'px';
}
});
window.chart.timeScale().fitContent();
console.log("TV Created!")
};

View File

@@ -0,0 +1,157 @@
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_list, lookback_max_points) {
data_list.forEach(function (item, index) {
// console.log(item, index);
window.charts_arr[index].data.push({ time: item.timestamp, value: item.value });
window.charts_arr[index].series.update({ time: item.timestamp, value: item.value });
if (window.charts_arr[index].series.data().length > lookback_max_points) {
window.charts_arr[index].series.setData(window.charts_arr[index].series.data().slice(-lookback_max_points));
};
});
// midPriceLine.applyOptions({
// price: data_dict.mid_px,
// color: '#c78228',
// lineWidth: 3,
// lineStyle: LightweightCharts.LineStyle.Dashed,
// axisLabelVisible: true,
// });
window.chart.timeScale().scrollToRealTime();
window.chart.timeScale().fitContent();
const currentRange = window.chart.timeScale().getVisibleLogicalRange();
window.chart.timeScale().setVisibleLogicalRange(currentRange);
};
async function create_tv(charts_list, create_chart_options) {
if (create_chart_options.crosshair == 'NORMAL') {
create_chart_options.crosshair = { mode: LightweightCharts.CrosshairMode.Normal }
};
window.chart = LightweightCharts.createChart(document.getElementById('tv'), create_chart_options);
window.charts_arr = [];
charts_list.forEach(function (item, index) {
// console.log(item, index);
charts_dict = {};
if ((Array.isArray(item.autoscaleInfoProvider) && item.autoscaleInfoProvider.length !== 0)) {
item.options.autoscaleInfoProvider = () => ({
priceRange: {
minValue: item.autoscaleInfoProvider[0],
maxValue: item.autoscaleInfoProvider[1]
}
})
};
if (item.type == "AREA" ) {
charts_dict.series = chart.addSeries(LightweightCharts.AreaSeries, item.options);
} else {
charts_dict.series = chart.addSeries(LightweightCharts.LineSeries, item.options);
};
charts_dict.data = [];
charts_dict.series.setData(charts_dict.data);
window.charts_arr.push(charts_dict);
});
window.chart.timeScale().fitContent();
console.log("TV Created!")
// window.midPriceLine_Config = {
// price: 0,
// color: '#c78228',
// lineWidth: 3,
// lineStyle: LightweightCharts.LineStyle.Dashed,
// axisLabelVisible: false,
// };
// window.midPriceLine = window.lineSeries.createPriceLine(midPriceLine_Config);
// 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';
// // <div style="color: ${'rgba( 239, 83, 80, 1)'}">
// // Atwater Trading
// // </div>
// toolTip.innerHTML = `
// <div style="font-size: 24px; margin: 4px 0px; color: ${'white'}">
// Chainlink: ${Math.round(100 * value_px) / 100}
// Binance: ${Math.round(100 * value_px_b) / 100}
// </div>
// <div style="color: ${'white'}">
// ${dateStr}
// </div>
// `;
// let left = param.point.x; // relative to timeScale
// const timeScaleWidth = chart.timeScale().width();
// const priceScaleWidth = chart.priceScale('left').width();
// const halfTooltipWidth = toolTipWidth / 2;
// left += priceScaleWidth - halfTooltipWidth;
// left = Math.min(left, priceScaleWidth + timeScaleWidth - toolTipWidth);
// left = Math.max(left, priceScaleWidth);
// toolTip.style.left = left + 'px';
// toolTip.style.top = 0 + 'px';
// }
// });
};