Advanced Order Placement

Automatically execute orders when signals are detected. Lightning-fast order placement with built-in safety mechanisms and error handling.

Signal-Based Order Execution

MagicTradeBot monitors market conditions and executes trades automatically when specific volatility signals are registered. The bot supports four distinct action types:

Supported Volatility Actions

  • BUY - Standard buy signal for entering long positions
  • SELL - Standard sell signal for entering short positions
  • PUMP - High-volatility upward movement detection
  • CRASH - High-volatility downward movement detection

When any of these signals are registered, the bot immediately initiates the order placement sequence based on your configured trade trigger settings.

Order Type Configuration

The bot offers three flexible order execution modes to match your trading strategy:

Market Orders (Type: 0)

Executes trades immediately at the best available market price. Ideal for high-speed entries during volatile conditions where execution certainty is more important than price precision.

Limit Orders (Type: 1)

Places orders at a specific price level using the configured AskPriceBufferPer to set the limit price. Orders expire after the TimeInForce duration if not filled.

Configuration:

  • AskPriceBufferPer: 0.1 (adjusts limit price by 0.1% from current ask)
  • TimeInForce: 60 seconds (order expires after 60 seconds if unfilled)

Hybrid Orders (Type: 2)

Combines the best of both worlds with intelligent fallback execution:

  1. Initial Attempt: Places a limit order using the configured buffer percentage
  2. Monitoring Phase: Sets a timer based on TimeInForce to track order fulfillment
  3. Smart Fallback: If the limit order remains partially or completely unfilled after the timer expires:
    • Cancels the existing limit order for any unfilled quantity
    • Immediately replaces it with a market order to ensure execution

This approach optimizes for better pricing while guaranteeing execution, preventing missed opportunities during fast-moving markets.

Stop Loss & Take Profit Integration

The bot provides comprehensive risk management through automatic SL/TP order placement:

Stop Loss Protection

When StopLossPercent > 0, the bot automatically places a stop loss order immediately after the main order execution. This protects your position from excessive downside risk.

Example: If StopLossPercent: 2.0, a stop loss order is placed 2% below your entry price for long positions (or 2% above for short positions).

Take Profit Targets

When TakeProfitPercent > 0, the bot places a take profit order to automatically lock in gains when your target is reached.

Example: If TakeProfitPercent: 5.0, a take profit order is placed 5% above your entry price for long positions (or 5% below for short positions).

Order Lifecycle Management

Once orders are placed, MagicTradeBot maintains complete oversight through dual-layer monitoring:

i. Internal Order Tracking

All active orders are tracked in two locations:

  • Persistent Storage: Orders are recorded in a YAML file for crash recovery
  • Memory State: Real-time in-memory tracking for instant decision-making

The bot continuously monitors order activity and makes intelligent decisions based on:

Time-Based Decisions

  • Order age and expiration handling
  • Scheduled re-evaluation of positions
  • Timeout management for unfilled orders

Candle-Based Decisions

  • Price action analysis on completed candles
  • Trend reversal detection
  • Volume and momentum shifts

Rule-Based Actions

  • Custom stop loss trailing logic
  • Dynamic take profit adjustment
  • Position sizing modifications

ii. Exchange-Level Position Monitoring

For orders with exchange-level stop loss and take profit:

The bot maintains continuous synchronization with the exchange to monitor open positions in real-time:

  • Take Profit Hit: Detects when TP orders are filled, updates internal state, archives the trade, and triggers any post-trade actions
  • Stop Loss Hit: Identifies SL executions, records the loss, updates portfolio metrics, and adjusts risk parameters if configured
  • Manual Closures: Detects positions closed through other means (manual intervention, exchange liquidation, etc.) and reconciles internal records

This dual-monitoring approach ensures that whether orders are managed internally by the bot or executed at the exchange level, all position changes are captured, logged, and handled appropriately.

Safety Mechanisms

  • Error Handling: Comprehensive exception handling for network failures, insufficient balance, and exchange errors
  • Order Validation: Pre-execution checks for minimum order size, available balance, and market conditions
  • Rate Limiting: Built-in throttling to prevent exchange API violations
  • Fail-Safe Recovery: Automatic retry logic with exponential backoff for transient failures
  • State Persistence: All orders survive bot restarts through YAML-based state management

Configuration Example

TradeTriggerOptions:
  OrderType:
    IsEnabled: true
    Type: 2                        # Hybrid order mode
    AskPriceBufferPer: 0.1         # 0.1% buffer for limit orders
    TimeInForce: 60                # 60-second timeout

SLTPSettings:
  StopLossPercent: 2.0             # 2% stop loss
  TakeProfitPercent: 5.0           # 5% take profit

With this configuration, when a PUMP signal is detected, the bot will place a hybrid buy order, set a 2% stop loss, and a 5% take profit target, all while continuously monitoring the position until it's closed.

📎 Related Topics