-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.ps1
More file actions
121 lines (109 loc) · 4.04 KB
/
test-api.ps1
File metadata and controls
121 lines (109 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# DEX API 테스트 스크립트
Write-Host "=== DEX API 테스트 시작 ===" -ForegroundColor Green
Write-Host ""
# 1. 헬스 체크
Write-Host "1. 헬스 체크..." -ForegroundColor Cyan
try {
$health = Invoke-RestMethod -Uri "http://localhost:3001/health" -Method Get
Write-Host "✓ API 서버 정상" -ForegroundColor Green
$health | ConvertTo-Json
} catch {
Write-Host "✗ API 서버 연결 실패" -ForegroundColor Red
exit 1
}
Write-Host ""
# 2. 오더북 조회
Write-Host "2. 오더북 조회 (BTC-USDT)..." -ForegroundColor Cyan
try {
$orderbook = Invoke-RestMethod -Uri "http://localhost:3001/orders/open?marketId=1" -Method Get
Write-Host "✓ 오더북 조회 성공" -ForegroundColor Green
Write-Host "열린 주문 수: $($orderbook.orders.Count)"
} catch {
Write-Host "✗ 오더북 조회 실패: $_" -ForegroundColor Red
}
Write-Host ""
# 3. Alice 주문 내역 조회 (인증 테스트)
Write-Host "3. Alice 주문 내역 조회..." -ForegroundColor Cyan
try {
$headers = @{
"x-api-key" = "alice-test-api-key-123"
}
$aliceOrders = Invoke-RestMethod -Uri "http://localhost:3001/orders/history" -Method Get -Headers $headers
Write-Host "✓ 인증 성공" -ForegroundColor Green
Write-Host "Alice 주문 수: $($aliceOrders.orders.Count)"
} catch {
Write-Host "✗ 인증 실패: $_" -ForegroundColor Red
}
Write-Host ""
# 4. Alice SELL 주문 생성
Write-Host "4. Alice SELL 주문 생성 (0.1 BTC @ 50000 USDT)..." -ForegroundColor Cyan
try {
$headers = @{
"x-api-key" = "alice-test-api-key-123"
"Content-Type" = "application/json"
}
$sellOrder = @{
marketId = 1
side = "SELL"
orderType = "LIMIT"
amount = "0.1"
price = "50000"
} | ConvertTo-Json
$sellResult = Invoke-RestMethod -Uri "http://localhost:3001/orders" -Method Post -Headers $headers -Body $sellOrder
Write-Host "✓ SELL 주문 생성 성공" -ForegroundColor Green
Write-Host "주문 ID: $($sellResult.orderId)"
$sellOrderId = $sellResult.orderId
} catch {
Write-Host "✗ SELL 주문 생성 실패: $_" -ForegroundColor Red
Write-Host $_.Exception.Message
}
Write-Host ""
# 5초 대기
Write-Host "5. 매칭 대기 (5초)..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
# 6. Bob BUY 주문 생성 (자동 매칭!)
Write-Host "6. Bob BUY 주문 생성 (0.1 BTC @ 50000 USDT - 자동 매칭!)..." -ForegroundColor Cyan
try {
$headers = @{
"x-api-key" = "bob-test-api-key-456"
"Content-Type" = "application/json"
}
$buyOrder = @{
marketId = 1
side = "BUY"
orderType = "LIMIT"
amount = "0.1"
price = "50000"
} | ConvertTo-Json
$buyResult = Invoke-RestMethod -Uri "http://localhost:3001/orders" -Method Post -Headers $headers -Body $buyOrder
Write-Host "✓ BUY 주문 생성 성공" -ForegroundColor Green
Write-Host "주문 ID: $($buyResult.orderId)"
} catch {
Write-Host "✗ BUY 주문 생성 실패: $_" -ForegroundColor Red
Write-Host $_.Exception.Message
}
Write-Host ""
# 7. 체결 내역 확인
Write-Host "7. 최근 체결 내역 확인..." -ForegroundColor Cyan
Start-Sleep -Seconds 2
try {
$trades = Invoke-RestMethod -Uri "http://localhost:3001/trades/recent?limit=5" -Method Get
Write-Host "✓ 체결 내역 조회 성공" -ForegroundColor Green
Write-Host "최근 체결 수: $($trades.trades.Count)"
if ($trades.trades.Count -gt 0) {
Write-Host "`n최근 체결:" -ForegroundColor Yellow
foreach ($trade in $trades.trades) {
Write-Host " - Trade ID: $($trade.id)"
Write-Host " 가격: $($trade.price) USDT"
Write-Host " 수량: $($trade.amount) BTC"
Write-Host " 상태: $($trade.status)"
if ($trade.txid) {
Write-Host " TX ID: $($trade.txid)"
}
}
}
} catch {
Write-Host "✗ 체결 내역 조회 실패: $_" -ForegroundColor Red
}
Write-Host ""
Write-Host "=== 테스트 완료 ===" -ForegroundColor Green