Add start and enddate when fetching the position history

This commit is contained in:
2025-10-24 18:00:23 +07:00
parent 554cac7d89
commit fc4369a008
10 changed files with 352 additions and 32 deletions

View File

@@ -0,0 +1,72 @@
#!/bin/bash
# Test Position History API with Date Filtering
# Based on get-position-history.test.ts
# Configuration
BASE_URL="http://localhost:4111"
ACCOUNT="0xb54a2f65D79bDeD20F9cBd9a1F85C3855EC3c210"
# Calculate dates (last 1 hour)
TO_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
FROM_DATE=$(date -u -v-1H +"%Y-%m-%dT%H:%M:%S.000Z" 2>/dev/null || date -u -d "1 hour ago" +"%Y-%m-%dT%H:%M:%S.000Z")
echo "================================================"
echo "Testing GMX Position History API"
echo "================================================"
echo ""
# Example 1: Get all positions (no date filter)
echo "📊 Example 1: Get all positions (no date filter)"
echo "Command:"
echo "curl -X GET \"${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=20\""
echo ""
curl -X GET "${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=20" \
-H "Content-Type: application/json" \
| jq '.'
echo ""
echo "================================================"
echo ""
# Example 2: Get positions with date range filter
echo "📅 Example 2: Get positions from last 1 hour with date filter"
echo "From: ${FROM_DATE}"
echo "To: ${TO_DATE}"
echo ""
echo "Command:"
echo "curl -X GET \"${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=10&fromDateTime=${FROM_DATE}&toDateTime=${TO_DATE}\""
echo ""
curl -X GET "${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=10&fromDateTime=$(echo $FROM_DATE | sed 's/:/%3A/g')&toDateTime=$(echo $TO_DATE | sed 's/:/%3A/g')" \
-H "Content-Type: application/json" \
| jq '.'
echo ""
echo "================================================"
echo ""
# Example 3: Get positions with ticker filter
echo "🎯 Example 3: Get positions for specific ticker (HYPE)"
echo "Command:"
echo "curl -X GET \"${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=10&ticker=HYPE\""
echo ""
curl -X GET "${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=10&ticker=HYPE" \
-H "Content-Type: application/json" \
| jq '.'
echo ""
echo "================================================"
echo ""
# Example 4: Get positions with date range AND ticker filter
echo "🎯📅 Example 4: Get positions for HYPE ticker in last 1 hour"
echo "From: ${FROM_DATE}"
echo "To: ${TO_DATE}"
echo "Ticker: HYPE"
echo ""
echo "Command:"
echo "curl -X GET \"${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=10&ticker=HYPE&fromDateTime=${FROM_DATE}&toDateTime=${TO_DATE}\""
echo ""
curl -X GET "${BASE_URL}/api/gmx/position-history?account=${ACCOUNT}&pageIndex=0&pageSize=10&ticker=HYPE&fromDateTime=$(echo $FROM_DATE | sed 's/:/%3A/g')&toDateTime=$(echo $TO_DATE | sed 's/:/%3A/g')" \
-H "Content-Type: application/json" \
| jq '.'
echo ""
echo "================================================"