diff --git a/Makefile b/Makefile index 902588c3..65bad415 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ run: streamlit run main.py --server.headless true uninstall: - conda env remove -n dashboard + conda env remove -n dashboard -y install: if conda env list | grep -q '^dashboard '; then \ diff --git a/environment_conda.yml b/environment_conda.yml index 61ef7fd2..a2b078a4 100644 --- a/environment_conda.yml +++ b/environment_conda.yml @@ -3,12 +3,12 @@ channels: - defaults - conda-forge dependencies: - - python=3.10 - - sqlalchemy=1.4 + - python=3.12 + - sqlalchemy - pip - pip: - hummingbot - - numpy==1.26.4 + - pydantic - streamlit==1.33.0 - watchdog - python-dotenv @@ -23,7 +23,6 @@ dependencies: - st_pages - streamlit-elements==0.1.* - streamlit-authenticator==0.3.2 - - pydantic==1.10.4 - flake8 - isort - pre-commit diff --git a/frontend/components/deploy_v2_with_controllers.py b/frontend/components/deploy_v2_with_controllers.py index 7a49bf9b..8de1e320 100644 --- a/frontend/components/deploy_v2_with_controllers.py +++ b/frontend/components/deploy_v2_with_controllers.py @@ -40,9 +40,7 @@ def launch_new_bot(self): "markets": {}, "candles_config": [], "controllers_config": self._controller_config_selected, - "config_update_interval": 20, "script_file_name": "v2_with_controllers.py", - "time_to_cash_out": None, } } diff --git a/frontend/components/launch_strategy_v2.py b/frontend/components/launch_strategy_v2.py index 2669269f..00079a6d 100644 --- a/frontend/components/launch_strategy_v2.py +++ b/frontend/components/launch_strategy_v2.py @@ -83,7 +83,6 @@ def launch_new_bot(self): "markets": {}, "candles_config": [], "controllers_config": self._controller_config_selected, - "config_update_interval": 10, "script_file_name": "v2_with_controllers.py", "time_to_cash_out": None, } diff --git a/frontend/pages/config/dman_maker_v2/user_inputs.py b/frontend/pages/config/dman_maker_v2/user_inputs.py index 8f207f3c..a9f12098 100644 --- a/frontend/pages/config/dman_maker_v2/user_inputs.py +++ b/frontend/pages/config/dman_maker_v2/user_inputs.py @@ -19,7 +19,7 @@ def user_inputs(): config = { "controller_name": "dman_maker_v2", "controller_type": "market_making", - "manual_kill_switch": None, + "manual_kill_switch": False, "candles_config": [], "connector_name": connector_name, "trading_pair": trading_pair, diff --git a/frontend/pages/config/grid_strike/README.md b/frontend/pages/config/grid_strike/README.md index a9696878..f4d19e69 100644 --- a/frontend/pages/config/grid_strike/README.md +++ b/frontend/pages/config/grid_strike/README.md @@ -1,13 +1,13 @@ -# Grid Strike Configuration Tool +# Grid Strike Grid Component Configuration Tool -Welcome to the Grid Strike Configuration Tool! This tool allows you to create, modify, visualize, and save configurations for the Grid Strike trading strategy. Here's how you can make the most out of it. +Welcome to the Grid Strike Grid Component Configuration Tool! This tool allows you to create, modify, visualize, and save configurations for the Grid Strike Grid Component trading strategy, which is a simplified version of the Grid Strike strategy focused on a single grid. ## Features -- **Start from Default Configurations**: Begin with a default configuration or use the values from an existing configuration. -- **Dynamic Price Range Defaults**: Automatically sets grid ranges based on current market conditions. -- **Visual Grid Configuration**: See your grid ranges directly on the price chart. -- **Multiple Grid Ranges**: Configure up to 5 different grid ranges with different sides (BUY/SELL). +- **Simple Grid Configuration**: Configure a single grid with start, end, and limit prices. +- **Dynamic Price Range Defaults**: Automatically sets price ranges based on current market conditions. +- **Visual Grid Configuration**: See your grid settings directly on the price chart. +- **Triple Barrier Risk Management**: Configure take profit, stop loss, and time limit parameters. - **Save and Deploy**: Once satisfied, save the configuration to deploy it later. ## How to Use @@ -15,9 +15,10 @@ Welcome to the Grid Strike Configuration Tool! This tool allows you to create, m ### 1. Basic Configuration Start by configuring the basic parameters: +- **ID Prefix**: Prefix for the strategy ID (default: "grid_"). +- **Trading Pair**: Choose the cryptocurrency trading pair (e.g., "BTC-FDUSD"). - **Connector Name**: Select the trading platform or exchange (e.g., "binance"). -- **Trading Pair**: Choose the cryptocurrency trading pair (e.g., "BTC-USDT"). -- **Leverage**: Set the leverage ratio (use 1 for spot trading). +- **Leverage**: Set the leverage ratio for margin/futures trading. ### 2. Chart Configuration @@ -26,69 +27,111 @@ Configure how you want to visualize the market data: - **Interval**: Choose the timeframe for the candlesticks (1m to 1d). - **Days to Display**: Select how many days of historical data to show. -### 3. Grid Ranges +### 3. Grid Configuration -Configure up to 5 grid ranges with different parameters: -- **Number of Grid Ranges**: Select how many ranges you want to configure (1-5). -- **Side**: Choose BUY or SELL for each range. -- **Start Price**: The price where the range begins. -- **End Price**: The price where the range ends. -- **Amount %**: Percentage of total amount allocated to this range. +Configure your grid parameters: +- **Side**: Choose BUY or SELL for the grid. +- **Start Price**: The price where the grid begins. +- **End Price**: The price where the grid ends. +- **Limit Price**: A price limit that will stop the strategy. +- **Min Spread Between Orders**: Minimum price difference between orders. +- **Min Order Amount (Quote)**: Minimum size for individual orders. +- **Maximum Open Orders**: Maximum number of active orders in the grid. -### 4. Advanced Configuration +### 4. Order Configuration -Fine-tune your strategy with advanced parameters: -- **Position Mode**: Choose between HEDGE or ONE-WAY. -- **Time Limit**: Maximum duration for orders (in hours). +Fine-tune your order placement: +- **Max Orders Per Batch**: Maximum number of orders to place at once. +- **Order Frequency**: Time between order placements in seconds. - **Activation Bounds**: Price deviation to trigger updates. -- **Min Spread Between Orders**: Minimum price difference between orders. -- **Min Order Amount**: Minimum size for individual orders. -- **Max Open Orders**: Maximum number of active orders per range. -- **Grid Range Update Interval**: How often to update grid ranges (in seconds). -## Understanding Grid Strike Strategy +### 5. Triple Barrier Configuration + +Set up risk management parameters: +- **Open Order Type**: The type of order to open positions (e.g., MARKET, LIMIT). +- **Take Profit**: Price movement percentage for take profit. +- **Stop Loss**: Price movement percentage for stop loss. +- **Time Limit**: Time limit for orders in hours. +- **Order Type Settings**: Configure order types for each barrier. + +### 6. Advanced Configuration + +Additional settings: +- **Position Mode**: Choose between HEDGE or ONE-WAY. +- **Strategy Time Limit**: Maximum duration for the entire strategy in hours. +- **Manual Kill Switch**: Option to enable manual kill switch. + +## Understanding Grid Strike Grid Component -The Grid Strike strategy creates a grid of orders within specified price ranges. Here's how it works: +The Grid Strike Grid Component strategy creates a single grid of orders within a specified price range. Here's how it works: -### Grid Range Mechanics -- Each grid range defines a price zone where the strategy will place orders -- BUY ranges place buy orders from higher to lower prices -- SELL ranges place sell orders from lower to higher prices -- Multiple ranges can work simultaneously with different configurations +### Grid Mechanics +- The strategy places orders uniformly between the start and end prices +- BUY grids place buy orders from start (higher) to end (lower) prices +- SELL grids place sell orders from start (lower) to end (higher) prices +- The limit price serves as an additional safety boundary ### Order Placement -- Orders are placed within each range based on the min spread between orders -- The amount per order is calculated based on the range's allocation percentage +- Orders are placed within the grid based on the min spread between orders +- The amount per order is calculated based on the total amount specified - Orders are automatically adjusted when price moves beyond activation bounds ### Visual Indicators -- Green lines represent BUY ranges -- Red lines represent SELL ranges -- Different dash patterns distinguish multiple ranges of the same side -- Horizontal lines show the start and end prices of each range +- Green lines represent the start and end prices +- Red line represents the limit price +- Candlestick chart shows the market price action -## Best Practices +## Example Configuration -1. **Range Placement** - - Place BUY ranges below current price - - Place SELL ranges above current price - - Avoid overlapping ranges of the same side +Here's a sample configuration for a BTC-FDUSD grid: + +```yaml +id: grid_btcfdusd +controller_name: grid_strike +controller_type: generic +total_amount_quote: 200 +manual_kill_switch: null +candles_config: [] +leverage: 75 +position_mode: HEDGE +connector_name: binance +trading_pair: BTC-FDUSD +side: 1 +start_price: 84000 +end_price: 84300 +limit_price: 83700 +min_spread_between_orders: 0.0001 +min_order_amount_quote: 5 +max_open_orders: 40 +max_orders_per_batch: 1 +order_frequency: 2 +activation_bounds: 0.01 +triple_barrier_config: + open_order_type: 3 + stop_loss: null + stop_loss_order_type: 1 + take_profit: 0.0001 + take_profit_order_type: 3 + time_limit: 21600 + time_limit_order_type: 1 +time_limit: 172800 +``` -2. **Amount Allocation** - - Distribute amounts across ranges based on your risk preference - - Ensure total allocation across all ranges doesn't exceed 100% - - Consider larger allocations for ranges closer to current price +## Best Practices -3. **Spread Configuration** - - Set min spread based on the asset's volatility - - Larger spreads mean fewer, more profitable orders - - Smaller spreads mean more frequent, less profitable orders +1. **Grid Placement** + - For BUY grids, set start price above end price + - For SELL grids, set end price above start price + - Set limit price as a safety boundary where you want to stop the strategy -4. **Risk Management** - - Use appropriate leverage (1 for spot) - - Set reasonable time limits for orders - - Monitor and adjust activation bounds based on market conditions +2. **Amount Management** + - Set total amount based on your risk tolerance + - Configure min order amount to ensure meaningful trade sizes -## Example Configuration +3. **Grid Density** + - Adjust min spread between orders based on the asset's volatility + - Set max open orders to control grid density -Here's a sample configuration for a BTC-USDT grid: +4. **Risk Management** + - Use triple barrier parameters to manage risk for individual positions + - Set appropriate time limits for both positions and the overall strategy \ No newline at end of file diff --git a/frontend/pages/config/grid_strike/app.py b/frontend/pages/config/grid_strike/app.py index e2d450d1..6040dc5f 100644 --- a/frontend/pages/config/grid_strike/app.py +++ b/frontend/pages/config/grid_strike/app.py @@ -13,45 +13,46 @@ from frontend.visualization.utils import add_traces_to_fig -def get_grid_range_traces(grid_ranges): - """Generate horizontal line traces for grid ranges with different colors.""" - dash_styles = ['solid', 'dash', 'dot', 'dashdot', 'longdash'] # 5 different styles +def get_grid_trace(start_price, end_price, limit_price): + """Generate horizontal line traces for the grid with different colors.""" traces = [] - buy_count = 0 - sell_count = 0 - for i, grid_range in enumerate(grid_ranges): - # Set color based on trade type - if grid_range["side"] == TradeType.BUY: - color = 'rgba(0, 255, 0, 1)' # Bright green for buy - dash_style = dash_styles[buy_count % len(dash_styles)] - buy_count += 1 - else: - color = 'rgba(255, 0, 0, 1)' # Bright red for sell - dash_style = dash_styles[sell_count % len(dash_styles)] - sell_count += 1 - # Start price line + + # Start price line + traces.append(go.Scatter( + x=[], # Will be set to full range when plotting + y=[float(start_price), float(start_price)], + mode='lines', + line=dict(color='rgba(0, 255, 0, 1)', width=1.5, dash='solid'), + name=f'Start Price: {float(start_price):,.2f}', + hoverinfo='name' + )) + + # End price line + traces.append(go.Scatter( + x=[], # Will be set to full range when plotting + y=[float(end_price), float(end_price)], + mode='lines', + line=dict(color='rgba(0, 255, 0, 1)', width=1.5, dash='dot'), + name=f'End Price: {float(end_price):,.2f}', + hoverinfo='name' + )) + + # Limit price line (if provided) + if limit_price: traces.append(go.Scatter( x=[], # Will be set to full range when plotting - y=[float(grid_range["start_price"]), float(grid_range["start_price"])], + y=[float(limit_price), float(limit_price)], mode='lines', - line=dict(color=color, width=1.5, dash=dash_style), - name=f'Range {i} Start: {float(grid_range["start_price"]):,.2f} ({grid_range["side"].name})', - hoverinfo='name' - )) - # End price line - traces.append(go.Scatter( - x=[], # Will be set to full range when plotting - y=[float(grid_range["end_price"]), float(grid_range["end_price"])], - mode='lines', - line=dict(color=color, width=1.5, dash=dash_style), - name=f'Range {i} End: {float(grid_range["end_price"]):,.2f} ({grid_range["side"].name})', + line=dict(color='rgba(255, 0, 0, 1)', width=1.5, dash='dashdot'), + name=f'Limit Price: {float(limit_price):,.2f}', hoverinfo='name' )) + return traces # Initialize the Streamlit page -initialize_st_page(title="Grid Strike", icon="📊", initial_sidebar_state="expanded") +initialize_st_page(title="Grid Strike Grid Component", icon="📊", initial_sidebar_state="expanded") backend_api_client = get_backend_api_client() get_default_config_loader("grid_strike") @@ -70,28 +71,34 @@ def get_grid_range_traces(grid_ranges): # Create a subplot with just 1 row for price action fig = make_subplots( rows=1, cols=1, - subplot_titles=(f'Grid Strike - {inputs["trading_pair"]} ({inputs["interval"]})',), + subplot_titles=(f'Grid Strike Grid Component - {inputs["trading_pair"]} ({inputs["interval"]})',), ) # Add basic candlestick chart candlestick_trace = get_candlestick_trace(candles) add_traces_to_fig(fig, [candlestick_trace], row=1, col=1) -# Add grid range visualization -grid_traces = get_grid_range_traces(inputs["grid_ranges"]) +# Add grid visualization +grid_traces = get_grid_trace( + inputs["start_price"], + inputs["end_price"], + inputs["limit_price"] +) + for trace in grid_traces: # Set the x-axis range for all grid traces trace.x = [candles.index[0], candles.index[-1]] fig.add_trace(trace, row=1, col=1) -# Update y-axis to make sure all grid ranges and candles are visible +# Update y-axis to make sure all grid points and candles are visible all_prices = [] # Add candle prices all_prices.extend(candles['high'].tolist()) all_prices.extend(candles['low'].tolist()) -# Add grid range prices -for grid_range in inputs["grid_ranges"]: - all_prices.extend([float(grid_range["start_price"]), float(grid_range["end_price"])]) +# Add grid prices +all_prices.extend([float(inputs["start_price"]), float(inputs["end_price"])]) +if inputs["limit_price"]: + all_prices.append(float(inputs["limit_price"])) y_min, y_max = min(all_prices), max(all_prices) padding = (y_max - y_min) * 0.1 # Add 10% padding @@ -128,21 +135,27 @@ def get_grid_range_traces(grid_ranges): def prepare_config_for_save(config): """Prepare config for JSON serialization.""" prepared_config = config.copy() - grid_ranges = [] - for grid_range in prepared_config["grid_ranges"]: - grid_range = grid_range.copy() - grid_range["side"] = grid_range["side"].value - grid_range["open_order_type"] = grid_range["open_order_type"].value - grid_range["take_profit_order_type"] = grid_range["take_profit_order_type"].value - grid_ranges.append(grid_range) - prepared_config["grid_ranges"] = grid_ranges + + # Convert position mode enum to value prepared_config["position_mode"] = prepared_config["position_mode"].value + + # Convert side to value + prepared_config["side"] = prepared_config["side"].value + + # Convert triple barrier order types to values + if "triple_barrier_config" in prepared_config and prepared_config["triple_barrier_config"]: + for key in ["open_order_type", "stop_loss_order_type", "take_profit_order_type", "time_limit_order_type"]: + if key in prepared_config["triple_barrier_config"] and prepared_config["triple_barrier_config"][key] is not None: + prepared_config["triple_barrier_config"][key] = prepared_config["triple_barrier_config"][key].value + + # Remove chart-specific fields del prepared_config["candles_connector"] del prepared_config["interval"] del prepared_config["days_to_visualize"] + return prepared_config -# Replace the render_save_config line with: +# Render save config component render_save_config(st.session_state["default_config"]["id"], - prepare_config_for_save(st.session_state["default_config"])) + prepare_config_for_save(st.session_state["default_config"])) \ No newline at end of file diff --git a/frontend/pages/config/grid_strike/user_inputs.py b/frontend/pages/config/grid_strike/user_inputs.py index c02daf24..f007b509 100644 --- a/frontend/pages/config/grid_strike/user_inputs.py +++ b/frontend/pages/config/grid_strike/user_inputs.py @@ -1,6 +1,3 @@ -from decimal import Decimal - -import plotly.graph_objs as go import streamlit as st from hummingbot.core.data_type.common import OrderType, PositionMode, TradeType @@ -16,65 +13,177 @@ def get_price_range_defaults(connector_name: str, trading_pair: str, interval: s interval=interval, days=days ) + current_price = float(candles['close'].iloc[-1]) min_price = float(candles['low'].quantile(0.05)) max_price = float(candles['high'].quantile(0.95)) - return round(min_price, 2), round(max_price, 2) + return round(min_price, 2), round(current_price, 2), round(max_price, 2) except Exception as e: st.warning(f"Could not fetch price data: {str(e)}. Using default values.") - return 40000.0, 60000.0 # Fallback defaults - - -def get_grid_range_traces(grid_ranges): - """Generate horizontal line traces for grid ranges with different colors.""" - dash_styles = ['solid', 'dash', 'dot', 'dashdot', 'longdash'] # 5 different styles - traces = [] - buy_count = 0 - sell_count = 0 - for i, grid_range in enumerate(grid_ranges): - # Set color based on trade type - if grid_range["side"] == TradeType.BUY: - color = 'rgba(0, 255, 0, 1)' # Bright green for buy - dash_style = dash_styles[buy_count % len(dash_styles)] - buy_count += 1 - else: - color = 'rgba(255, 0, 0, 1)' # Bright red for sell - dash_style = dash_styles[sell_count % len(dash_styles)] - sell_count += 1 - # Start price line - traces.append(go.Scatter( - x=[], # Will be set to full range when plotting - y=[float(grid_range["start_price"]), float(grid_range["start_price"])], - mode='lines', - line=dict(color=color, width=1.5, dash=dash_style), - name=f'Range {i} Start: {float(grid_range["start_price"]):,.2f} ({grid_range["side"].name})', - hoverinfo='name' - )) - # End price line - traces.append(go.Scatter( - x=[], # Will be set to full range when plotting - y=[float(grid_range["end_price"]), float(grid_range["end_price"])], - mode='lines', - line=dict(color=color, width=1.5, dash=dash_style), - name=f'Range {i} End: {float(grid_range["end_price"]):,.2f} ({grid_range["side"].name})', - hoverinfo='name' - )) - return traces + return 40000.0, 42000.0, 44000.0 # Fallback defaults def user_inputs(): # Split the page into two columns for the expanders left_col, right_col = st.columns(2) with left_col: - # Basic trading parameters - with st.expander("Basic Configuration", expanded=True): + # Combined Basic, Amount, and Grid Configuration + with st.expander("Grid Configuration", expanded=True): + # Basic parameters + c1, c2 = st.columns(2) + with c1: + connector_name = st.text_input("Connector Name", value="binance_perpetual") + # Side selection + side = st.selectbox( + "Side", + options=["BUY", "SELL"], + index=0, + help="Trading direction for the grid" + ) + leverage = st.number_input("Leverage", min_value=1, value=20) + with c2: + trading_pair = st.text_input("Trading Pair", value="WLD-USDT") + # Amount parameter + total_amount_quote = st.number_input( + "Total Amount (Quote)", + min_value=0.0, + value=200.0, + help="Total amount in quote currency to use for trading" + ) + position_mode = st.selectbox( + "Position Mode", + options=["HEDGE", "ONEWAY"], + index=0 + ) + # Grid price parameters + with c1: + # Get default price ranges based on current market data + min_price, current_price, max_price = get_price_range_defaults( + connector_name, + trading_pair, + "1h", # Default interval for price range calculation + 30 # Default days for price range calculation + ) + if side == "BUY": + start_price = min(min_price, current_price) + end_price = max(current_price, max_price) + limit_price = start_price * 0.95 + else: + start_price = max(max_price, current_price) + end_price = min(current_price, min_price) + limit_price = start_price * 1.05 + # Price configuration with meaningful defaults + start_price = st.number_input( + "Start Price", + value=start_price, + format="%.2f", + help="Grid start price" + ) + + end_price = st.number_input( + "End Price", + value=end_price, + format="%.2f", + help="Grid end price" + ) + + limit_price = st.number_input( + "Limit Price", + value=limit_price, + format="%.2f", + help="Price limit to stop the strategy" + ) + + with c2: + # Grid spacing configuration + min_spread = st.number_input( + "Min Spread Between Orders", + min_value=0.0000, + value=0.0001, + format="%.4f", + help="Minimum price difference between orders", + step=0.0001 + ) + + min_order_amount = st.number_input( + "Min Order Amount (Quote)", + min_value=1.0, + value=6.0, + help="Minimum amount for each order in quote currency" + ) + + max_open_orders = st.number_input( + "Maximum Open Orders", + min_value=1, + value=3, + help="Maximum number of active orders in the grid" + ) + + with right_col: + # Order configuration + with st.expander("Order Configuration", expanded=True): c1, c2, c3 = st.columns(3) with c1: - connector_name = st.text_input("Connector Name", value="binance") + max_orders_per_batch = st.number_input( + "Max Orders Per Batch", + min_value=1, + value=1, + help="Maximum number of orders to place at once" + ) with c2: - trading_pair = st.text_input("Trading Pair", value="BTC-USDT") + order_frequency = st.number_input( + "Order Frequency (s)", + min_value=1, + value=2, + help="Time between order placements in seconds" + ) with c3: - leverage = st.number_input("Leverage", min_value=1, value=20) - # Visualization Configuration + activation_bounds = st.number_input( + "Activation Bounds", + min_value=0.0, + value=0.01, + format="%.4f", + help="Price deviation to trigger updates" + ) + + # Triple barrier configuration + with st.expander("Triple Barrier Configuration", expanded=True): + c1, c2 = st.columns(2) + with c1: + # Order types + open_order_type_options = ["LIMIT", "LIMIT_MAKER", "MARKET"] + open_order_type = st.selectbox( + "Open Order Type", + options=open_order_type_options, + index=1, # Default to MARKET + key="open_order_type" + ) + + take_profit_order_type_options = ["LIMIT", "LIMIT_MAKER", "MARKET"] + take_profit_order_type = st.selectbox( + "Take Profit Order Type", + options=take_profit_order_type_options, + index=1, # Default to MARKET + key="tp_order_type" + ) + + with c2: + # Barrier values + take_profit = st.number_input( + "Take Profit", + min_value=0.0, + value=0.0001, + format="%.4f", + help="Price movement percentage for take profit" + ) + + stop_loss = st.number_input( + "Stop Loss", + min_value=0.0, + value=0.1, + format="%.4f", + help="Price movement percentage for stop loss (0 for none)" + ) + # Chart configuration with st.expander("Chart Configuration", expanded=True): c1, c2, c3 = st.columns(3) with c1: @@ -87,7 +196,7 @@ def user_inputs(): interval = st.selectbox( "Interval", options=["1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "12h", "1d"], - index=10, # Default to 30m + index=4, # Default to 1h help="Candlestick interval" ) with c3: @@ -95,129 +204,23 @@ def user_inputs(): "Days to Display", min_value=1, max_value=365, - value=180, + value=30, help="Number of days of historical data to display" ) - # Get default price ranges based on current market data - default_min, default_max = get_price_range_defaults( - candles_connector, - trading_pair, - interval, - days_to_visualize - ) - # Grid Ranges Configuration - with st.expander("Grid Ranges", expanded=True): - grid_ranges = [] - c1, c2 = st.columns(2) - with c1: - num_ranges = st.number_input("Number of Grid Ranges", min_value=1, max_value=5, value=1) - with c2: - decimals = st.number_input("Decimals to Display", min_value=0, max_value=20, value=4) - fmt = f"%.{decimals}f" - for i in range(num_ranges): - st.markdown(f"#### Range {i}") - # Price configuration - c1, c2, c3, c4 = st.columns(4) - with c1: - # Set default start price based on side - side = st.selectbox( - f"Side {i}", - options=[TradeType.BUY.name, TradeType.SELL.name], - key=f"side_{i}" - ) - with c2: - # Set default start price based on side - start_price = st.number_input( - f"Start Price {i}", - value=default_min, - key=f"start_price_{i}", - format=fmt - ) - with c3: - # Set default end price based on side - end_price = st.number_input( - f"End Price {i}", - value=default_max, - key=f"end_price_{i}", - format=fmt - ) - with c4: - total_amount_pct = st.number_input( - f"Amount % {i}", - min_value=0.0, - max_value=100.0, - value=50.0, - key=f"amount_pct_{i}" - ) - st.markdown("---") - grid_ranges.append({ - "id": f"R{i}", - "start_price": Decimal(str(start_price)), - "end_price": Decimal(str(end_price)), - "total_amount_pct": Decimal(str(total_amount_pct/100)), - "side": TradeType[side], - "open_order_type": OrderType.LIMIT_MAKER, - "take_profit_order_type": OrderType.LIMIT - }) - with right_col: - # Amount configuration - with st.expander("Amount Configuration", expanded=True): - total_amount_quote = st.number_input( - "Total Amount (Quote)", - min_value=0.0, - value=1000.0, - help="Total amount in quote currency to use for trading" - ) - min_order_amount = st.number_input( - "Minimum Order Amount", - min_value=1.0, - value=10.0, - help="Minimum amount for each order" - ) - # Advanced Configuration - with st.expander("Advanced Configuration", expanded=True): - position_mode = st.selectbox( - "Position Mode", - options=["HEDGE", "ONEWAY"], - index=0 - ) - c1, c2 = st.columns(2) - with c1: - time_limit = st.number_input( - "Time Limit (hours)", - min_value=1, - value=48, - help="Strategy time limit in hours" - ) - min_spread = st.number_input( - "Min Spread Between Orders", - min_value=0.0000, - value=0.0001, - format="%.4f", # Show 3 decimal places - help="Minimum price difference between orders", - step=0.0001 - ) - activation_bounds = st.number_input( - "Activation Bounds", - min_value=0.0, - value=0.01, - format="%.4f", - help="Price deviation to trigger updates" - ) - with c2: - max_open_orders = st.number_input( - "Maximum Open Orders", - min_value=1, - value=5, - help="Maximum number of open orders" - ) - grid_update_interval = st.number_input( - "Grid Update Interval (s)", - min_value=1, - value=60, - help="How often to update grid ranges" - ) + + + # Convert stop_loss to None if it's zero + stop_loss_value = stop_loss if stop_loss > 0 else None + + # Prepare triple barrier config + triple_barrier_config = { + "open_order_type": OrderType[open_order_type], + "stop_loss": stop_loss_value, + "take_profit": take_profit, + "take_profit_order_type": OrderType[take_profit_order_type], + "time_limit": None, + } return { "controller_name": "grid_strike", @@ -228,14 +231,18 @@ def user_inputs(): "interval": interval, "days_to_visualize": days_to_visualize, "leverage": leverage, - "total_amount_quote": Decimal(str(total_amount_quote)), - "grid_ranges": grid_ranges, + "side": TradeType[side], + "start_price": start_price, + "end_price": end_price, + "limit_price": limit_price, "position_mode": PositionMode[position_mode], - "time_limit": time_limit * 60 * 60, - "activation_bounds": Decimal(str(activation_bounds)), - "min_spread_between_orders": Decimal(str(min_spread)) if min_spread > 0 else None, - "min_order_amount": Decimal(str(min_order_amount)), + "total_amount_quote": total_amount_quote, + "min_spread_between_orders": min_spread, + "min_order_amount_quote": min_order_amount, "max_open_orders": max_open_orders, - "grid_range_update_interval": grid_update_interval, - "extra_balance_base_usd": Decimal("10") - } + "max_orders_per_batch": max_orders_per_batch, + "order_frequency": order_frequency, + "activation_bounds": activation_bounds, + "triple_barrier_config": triple_barrier_config, + "candles_config": [] + } \ No newline at end of file diff --git a/frontend/pages/config/kalman_filter_v1/app.py b/frontend/pages/config/kalman_filter_v1/app.py index 08749dcd..cee2f4f3 100644 --- a/frontend/pages/config/kalman_filter_v1/app.py +++ b/frontend/pages/config/kalman_filter_v1/app.py @@ -190,7 +190,7 @@ def add_indicators(df, observation_covariance=1, transition_covariance=0.01, ini "id": id, "controller_name": "bollinger_v1", "controller_type": "directional_trading", - "manual_kill_switch": None, + "manual_kill_switch": False, "candles_config": [], "connector_name": connector_name, "trading_pair": trading_pair, diff --git a/frontend/pages/config/pmm_dynamic/user_inputs.py b/frontend/pages/config/pmm_dynamic/user_inputs.py index 1487e424..e3152880 100644 --- a/frontend/pages/config/pmm_dynamic/user_inputs.py +++ b/frontend/pages/config/pmm_dynamic/user_inputs.py @@ -28,7 +28,7 @@ def user_inputs(): config = { "controller_name": "pmm_dynamic", "controller_type": "market_making", - "manual_kill_switch": None, + "manual_kill_switch": False, "candles_config": [], "connector_name": connector_name, "trading_pair": trading_pair, diff --git a/frontend/pages/config/pmm_simple/user_inputs.py b/frontend/pages/config/pmm_simple/user_inputs.py index 6c4f62d6..1002a10e 100644 --- a/frontend/pages/config/pmm_simple/user_inputs.py +++ b/frontend/pages/config/pmm_simple/user_inputs.py @@ -13,7 +13,7 @@ def user_inputs(): config = { "controller_name": "pmm_simple", "controller_type": "market_making", - "manual_kill_switch": None, + "manual_kill_switch": False, "candles_config": [], "connector_name": connector_name, "trading_pair": trading_pair,