-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapitest.http
More file actions
527 lines (441 loc) · 13.2 KB
/
apitest.http
File metadata and controls
527 lines (441 loc) · 13.2 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
###############################################################################
# Quicksilver API 测试用例
#
# 使用说明:
# 1. 在 VS Code 中安装 REST Client 扩展
# 2. 确保服务运行在 http://localhost:8080
# 3. 点击请求上方的 "Send Request" 执行测试
# 4. 私有接口测试前需先设置有效的 API Key
#
# 测试顺序:
# 1. 公开接口测试 (无需认证)
# 2. 用户认证设置
# 3. 私有接口测试 (需要认证)
###############################################################################
@baseUrl = http://localhost:8080
@apiKey = qs-test-api-key-2024
@apiSecret = qs-test-api-secret-change-in-production
###############################################################################
# 1. 健康检查和基础接口
###############################################################################
### 1.1 健康检查
# @name healthCheck
GET {{baseUrl}}/health HTTP/1.1
### 1.2 Ping - 测试服务响应
# @name ping
GET {{baseUrl}}/v1/ping HTTP/1.1
### 1.3 获取服务器时间
# @name serverTime
GET {{baseUrl}}/v1/time HTTP/1.1
###############################################################################
# 2. 市场数据接口 (公开)
###############################################################################
### 2.1 获取所有交易对
# @name getMarkets
GET {{baseUrl}}/v1/markets HTTP/1.1
### 2.2 获取 BTC/USDT 行情 (正常情况)
# @name getTickerBTC
GET {{baseUrl}}/v1/ticker/BTC/USDT HTTP/1.1
### 2.3 获取 BTC-USDT 行情 (使用短横线格式)
# @name getTickerBTCDash
GET {{baseUrl}}/v1/ticker/BTC-USDT HTTP/1.1
### 2.4 获取 ETH/USDT 行情
# @name getTickerETH
GET {{baseUrl}}/v1/ticker/ETH/USDT HTTP/1.1
### 2.5 获取不存在的交易对 (应返回 404)
# @name getTickerNotFound
GET {{baseUrl}}/v1/ticker/INVALID/PAIR HTTP/1.1
### 2.6 获取 BTC/USDT 最近成交
# @name getTradesBTC
GET {{baseUrl}}/v1/trades/BTC/USDT HTTP/1.1
### 2.7 获取 ETH/USDT 最近成交
# @name getTradesETH
GET {{baseUrl}}/v1/trades/ETH-USDT HTTP/1.1
### 2.8 获取不存在交易对的成交记录 (应返回空数组)
# @name getTradesNotFound
GET {{baseUrl}}/v1/trades/INVALID/PAIR HTTP/1.1
###############################################################################
# 3. 用户认证接口 (私有)
###############################################################################
### 3.1 获取余额 - 无认证头 (应返回 401)
# @name getBalanceUnauthorized
GET {{baseUrl}}/v1/balance HTTP/1.1
### 3.2 获取余额 - 有效认证
# @name getBalance
GET {{baseUrl}}/v1/balance HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 3.3 获取余额 - 无效 API Key (应返回 401)
# @name getBalanceInvalidKey
GET {{baseUrl}}/v1/balance HTTP/1.1
X-API-Key: invalid-key
X-API-Secret: invalid-secret
###############################################################################
# 4. 订单管理接口 (私有)
###############################################################################
### 4.1 创建市价买单 - 无认证 (应返回 401)
# @name createOrderUnauthorized
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": 0.01
}
### 4.2 创建市价买单
# @name createMarketBuyOrder
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": 0.01,
"client_order_id": "test-market-buy-001"
}
### 4.3 创建市价卖单
# @name createMarketSellOrder
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "sell",
"type": "market",
"amount": 0.01,
"client_order_id": "test-market-sell-001"
}
### 4.4 创建限价买单
# @name createLimitBuyOrder
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"price": 50000.00,
"amount": 0.01,
"client_order_id": "test-limit-buy-001"
}
### 4.5 创建限价卖单
# @name createLimitSellOrder
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "ETH/USDT",
"side": "sell",
"type": "limit",
"price": 3000.00,
"amount": 0.1,
"client_order_id": "test-limit-sell-001"
}
### 4.6 创建订单 - 缺少必填字段 (应返回 400)
# @name createOrderInvalidRequest
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy"
}
### 4.7 创建订单 - 无效的交易对 (应返回 400)
# @name createOrderInvalidSymbol
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "INVALID/PAIR",
"side": "buy",
"type": "market",
"amount": 0.01
}
### 4.8 创建订单 - 无效的订单方向 (应返回 400)
# @name createOrderInvalidSide
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "invalid",
"type": "market",
"amount": 0.01
}
### 4.9 创建订单 - 数量为负数 (应返回 400)
# @name createOrderNegativeAmount
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": -0.01
}
### 4.10 获取订单详情 - 订单 ID: 1
# @name getOrder
GET {{baseUrl}}/v1/order/1 HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 4.11 获取订单详情 - 不存在的订单 (应返回 404)
# @name getOrderNotFound
GET {{baseUrl}}/v1/order/99999 HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 4.12 获取订单详情 - 无效的订单 ID (应返回 400)
# @name getOrderInvalidID
GET {{baseUrl}}/v1/order/invalid HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 4.13 撤销订单 - 订单 ID: 1
# @name cancelOrder
DELETE {{baseUrl}}/v1/order/1 HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 4.14 撤销订单 - 不存在的订单 (应返回 404)
# @name cancelOrderNotFound
DELETE {{baseUrl}}/v1/order/99999 HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 4.15 获取所有订单列表
# @name getOrders
GET {{baseUrl}}/v1/orders HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 4.16 获取未完成订单列表
# @name getOpenOrders
GET {{baseUrl}}/v1/orders/open HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
###############################################################################
# 5. 交易历史接口 (私有)
###############################################################################
### 5.1 获取我的成交记录
# @name getMyTrades
GET {{baseUrl}}/v1/myTrades HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 5.2 获取我的成交记录 - 无认证 (应返回 401)
# @name getMyTradesUnauthorized
GET {{baseUrl}}/v1/myTrades HTTP/1.1
###############################################################################
# 6. 边界测试和压力测试
###############################################################################
### 6.1 测试超长交易对名称
# @name getLongSymbol
GET {{baseUrl}}/v1/ticker/VERYLONGSYMBOLNAMETHATEXCEEDSLIMIT/USDT HTTP/1.1
### 6.2 测试特殊字符
# @name getSpecialChars
GET {{baseUrl}}/v1/ticker/BTC%2FUSDT HTTP/1.1
### 6.3 创建订单 - 数量为 0 (应返回 400)
# @name createOrderZeroAmount
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": 0
}
### 6.4 创建订单 - 极小数量
# @name createOrderMinAmount
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": 0.00000001
}
### 6.5 创建订单 - 极大数量
# @name createOrderMaxAmount
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": 999999999.99999999
}
### 6.6 创建限价单 - 价格为 0 (应返回 400)
# @name createLimitOrderZeroPrice
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"price": 0,
"amount": 0.01
}
### 6.7 创建限价单 - 缺少价格 (应返回 400)
# @name createLimitOrderNoPrice
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"amount": 0.01
}
###############################################################################
# 7. CCXT 兼容性测试
###############################################################################
### 7.1 获取行情 - 验证 CCXT 格式响应字段
# 预期包含: symbol, timestamp, datetime, last, bid, ask, high, low, volume 等字段
# @name ccxtTickerFormat
GET {{baseUrl}}/v1/ticker/BTC/USDT HTTP/1.1
### 7.2 获取余额 - 验证 CCXT 格式
# 预期返回: { "asset": "USDT", "available": 0.0, "locked": 0.0 } 等
# @name ccxtBalanceFormat
GET {{baseUrl}}/v1/balance HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 7.3 创建订单 - 验证 CCXT 响应格式
# 预期返回包含: id, clientOrderId, timestamp, symbol, type, side, price, amount, status 等
# @name ccxtOrderFormat
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"price": 50000.00,
"amount": 0.01,
"client_order_id": "ccxt-test-001"
}
###############################################################################
# 8. 并发测试场景
###############################################################################
### 8.1 连续创建多个订单
# @name concurrentOrder1
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"price": 49000.00,
"amount": 0.01,
"client_order_id": "concurrent-test-001"
}
### 8.2 连续创建多个订单
# @name concurrentOrder2
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"price": 48000.00,
"amount": 0.01,
"client_order_id": "concurrent-test-002"
}
### 8.3 连续创建多个订单
# @name concurrentOrder3
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "limit",
"price": 47000.00,
"amount": 0.01,
"client_order_id": "concurrent-test-003"
}
###############################################################################
# 9. 错误处理测试
###############################################################################
### 9.1 无效的 Content-Type (应返回 400 或正常处理)
# @name invalidContentType
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: text/plain
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market",
"amount": 0.01
}
### 9.2 发送空 Body (应返回 400)
# @name emptyBody
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 9.3 发送格式错误的 JSON (应返回 400)
# @name malformedJSON
POST {{baseUrl}}/v1/order HTTP/1.1
Content-Type: application/json
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
{
"symbol": "BTC/USDT",
"side": "buy",
"type": "market"
"amount": 0.01
### 9.4 使用 GET 方法访问 POST 端点 (应返回 405)
# @name methodNotAllowed
GET {{baseUrl}}/v1/order HTTP/1.1
X-API-Key: {{apiKey}}
X-API-Secret: {{apiSecret}}
### 9.5 访问不存在的路由 (应返回 404)
# @name notFoundRoute
GET {{baseUrl}}/v1/nonexistent HTTP/1.1
###############################################################################
# 10. 性能测试提示
###############################################################################
# 注意: 以下测试需要使用专门的性能测试工具执行
# 推荐使用: Apache Bench (ab), wrk, 或 k6
# 10.1 行情接口吞吐量测试
# ab -n 10000 -c 100 http://localhost:8080/v1/ticker/BTC/USDT
# 10.2 订单创建压力测试
# wrk -t12 -c400 -d30s --script=order-create.lua http://localhost:8080/v1/order
# 10.3 查询接口延迟测试
# k6 run --vus 100 --duration 30s load-test.js
###############################################################################
# 测试用例结束
# 总计: 60+ 个测试场景
#
# 测试覆盖:
# ✅ 健康检查
# ✅ 公开市场数据接口
# ✅ 用户认证
# ✅ 订单管理 (CRUD)
# ✅ 交易历史
# ✅ 边界条件
# ✅ 错误处理
# ✅ CCXT 兼容性
# ✅ 并发场景
# ✅ 性能测试指引
###############################################################################