Skip to main content

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:
SHORT 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:
Example (LONG):
Example (SHORT):

Condition B: Liquidation Distance

Formula:
Example (LONG):
Example (SHORT):

Critical Override

Special Case: When liquidation distance drops below 3%, hedge triggers immediately regardless of anti-cascade logic:
Example:
Critical override ensures emergency protection when liquidation is imminent!

🛡️ Anti-Cascade Protection

The implementation includes comprehensive cascade prevention to avoid repeated hedging of the same drawdown event.

The Cascade Problem

Without Anti-Cascade:
With Anti-Cascade:

Safety Mechanism 1: Original Position Tracking

The bot tracks the original position size when a hedge sequence starts:
Key Point: All hedge ratio calculations use the original position size, not the current NET position.

Safety Mechanism 2: Hedge Ratio Enforcement

Before placing a new hedge, the system checks if the target ratio is already achieved:
Example:

Safety Mechanism 3: Price/Quantity Movement Checks

Won’t re-hedge unless price moved 2%+ OR position changed 20%+ since last hedge:
Example Scenarios: Scenario 1: Price hasn’t moved much
Scenario 2: Price moved significantly
Scenario 3: Position grew significantly

Safety Mechanism 4: Original Quantity Reset

The original quantity resets when position changes by 50%+:
Example:

🎬 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

Why MARKET:
  • Guarantees immediate execution
  • Protects against further drawdown
  • No risk of order not filling

Hedge Take Profit: LIMIT Order (Initial)

Why LIMIT:
  • Sets specific profit target
  • Remains active until hit or replaced by trailing stop

Trailing Stop: MARKET Order (When Triggered)

Why MARKET:
  • 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:
Key Differences:
  • 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:
Timing:
  • 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)
Total: Minimal CPU impact (less than 0.01% per symbol)

Memory Usage

Per Symbol:
  • Hedge state: ~500 bytes
  • Tracking info: ~300 bytes
Total: less than 1 KB per symbol (negligible)

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
When Trailing Triggers:
  • 1 call: Cancel TP order
  • 1 call: Place market close order
Total: 2-4 API calls per hedge cycle (infrequent)

🧪 Testing & Validation

What to Monitor

In Logs:
In Exchange:

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


Now you understand exactly how auto-hedging works under the hood! 🔧