feat: Add on-chain TP/SL order placement
- Add placeExitOrders() to create reduce-only LIMIT orders for TP1, TP2, and SL - Orders now visible in Drift UI - Tested with real tiny position (0 base x 5x = 0) - All 3 exit orders placed successfully on-chain - Position manager continues monitoring as backup - Added test script and results documentation
This commit is contained in:
73
test-exit-orders.sh
Executable file
73
test-exit-orders.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
# Test script to execute a tiny trade and verify exit orders are placed on-chain
|
||||
|
||||
echo "🧪 Testing exit order placement with tiny position..."
|
||||
echo "📊 Current settings:"
|
||||
echo " Position: \$10 (base)"
|
||||
echo " Leverage: 5x"
|
||||
echo " Notional: \$50"
|
||||
echo ""
|
||||
|
||||
# API endpoint and credentials
|
||||
API_URL="http://localhost:3001/api/trading/execute"
|
||||
API_KEY="2a344f0149442c857fb56c038c0c7d1b113883b830bec792c76f1e0efa15d6bb"
|
||||
|
||||
# Trade request payload
|
||||
PAYLOAD='{
|
||||
"symbol": "SOLUSDT",
|
||||
"direction": "long",
|
||||
"timeframe": "5",
|
||||
"signalStrength": "strong"
|
||||
}'
|
||||
|
||||
echo "🚀 Sending trade execution request..."
|
||||
echo ""
|
||||
|
||||
# Execute the request
|
||||
RESPONSE=$(curl -s -X POST "$API_URL" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-d "$PAYLOAD")
|
||||
|
||||
echo "📨 Response:"
|
||||
echo "$RESPONSE" | jq '.' 2>/dev/null || echo "$RESPONSE"
|
||||
echo ""
|
||||
|
||||
# Check if successful
|
||||
if echo "$RESPONSE" | jq -e '.success' > /dev/null 2>&1; then
|
||||
echo "✅ Trade executed successfully!"
|
||||
|
||||
# Extract signatures
|
||||
POSITION_ID=$(echo "$RESPONSE" | jq -r '.positionId')
|
||||
EXIT_SIGS=$(echo "$RESPONSE" | jq -r '.exitOrderSignatures[]?' 2>/dev/null)
|
||||
|
||||
echo ""
|
||||
echo "📝 Transaction details:"
|
||||
echo " Entry TX: $POSITION_ID"
|
||||
|
||||
if [ -n "$EXIT_SIGS" ]; then
|
||||
echo " Exit orders placed:"
|
||||
echo "$EXIT_SIGS" | while read -r sig; do
|
||||
echo " - $sig"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "🔍 Verify on Drift:"
|
||||
echo " https://app.drift.trade/"
|
||||
echo ""
|
||||
echo "🔍 Verify on Solscan:"
|
||||
echo "$EXIT_SIGS" | while read -r sig; do
|
||||
echo " https://solscan.io/tx/$sig"
|
||||
done
|
||||
else
|
||||
echo " ⚠️ No exit order signatures in response"
|
||||
fi
|
||||
else
|
||||
echo "❌ Trade execution failed!"
|
||||
ERROR=$(echo "$RESPONSE" | jq -r '.error // .message')
|
||||
echo " Error: $ERROR"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📊 Check container logs for details:"
|
||||
echo " docker logs trading-bot-v4 --tail 100"
|
||||
Reference in New Issue
Block a user