(feat) update pages

This commit is contained in:
cardosofede
2025-07-11 02:57:57 +03:00
parent 91cd3d0365
commit e44fa89283
39 changed files with 6036 additions and 780 deletions

View File

@@ -0,0 +1,105 @@
# Backtesting Creation
The Backtesting Creation page enables you to design, configure, and launch backtests for various trading strategies using historical market data.
## Features
### 🎯 Strategy Configuration
- **Pre-built Strategy Templates**: Choose from popular strategies like PMM, XEMM, Grid, and Bollinger Bands
- **Custom Parameter Settings**: Fine-tune strategy parameters including spreads, order amounts, and risk limits
- **Multi-Exchange Support**: Backtest strategies across different exchanges and trading pairs
- **Position Mode Selection**: Test strategies in ONE-WAY or HEDGE position modes
### 📅 Backtest Setup
- **Historical Data Selection**: Choose date ranges for backtesting with available market data
- **Timeframe Configuration**: Select candle intervals (1m, 5m, 15m, 1h, 1d)
- **Initial Portfolio Settings**: Set starting balances for base and quote currencies
- **Fee Structure**: Configure maker/taker fees to match real trading conditions
### 🚀 Execution Options
- **Single Backtest**: Run individual backtests with specific configurations
- **Batch Testing**: Queue multiple backtests with different parameters
- **Optimization Mode**: Automatically test parameter ranges to find optimal settings
- **Real-time Progress**: Monitor backtest execution with live progress updates
## Usage Instructions
### 1. Select Strategy
- Choose a strategy type from the dropdown menu
- Review the strategy description and requirements
- Load a saved configuration or start with defaults
### 2. Configure Parameters
- **Trading Pair**: Select the market to backtest (e.g., BTC-USDT)
- **Date Range**: Set start and end dates for historical data
- **Strategy Parameters**: Adjust strategy-specific settings
- Spread percentages
- Order amounts and levels
- Risk management thresholds
- Refresh intervals
### 3. Set Initial Conditions
- **Starting Balance**: Define initial holdings in base and quote currencies
- **Leverage**: Set leverage for perpetual/futures markets (1x for spot)
- **Fees**: Input maker and taker fee percentages
### 4. Launch Backtest
- Review all settings in the configuration summary
- Click "Run Backtest" to start execution
- Monitor progress in the status panel
- Access results in the Analyze page once complete
## Technical Notes
### Data Requirements
- Historical candle data must be available for the selected date range
- Order book snapshots are simulated based on historical spreads
- Trade data is used for volume-weighted calculations
### Execution Engine
- **Event-Driven Simulation**: Tick-by-tick processing of market events
- **Order Matching**: Realistic order filling based on historical liquidity
- **Latency Simulation**: Configurable delays to model real-world conditions
### Performance Optimization
- Backtests run on the backend server for optimal performance
- Large date ranges are processed in chunks to prevent memory issues
- Results are streamed to the UI as they become available
## Component Structure
```
create/
├── create.py # Main page application
├── components/
│ ├── strategy_selector.py # Strategy selection interface
│ ├── parameter_form.py # Dynamic parameter input forms
│ └── backtest_launcher.py # Backtest execution controls
└── configs/
├── strategy_defaults.py # Default configurations
└── validation.py # Parameter validation rules
```
## Supported Strategies
### Market Making
- **Pure Market Making (PMM)**: Continuous bid/ask placement around mid-price
- **Cross-Exchange Market Making (XEMM)**: Arbitrage between exchanges
- **Perpetual Market Making**: Strategies for perpetual futures
### Directional
- **Bollinger Bands**: Mean reversion based on volatility bands
- **MACD + Bollinger**: Combined momentum and volatility signals
- **SuperTrend**: Trend-following with dynamic stops
### Grid Trading
- **Grid Strike**: Fixed-interval grid with customizable ranges
- **Dynamic Grid**: Adaptive grid based on market volatility
## Error Handling
The creation page handles various error scenarios:
- **Invalid Parameters**: Real-time validation with helpful error messages
- **Insufficient Data**: Clear warnings when historical data is missing
- **Configuration Conflicts**: Automatic detection of incompatible settings
- **Server Errors**: Graceful fallbacks with retry options

View File

View File

@@ -0,0 +1,47 @@
from types import SimpleNamespace
import streamlit as st
from streamlit_elements import elements, mui
from frontend.components.controllers_file_explorer import ControllersFileExplorer
from frontend.components.dashboard import Dashboard
from frontend.components.directional_strategy_creation_card import DirectionalStrategyCreationCard
from frontend.components.editor import Editor
from frontend.st_utils import initialize_st_page
initialize_st_page(title="Create", icon="️⚔️")
# TODO:
# * Add videos explaining how to the triple barrier method works and how the backtesting is designed,
# link to video of how to create a strategy, etc in a toggle.
# * Add functionality to start strategy creation from scratch or by duplicating an existing one
if "ds_board" not in st.session_state:
board = Dashboard()
ds_board = SimpleNamespace(
dashboard=board,
create_strategy_card=DirectionalStrategyCreationCard(board, 0, 0, 12, 1),
file_explorer=ControllersFileExplorer(board, 0, 2, 3, 7),
editor=Editor(board, 4, 2, 9, 7),
)
st.session_state.ds_board = ds_board
else:
ds_board = st.session_state.ds_board
# Add new tabs
for tab_name, content in ds_board.file_explorer.tabs.items():
if tab_name not in ds_board.editor.tabs:
ds_board.editor.add_tab(tab_name, content["content"], content["language"])
# Remove deleted tabs
for tab_name in list(ds_board.editor.tabs.keys()):
if tab_name not in ds_board.file_explorer.tabs:
ds_board.editor.remove_tab(tab_name)
with elements("directional_strategies"):
with mui.Paper(elevation=3, style={"padding": "2rem"}, spacing=[2, 2], container=True):
with ds_board.dashboard():
ds_board.create_strategy_card()
ds_board.file_explorer()
ds_board.editor()