Step-by-Step Explanation: How Buy and Sell Orders Are Placed by the Bot
1. Market Data Fetching
- The bot fetches the latest candle data from Delta Exchange.
- Typically uses 15-minute intervals (or user-defined).
- It loads Open, High, Low, Close, and Volume (OHLCV) for each candle.
2. Indicator Calculation
- Uses technical indicators to understand market conditions:
- EMA (Exponential Moving Average): trend direction
- RSI (Relative Strength Index): overbought/oversold zones
- VWAP (Volume Weighted Average Price): fair value
- Calculates values from the latest and recent candles.
3. Buy Signal Logic
- A BUY signal is triggered when:
a. Price crosses above EMA (bullish trend start)
b. RSI is below 30 and turning up (oversold)
c. Price is near or above VWAP (fair value breakout)
- All these conditions must align to confirm a strong entry.
4. Sell Signal Logic
- A SELL signal is triggered when:
a. Price crosses below EMA (bearish trend)
b. RSI is above 70 and turning down (overbought)
c. Price is below VWAP (weakness confirmation)
- These signals are used to enter short trades or exit longs.
5. Risk & Position Sizing
- Once a signal is confirmed:
- Capital at risk is calculated: capital * risk%
- Stop-loss and take-profit prices are determined
- Lot size = risk capital / stop distance (adjusted for leverage)
6. Order Placement
- Bot sends order to Delta Exchange using the API:
- Market Order for instant execution OR
- Limit Order if configured (better price but slower execution)
- Example for market order:
place_order(symbol="BTCUSDT", side="buy", type="market", size=2)
7. Post-Order Tracking
- Tracks whether the order is filled.
- Stores order ID and execution price.
8. Stop-Loss & Take-Profit
- Immediately places SL and TP (if supported by API) or tracks them in bot memory.
- SL is placed below/above entry depending on direction.
- TP is set at a logical reward:risk level (e.g., 3x risk).
9. Trailing Stop (if enabled)
- Adjusts SL upward as price moves in favor of the trade.
- Locks in profit and reduces drawdown.
10. Exit Management
- Bot constantly monitors price:
- If SL is hit: exit and log a loss
- If TP is hit: exit and log a profit
- If trend reverses: exit manually or by new signal
11. Order History & Logging
- All entries and exits are logged with:
- Timestamp
- Symbol
- Direction (buy/sell)
- Size
- Entry, SL, TP
- Final P&L
This structured logic allows the bot to place accurate, risk-managed trades with technical confirmation.