Spaces:
Runtime error
Download docs/integrations/TWAP_INTEGRATION.md from GaryLeckey/aureon-os: direct link, hf CLI and curl.
- Browser
- Download file 8.31 kB
-
https://huggingface.co/spaces/GaryLeckey/aureon-os/resolve/main/docs/integrations/TWAP_INTEGRATION.md
- Command line
-
hf download hf://spaces/GaryLeckey/aureon-os/docs/integrations/TWAP_INTEGRATION.md
-
curl -L -o TWAP_INTEGRATION.md https://huggingface.co/spaces/GaryLeckey/aureon-os/resolve/main/docs/integrations/TWAP_INTEGRATION.md
π TWAP Integration - Intelligent Order Execution
Overview
AUREON now features Binance Algo TWAP (Time-Weighted Average Price) integration for intelligent large order execution. Orders above the configured threshold are automatically executed using TWAP to minimize market impact and improve fill quality.
π― How It Works
Automatic TWAP Routing
- Pride Scanner identifies high-opportunity targets
- QGITA generates trading signals with confidence tiers
- Order Size Check:
- Order value β₯ $500 β TWAP Execution
- Order value < $500 β Standard OMS Queue
- TWAP Execution:
- Breaks order into smaller sub-orders
- Executes over configured time period (5min - 24hr)
- Reduces slippage and market impact
π Database Schema
twap_orders Table
Tracks main TWAP order lifecycle:
- id (UUID): Unique order ID
- algo_id (BIGINT): Binance algo order ID
- client_algo_id (TEXT): Our unique tracking ID
- hunt_session_id (UUID): Links to hunt session
- oms_order_id (UUID): Links to OMS queue
- symbol (TEXT): Trading pair (e.g., BTCUSDT)
- side (TEXT): BUY or SELL
- total_quantity (NUMERIC): Total order size
- duration_seconds (INT): Execution duration (300-86400s)
- limit_price (NUMERIC): Optional price limit
- executed_quantity (NUMERIC): Amount filled
- executed_amount (NUMERIC): USD value executed
- avg_price (NUMERIC): Average execution price
- algo_status (TEXT): WORKING | FINISHED | CANCELLED | ERROR
- urgency (TEXT): LOW | MEDIUM | HIGH
twap_sub_orders Table
Tracks individual sub-order executions:
- twap_order_id (UUID): Parent TWAP order
- sub_id (INT): Sub-order index
- order_id (BIGINT): Binance order ID
- executed_quantity (NUMERIC): Sub-order fill
- avg_price (NUMERIC): Sub-order price
- fee_amount (NUMERIC): Trading fee
- order_status (TEXT): Fill status
π§ Configuration
Hunt Session TWAP Settings
// hunt_sessions table
twap_threshold_usd: 500 // Orders β₯ $500 use TWAP
twap_duration_seconds: 600 // 10 minutes default
Customize Per Hunt
const huntConfig = {
minVolatility: 2.0,
minVolume: 100000,
maxTargets: 5,
scanInterval: 300,
twapThreshold: 500, // USD threshold
twapDuration: 600, // 10 minutes
};
π Edge Functions
binance-algo-twap
Handles Binance Algo Trading API interaction:
Actions:
place- Create new TWAP order{ action: 'place', symbol: 'BTCUSDT', side: 'BUY', quantity: 0.05, duration: 600, limitPrice: 43000, // optional huntSessionId: 'uuid', }sync- Fetch execution status{ action: 'sync', twapOrderId: 'uuid', }cancel- Cancel active TWAP order{ action: 'cancel', twapOrderId: 'uuid', }
π Monitoring
TWAP Monitor Component
Real-time dashboard showing:
- Active TWAP orders with live progress bars
- Fill percentage (quantity executed / total)
- Time progress (elapsed / total duration)
- Average execution price
- Remaining time countdown
- Recent completed orders
Access via: Markets page β Hunt tab β TWAP Monitor panel
π‘ Benefits
Why TWAP?
Reduced Slippage
- Breaks large orders into smaller pieces
- Avoids moving the market with big orders
- Better average fill price
Smart Execution
- Time-weighted distribution
- Adapts to market conditions
- Matches liquidity patterns
Market Impact Minimization
- $1000 order in 1 shot β High impact
- $1000 order over 10min β Low impact
- Preserves opportunity profitability
Professional Grade
- Same tools used by institutional traders
- Binance Algo Trading infrastructure
- Sub-order tracking and analytics
π Security
API Requirements
# Required Binance API permissions:
- Spot Trading: ENABLED
- Algo Trading: ENABLED
- Withdrawals: DISABLED (security)
# Required secrets:
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_api_secret
RLS Policies
- Users can only view their own TWAP orders
- Orders linked via
hunt_session_id β user_id - Service role manages all TWAP operations
- Sub-orders inherit parent order permissions
π Usage Example
Automated Hunt with TWAP
// 1. Start hunt session
await startHunt({
minVolatility: 3.0,
minVolume: 200000,
maxTargets: 3,
scanInterval: 300,
twapThreshold: 500, // Use TWAP for orders β₯ $500
twapDuration: 900, // Execute over 15 minutes
});
// 2. System automatically:
// - Scans markets
// - Generates QGITA signals
// - Routes large orders to TWAP
// - Routes small orders to OMS
// - Tracks all executions
// 3. Monitor via UI:
// - Hunt Control: Shows scan stats
// - TWAP Monitor: Shows active TWAPs
// - OMS Monitor: Shows queued orders
ποΈ Tuning Guidelines
TWAP Duration
Short Duration (5-10 min):
- Fast markets
- High urgency
- Smaller orders ($500-$2000)
Medium Duration (10-30 min):
- Normal conditions
- Medium orders ($2000-$10000)
- Balanced execution
Long Duration (30min-24hr):
- Slow markets
- Very large orders ($10000+)
- Maximum slippage reduction
Threshold Optimization
Conservative (β₯ $1000):
- Only use TWAP for truly large orders
- Most orders via OMS
- Lower API usage
Aggressive (β₯ $200):
- More orders via TWAP
- Better average prices
- Higher API usage
Default ($500):
- Balanced approach
- Good for most use cases
π Integration Flow
PRIDE SCANNER
β
Identifies: BTCUSDT, $800 value, 15% volatility
β
QGITA SIGNAL GENERATOR
β
Generates: BUY signal, Tier 1, 85% confidence
β
ORDER ROUTER (automated-hunt-loop)
β
Checks: $800 β₯ $500 threshold?
β
YES β TWAP Execution
β
binance-algo-twap edge function
β
Binance API: POST /sapi/v1/algo/spot/newOrderTwap
β
- Breaks into 10 sub-orders
- Executes over 10 minutes
- Records to twap_orders table
β
TWAP Monitor UI
β
Real-time progress updates every 5 seconds
π§ͺ Testing
Testnet TWAP
# Enable testnet mode
export BINANCE_TESTNET=true
# Start hunt with TWAP
npm run lion:hunt
# Monitor logs for TWAP execution
# Look for: "π BTCUSDT using TWAP: $800.00"
Verify TWAP Order
-- Check active TWAP orders
SELECT
symbol,
side,
total_quantity,
executed_quantity,
algo_status,
duration_seconds
FROM twap_orders
WHERE algo_status = 'WORKING'
ORDER BY created_at DESC;
-- Check sub-orders
SELECT
sub_id,
executed_quantity,
avg_price,
order_status
FROM twap_sub_orders
WHERE twap_order_id = 'your_order_id'
ORDER BY sub_id;
π API Reference
See docs/BINANCE_ALGO_API_REFERENCE.txt for complete Binance Algo Trading API documentation.
Key Endpoints Used
POST
/sapi/v1/algo/spot/newOrderTwap- Weight: 3000 (UID)
- Creates new TWAP order
GET
/sapi/v1/algo/spot/subOrders- Weight: 1 (IP)
- Fetches sub-order execution details
DELETE
/sapi/v1/algo/spot/order- Weight: 1 (IP)
- Cancels active TWAP order
π― Next Steps
- Test on Testnet: Verify TWAP execution with small amounts
- Monitor Performance: Track slippage vs standard orders
- Tune Parameters: Adjust threshold and duration based on results
- Scale Up: Increase thresholds as confidence grows
β οΈ Important Notes
- Max 20 concurrent TWAP orders (Binance limit)
- Min duration: 5 minutes (300 seconds)
- Max duration: 24 hours (86400 seconds)
- Max notional: Varies by symbol (200k-10mm)
- TWAP orders can't be modified, only cancelled
π Support
For issues or questions:
- Check edge function logs:
supabase functions logs binance-algo-twap - Review TWAP orders table:
SELECT * FROM twap_orders ORDER BY created_at DESC - Binance API errors: Check
error_codeanderror_messagecolumns
π¦ THE LION HUNTS WITH INTELLIGENCE ππ
Last Updated: November 22, 2025 Version: 1.0.0 Status: OPERATIONAL β