How Auto-Hedging Works: Technical Deep-Dive
This page provides a comprehensive technical explanation of the auto-hedge system, including NET position monitoring, trigger logic, cascade prevention, and hedge management.🧮 NET Position Monitoring
Why NET Position?
Vortex DCA runs independent long and short grids simultaneously. Auto-hedge monitors the NET position (long qty - short qty) to determine which side needs protection.Separate Long/Short Monitoring
Auto-hedge monitors each side independently: LONG Side:This approach ensures hedges are only placed on the side that needs protection, avoiding unnecessary trades.
🎯 Trigger Conditions
Auto-hedge triggers when EITHER condition is met:Condition A: Drawdown Threshold
Formula:Condition B: Liquidation Distance
Formula:Critical Override
Special Case: When liquidation distance drops below 3%, hedge triggers immediately regardless of anti-cascade logic:🛡️ Anti-Cascade Protection
The implementation includes comprehensive cascade prevention to avoid repeated hedging of the same drawdown event.The Cascade Problem
Without Anti-Cascade:Safety Mechanism 1: Original Position Tracking
The bot tracks the original position size when a hedge sequence starts:Safety Mechanism 2: Hedge Ratio Enforcement
Before placing a new hedge, the system checks if the target ratio is already achieved:Safety Mechanism 3: Price/Quantity Movement Checks
Won’t re-hedge unless price moved 2%+ OR position changed 20%+ since last hedge:Safety Mechanism 4: Original Quantity Reset
The original quantity resets when position changes by 50%+:🎬 Complete Hedge Cycle Example
Let’s walk through a complete auto-hedge cycle:Initial State
Step 1: Grid Fills (Long Side)
Step 2: Further Price Drop - Drawdown Trigger
Step 3: Calculate Hedge Size
Step 4: Place Hedge Order
Step 5: Hedge Fills
Step 6: Place Hedge Take Profit
Step 7: Trailing Stop Activates
Step 8: Trailing Stop Triggers
Step 9: Position After Hedge Close
Step 10: Grid Continues Operating
⚙️ Order Types Used
Hedge Placement: MARKET Order
- Guarantees immediate execution
- Protects against further drawdown
- No risk of order not filling
Hedge Take Profit: LIMIT Order (Initial)
- Sets specific profit target
- Remains active until hit or replaced by trailing stop
Trailing Stop: MARKET Order (When Triggered)
- Locks in profit immediately
- Prevents profit giveback from slippage
🔧 Exchange-Specific Implementation
BloFin Parameter Conversion
The strategy uses standardized parameters, but BloFin requires specific formatting:reduce_only (bool)->reduceOnly (string "true"/"false")- Position side explicitly specified in params
- Leverage set per order
The exchange adapter handles all parameter conversions automatically - you don’t need to worry about exchange-specific formatting!
📊 State Tracking
Auto-hedge maintains several state variables:🔁 Main Loop Integration
Auto-hedge runs in the main strategy loop:- Hedge checks run every 3 seconds (same as TP refresh)
- Ensures quick response to drawdowns
- Low overhead (simple calculations)
📈 Performance Characteristics
Computational Overhead
Per Check (every 3 seconds):- Calculate NET position: O(1)
- Calculate drawdown: O(1)
- Calculate liq distance: O(1)
- Anti-cascade checks: O(1)
Memory Usage
Per Symbol:- Hedge state: ~500 bytes
- Tracking info: ~300 bytes
Network Calls
Normal Operation: 0 API calls (monitoring only) When Hedge Triggers:- 1 call: Place hedge market order
- 1 call: Place hedge TP limit order
- 1 call: Cancel TP order
- 1 call: Place market close order
🧪 Testing & Validation
What to Monitor
In Logs:Validation Checklist
- Drawdown trigger tested at configured %
- Liquidation distance trigger tested
- Critical override tested (liq < 3%)
- Anti-cascade prevents repeated hedges
- Hedge ratio enforcement working
- Original qty tracking correct
- Trailing stop activates at TP target
- Trailing stop triggers on retrace
- Market orders execute immediately
- Positions balance correctly after hedge
🔗 Related Documentation
- Auto-Hedging Overview - Feature introduction
- Configuration Guide - Parameter reference
- Risk Management Best Practices - Safety guidelines
Now you understand exactly how auto-hedging works under the hood! 🔧