@michaleffffff/mcp-trading-server 3.0.3 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +48 -408
  3. package/TOOL_EXAMPLES.md +63 -555
  4. package/dist/prompts/tradingGuide.js +16 -19
  5. package/dist/server.js +20 -2
  6. package/dist/services/balanceService.js +4 -4
  7. package/dist/services/marketService.js +48 -12
  8. package/dist/services/tradeService.js +33 -10
  9. package/dist/tools/accountInfo.js +1 -82
  10. package/dist/tools/accountTransfer.js +91 -5
  11. package/dist/tools/adjustMargin.js +1 -1
  12. package/dist/tools/cancelOrders.js +71 -0
  13. package/dist/tools/checkAccountReady.js +69 -0
  14. package/dist/tools/checkApproval.js +1 -1
  15. package/dist/tools/closeAllPositions.js +12 -12
  16. package/dist/tools/closePosition.js +60 -12
  17. package/dist/tools/createPerpMarket.js +1 -1
  18. package/dist/tools/executeTrade.js +6 -6
  19. package/dist/tools/findPool.js +26 -0
  20. package/dist/tools/getAccountSnapshot.js +41 -0
  21. package/dist/tools/getAllTickers.js +5 -4
  22. package/dist/tools/getBaseDetail.js +1 -1
  23. package/dist/tools/getKline.js +7 -4
  24. package/dist/tools/getMyLpHoldings.js +3 -2
  25. package/dist/tools/getNetworkFee.js +1 -1
  26. package/dist/tools/getOrders.js +46 -0
  27. package/dist/tools/getPoolMetadata.js +83 -0
  28. package/dist/tools/getPositionsAll.js +80 -0
  29. package/dist/tools/{getMarketPrice.js → getPrice.js} +8 -5
  30. package/dist/tools/getUserTradingFeeRate.js +1 -1
  31. package/dist/tools/index.js +15 -19
  32. package/dist/tools/listPools.js +53 -0
  33. package/dist/tools/manageLiquidity.js +10 -5
  34. package/dist/tools/manageTpSl.js +163 -0
  35. package/dist/tools/openPositionSimple.js +22 -5
  36. package/dist/tools/searchTools.js +35 -0
  37. package/dist/utils/mappings.js +10 -7
  38. package/dist/utils/slippage.js +23 -0
  39. package/package.json +1 -1
  40. package/dist/tools/cancelAllOrders.js +0 -57
  41. package/dist/tools/cancelOrder.js +0 -22
  42. package/dist/tools/getAccountVipInfo.js +0 -20
  43. package/dist/tools/getKlineLatestBar.js +0 -28
  44. package/dist/tools/getOraclePrice.js +0 -22
  45. package/dist/tools/getPoolList.js +0 -17
  46. package/dist/tools/getPoolSymbolAll.js +0 -16
  47. package/dist/tools/getPositions.js +0 -77
  48. package/dist/tools/marketInfo.js +0 -72
  49. package/dist/tools/orderQueries.js +0 -51
  50. package/dist/tools/poolConfig.js +0 -22
  51. package/dist/tools/positionHistory.js +0 -28
  52. package/dist/tools/searchMarket.js +0 -21
  53. package/dist/tools/setTpSl.js +0 -50
  54. package/dist/tools/updateOrderTpSl.js +0 -34
package/TOOL_EXAMPLES.md CHANGED
@@ -1,53 +1,14 @@
1
- # MYX MCP Tool Examples Handbook
1
+ # MYX MCP Tool Examples Handbook (v3.0.4)
2
2
 
3
- This handbook is designed for AI assistants and integrators.
4
- It includes:
5
- - clear parameter unit rules,
6
- - common end-to-end workflows,
7
- - at least one practical call example for every exposed tool.
8
-
9
- > All examples use MCP call payload shape:
10
- > `{ "name": "<tool_name>", "arguments": { ... } }`
11
-
12
- ---
13
-
14
- ## 1) Parameter Units & Precision (Important)
15
-
16
- - **Human-readable by default** (many trading tools): `"100"` means 100 quote tokens (e.g., USDC).
17
- - **Raw-unit override**: use `"raw:<integer>"` when supported by the tool.
18
- - **Price precision**: many low-level trading paths expect **30-decimal raw price**.
19
- - **Token amount precision**: depends on token decimals (e.g., USDC often 6).
20
- - **Slippage (`slippagePct`)**: 4-decimal integer style (e.g., `100 = 1%`, `50 = 0.5%`).
21
- - **Approval tool** (`check_approval`) uses **raw integer amount**.
3
+ This guide provides practical payload examples for the consolidated toolset.
4
+ All examples follow the MCP format: `{ "name": "...", "arguments": { ... } }`.
22
5
 
23
6
  ---
24
7
 
25
- ## 2) Common Operation Flows
8
+ ## 🟢 Trading Operations
26
9
 
27
- ## Flow A: Discover Market → Open Position (Recommended)
28
- 1. `search_market` (keyword or empty keyword list)
29
- 2. `get_market_detail` / `get_market_price`
30
- 3. `get_account` (with `poolId`)
31
- 4. `open_position_simple` (preferred high-level execution)
32
-
33
- ## Flow B: Limit Order Lifecycle
34
- 1. `execute_trade` with `orderType=LIMIT`
35
- 2. `get_open_orders`
36
- 3. `get_order_history`
37
- 4. `cancel_order` or `cancel_all_orders`
38
-
39
- ## Flow C: Balance Troubleshooting
40
- 1. `get_account` (without `poolId`) → wallet view
41
- 2. `get_account` (with `poolId`) → trading-account + margin
42
- 3. `account_deposit` / `account_withdraw` as needed
43
-
44
- ---
45
-
46
- ## 3) Tool-by-Tool Practical Examples
47
-
48
- ## Trading Operations
49
-
50
- ### `open_position_simple`
10
+ ### `open_position_simple` (Recommended)
11
+ High-level tool that computes size and fees automatically.
51
12
  ```json
52
13
  {
53
14
  "name": "open_position_simple",
@@ -55,575 +16,122 @@ It includes:
55
16
  "keyword": "BTC",
56
17
  "direction": "LONG",
57
18
  "collateralAmount": "100",
58
- "leverage": 5,
59
- "orderType": "MARKET",
60
- "autoDeposit": false,
61
- "dryRun": true
19
+ "leverage": 10,
20
+ "tpPrice": "75000",
21
+ "slPrice": "62000"
62
22
  }
63
23
  }
64
24
  ```
65
25
 
66
- ### `execute_trade`
26
+ ### `cancel_orders` (Unified)
27
+ Supports three modes: single ID, all in a pool, or all in account.
67
28
  ```json
29
+ // Mode 1: Specific IDs
68
30
  {
69
- "name": "execute_trade",
70
- "arguments": {
71
- "poolId": "0xPOOL_ID",
72
- "positionId": "",
73
- "orderType": "MARKET",
74
- "direction": "LONG",
75
- "collateralAmount": "100",
76
- "size": "0.01",
77
- "price": "65000",
78
- "timeInForce": 0,
79
- "postOnly": false,
80
- "slippagePct": "100",
81
- "executionFeeToken": "0xQUOTE_TOKEN",
82
- "leverage": 5,
83
- "marketId": "0xMARKET_ID"
84
- }
85
- }
86
- ```
87
- Notes:
88
- - `tradingFee` is optional (auto-computed if omitted).
89
- - Amount-like fields support `human:` and `raw:` prefixes.
90
- - `positionId: "0x000...000"` is auto-treated as a new position.
91
-
92
- ### `close_position`
93
- ```json
94
- {
95
- "name": "close_position",
96
- "arguments": {
97
- "poolId": "0xPOOL_ID",
98
- "positionId": "0xPOSITION_ID",
99
- "orderType": "MARKET",
100
- "direction": "LONG",
101
- "collateralAmount": "0",
102
- "size": "0.01",
103
- "price": "65000",
104
- "timeInForce": 0,
105
- "postOnly": false,
106
- "slippagePct": "100",
107
- "executionFeeToken": "0xQUOTE_TOKEN",
108
- "leverage": 5
109
- }
110
- }
111
- ```
112
-
113
- ### `close_all_positions`
114
- ```json
115
- {
116
- "name": "close_all_positions",
117
- "arguments": {
118
- "poolId": "0xPOOL_ID",
119
- "slippagePct": "200"
120
- }
31
+ "name": "cancel_orders",
32
+ "arguments": { "orderIds": ["0x123...", "0x456..."] }
121
33
  }
122
- ```
123
34
 
124
- ### `cancel_order`
125
- ```json
35
+ // Mode 2: Pool-wide
126
36
  {
127
- "name": "cancel_order",
128
- "arguments": {
129
- "orderId": "0xORDER_ID"
130
- }
37
+ "name": "cancel_orders",
38
+ "arguments": { "poolId": "BTC" }
131
39
  }
132
- ```
133
40
 
134
- ### `cancel_all_orders`
135
- ```json
41
+ // Mode 3: Global
136
42
  {
137
- "name": "cancel_all_orders",
138
- "arguments": {
139
- "orderIds": [
140
- "0xORDER_ID_1",
141
- "0xORDER_ID_2"
142
- ]
143
- }
144
- }
145
- ```
146
- Single-ID string is also accepted:
147
- ```json
148
- {
149
- "name": "cancel_all_orders",
150
- "arguments": {
151
- "orderIds": "0xORDER_ID_1"
152
- }
43
+ "name": "cancel_orders",
44
+ "arguments": { "cancelAll": true }
153
45
  }
154
46
  ```
155
47
 
156
- ### `set_tp_sl`
48
+ ### `manage_tp_sl`
49
+ Update existing protection orders or set new ones for a position.
157
50
  ```json
158
51
  {
159
- "name": "set_tp_sl",
52
+ "name": "manage_tp_sl",
160
53
  "arguments": {
161
- "poolId": "0xPOOL_ID",
162
- "positionId": "0xPOSITION_ID",
163
- "direction": "LONG",
54
+ "poolId": "BTC",
55
+ "positionId": "0xABC...",
164
56
  "leverage": 5,
165
- "executionFeeToken": "0xQUOTE_TOKEN",
166
- "tpTriggerType": "GTE",
167
- "tpPrice": "70000",
168
- "tpSize": "0.01",
169
- "slTriggerType": "LTE",
170
- "slPrice": "60000",
171
- "slSize": "0.01",
172
- "slippagePct": "100"
173
- }
174
- }
175
- ```
176
-
177
- ### `update_order_tp_sl`
178
- ```json
179
- {
180
- "name": "update_order_tp_sl",
181
- "arguments": {
182
- "orderId": "0xORDER_ID",
183
- "marketId": "0xMARKET_ID",
184
- "size": "0.01",
185
- "price": "65000",
186
- "tpPrice": "70000",
187
- "tpSize": "0.005",
188
- "slPrice": "60000",
189
- "slSize": "0.005",
190
- "useOrderCollateral": true,
191
- "quoteToken": "0xQUOTE_TOKEN"
192
- }
193
- }
194
- ```
195
- String booleans are also accepted:
196
- ```json
197
- {
198
- "name": "update_order_tp_sl",
199
- "arguments": {
200
- "orderId": "0xORDER_ID",
201
- "marketId": "0xMARKET_ID",
202
- "size": 0.01,
203
- "price": 65000,
204
- "tpPrice": 70000,
205
- "tpSize": 0.005,
206
- "slPrice": 60000,
207
- "slSize": 0.005,
208
- "useOrderCollateral": "true",
209
- "isTpSlOrder": "true",
210
- "quoteToken": "0xQUOTE_TOKEN"
211
- }
212
- }
213
- ```
214
- Note:
215
- - This tool is most reliable for existing TP/SL orders or open positions.
216
- - If an unfilled LIMIT/STOP order returns `Failed to update order`, wait for fill and use `set_tp_sl`.
217
-
218
- ### `adjust_margin`
219
- ```json
220
- {
221
- "name": "adjust_margin",
222
- "arguments": {
223
- "poolId": "0xPOOL_ID",
224
- "positionId": "0xPOSITION_ID",
225
- "adjustAmount": "1"
226
- }
227
- }
228
- ```
229
- Raw precision mode:
230
- ```json
231
- {
232
- "name": "adjust_margin",
233
- "arguments": {
234
- "poolId": "0xPOOL_ID",
235
- "positionId": "0xPOSITION_ID",
236
- "adjustAmount": "raw:1000000"
237
- }
238
- }
239
- ```
240
- Success payload includes normalized raw amount under `data.normalized.adjustAmountRaw`.
241
-
242
- ### `check_approval`
243
- ```json
244
- {
245
- "name": "check_approval",
246
- "arguments": {
247
- "amount": "100000000",
248
- "autoApprove": false
249
- }
250
- }
251
- ```
252
-
253
- ### `get_user_trading_fee_rate`
254
- ```json
255
- {
256
- "name": "get_user_trading_fee_rate",
257
- "arguments": {
258
- "assetClass": 1,
259
- "riskTier": 1
260
- }
261
- }
262
- ```
263
-
264
- ### `get_network_fee`
265
- ```json
266
- {
267
- "name": "get_network_fee",
268
- "arguments": {
269
- "marketId": "0xMARKET_ID"
270
- }
271
- }
272
- ```
273
-
274
- ## Market Data
275
-
276
- ### `search_market`
277
- ```json
278
- {
279
- "name": "search_market",
280
- "arguments": {
281
- "keyword": "ETH",
282
- "limit": 10
283
- }
284
- }
285
- ```
286
-
287
- ### `search_market` (list active markets)
288
- ```json
289
- {
290
- "name": "search_market",
291
- "arguments": {
292
- "keyword": "",
293
- "limit": 20
294
- }
295
- }
296
- ```
297
- Note: this tool may internally fallback to SDK `api.getMarketList()` / `api.getPoolList()` when direct search is empty.
298
-
299
- ### `get_pool_list`
300
- ```json
301
- {
302
- "name": "get_pool_list",
303
- "arguments": {}
304
- }
305
- ```
306
-
307
- ### `get_market_detail`
308
- ```json
309
- {
310
- "name": "get_market_detail",
311
- "arguments": {
312
- "poolId": "BTC"
313
- }
314
- }
315
- ```
316
-
317
- ### `get_pool_info`
318
- ```json
319
- {
320
- "name": "get_pool_info",
321
- "arguments": {
322
- "poolId": "0xPOOL_ID"
323
- }
324
- }
325
- ```
326
- Note: the server auto-retries with oracle/ticker market price when direct on-chain read hits divide-by-zero.
327
-
328
- ### `get_liquidity_info`
329
- ```json
330
- {
331
- "name": "get_liquidity_info",
332
- "arguments": {
333
- "poolId": "0xPOOL_ID",
334
- "marketPrice": "6500000000000000000000000000000000"
335
- }
336
- }
337
- ```
338
-
339
- ### `get_pool_level_config`
340
- ```json
341
- {
342
- "name": "get_pool_level_config",
343
- "arguments": {
344
- "poolId": "0xPOOL_ID"
345
- }
346
- }
347
- ```
348
-
349
- ### `get_market_price`
350
- ```json
351
- {
352
- "name": "get_market_price",
353
- "arguments": {
354
- "poolId": "0xPOOL_ID"
355
- }
356
- }
357
- ```
358
-
359
- ### `get_oracle_price`
360
- ```json
361
- {
362
- "name": "get_oracle_price",
363
- "arguments": {
364
- "poolId": "0xPOOL_ID"
365
- }
366
- }
367
- ```
368
-
369
- ### `get_kline`
370
- ```json
371
- {
372
- "name": "get_kline",
373
- "arguments": {
374
- "poolId": "0xPOOL_ID",
375
- "interval": "15m",
376
- "limit": 100
377
- }
378
- }
379
- ```
380
-
381
- ### `get_kline_latest_bar`
382
- ```json
383
- {
384
- "name": "get_kline_latest_bar",
385
- "arguments": {
386
- "poolId": "0xPOOL_ID",
387
- "interval": "1m"
388
- }
389
- }
390
- ```
391
-
392
- ### `get_all_tickers`
393
- ```json
394
- {
395
- "name": "get_all_tickers",
396
- "arguments": {}
397
- }
398
- ```
399
-
400
- ### `get_pool_symbol_all`
401
- ```json
402
- {
403
- "name": "get_pool_symbol_all",
404
- "arguments": {}
405
- }
406
- ```
407
-
408
- ### `get_base_detail`
409
- ```json
410
- {
411
- "name": "get_base_detail",
412
- "arguments": {
413
- "baseAddress": "0xBASE_TOKEN"
414
- }
415
- }
416
- ```
417
-
418
- ## Account & Query
419
-
420
- ### `get_account`
421
- ```json
422
- {
423
- "name": "get_account",
424
- "arguments": {
425
- "poolId": "0xPOOL_ID"
426
- }
427
- }
428
- ```
429
-
430
- If one section fails, check `data.meta.partial` and section-level `error` fields.
431
-
432
- ### `get_account` (wallet-only view)
433
- ```json
434
- {
435
- "name": "get_account",
436
- "arguments": {}
437
- }
438
- ```
439
-
440
- ### `get_my_lp_holdings`
441
- ```json
442
- {
443
- "name": "get_my_lp_holdings",
444
- "arguments": {}
445
- }
446
- ```
447
- LP asset naming rule in each item:
448
- - `baseLpAssetName`: `mBASE.QUOTE` (e.g. `mBTC.USDC`)
449
- - `quoteLpAssetName`: `mQUOTE.BASE` (e.g. `mUSDC.BTC`)
450
- Include zero-balance pools and optional filtering:
451
- ```json
452
- {
453
- "name": "get_my_lp_holdings",
454
- "arguments": {
455
- "includeZero": true,
456
- "poolIds": [
457
- "0xPOOL_ID_1",
458
- "0xPOOL_ID_2"
459
- ],
460
- "maxPools": 50
57
+ "tpPrice": "80000",
58
+ "slPrice": "55000"
461
59
  }
462
60
  }
463
61
  ```
464
62
 
465
- ### `get_positions`
466
- ```json
467
- {
468
- "name": "get_positions",
469
- "arguments": {}
470
- }
471
- ```
472
-
473
- ### `get_open_orders`
474
- ```json
475
- {
476
- "name": "get_open_orders",
477
- "arguments": {}
478
- }
479
- ```
63
+ ---
480
64
 
481
- ### `get_order_history`
482
- ```json
483
- {
484
- "name": "get_order_history",
485
- "arguments": {
486
- "poolId": "0xPOOL_ID",
487
- "limit": 20
488
- }
489
- }
490
- ```
65
+ ## 🔵 Market Data
491
66
 
492
- ### `get_position_history`
67
+ ### `find_pool`
68
+ Keyword or symbol based discovery.
493
69
  ```json
494
70
  {
495
- "name": "get_position_history",
496
- "arguments": {
497
- "poolId": "0xPOOL_ID",
498
- "limit": 20
499
- }
71
+ "name": "find_pool",
72
+ "arguments": { "keyword": "ETH" }
500
73
  }
501
74
  ```
502
75
 
503
- ### `get_trade_flow`
76
+ ### `get_price`
77
+ Unified price fetching.
504
78
  ```json
505
79
  {
506
- "name": "get_trade_flow",
507
- "arguments": {
508
- "limit": 20
80
+ "name": "get_price",
81
+ "arguments": {
82
+ "poolId": "0x...",
83
+ "priceType": "market"
509
84
  }
510
85
  }
511
86
  ```
512
87
 
513
- ### `get_account_vip_info`
88
+ ### `get_pool_metadata`
89
+ Detailed pool state (Fees, Liquidity, Open Interest).
514
90
  ```json
515
91
  {
516
- "name": "get_account_vip_info",
517
- "arguments": {}
518
- }
519
- ```
520
-
521
- ### `account_deposit`
522
- ```json
523
- {
524
- "name": "account_deposit",
525
- "arguments": {
526
- "amount": "100",
527
- "tokenAddress": "0xQUOTE_TOKEN"
528
- }
92
+ "name": "get_pool_metadata",
93
+ "arguments": { "poolId": "0x..." }
529
94
  }
530
95
  ```
531
96
 
532
- ### `account_withdraw`
533
- ```json
534
- {
535
- "name": "account_withdraw",
536
- "arguments": {
537
- "poolId": "0xPOOL_ID",
538
- "amount": "50",
539
- "isQuoteToken": true
540
- }
541
- }
542
- ```
97
+ ---
543
98
 
544
- ## Liquidity / LP
99
+ ## 🟡 Account & Portfolio
545
100
 
546
- ### `manage_liquidity`
101
+ ### `get_account_snapshot`
102
+ Unified overview. Includes wallet balances and VIP info.
547
103
  ```json
548
104
  {
549
- "name": "manage_liquidity",
550
- "arguments": {
551
- "action": "deposit",
552
- "poolType": "QUOTE",
553
- "poolId": "0xPOOL_ID",
554
- "amount": 100,
555
- "slippage": 0.01
556
- }
557
- }
558
- ```
559
- Alias action example (`remove` == `withdraw`):
560
- ```json
561
- {
562
- "name": "manage_liquidity",
563
- "arguments": {
564
- "action": "remove",
565
- "poolType": "BASE",
566
- "poolId": "0xPOOL_ID",
567
- "amount": 1.5,
568
- "slippage": 0.01
569
- }
570
- }
571
- ```
572
- If operation fails, check `error.message` for concrete reasons (for example `Insufficient Balance`) instead of generic `undefined`.
573
- `poolId` must be valid on the target `chainId`; if uncertain, resolve with `search_market` / `get_pool_list` first.
574
- Success response includes `data.lpAssetNames`:
575
- - `baseLpAssetName`: `mBASE.QUOTE` (e.g. `mBTC.USDC`)
576
- - `quoteLpAssetName`: `mQUOTE.BASE` (e.g. `mUSDC.BTC`)
577
- - `operatedLpAssetName`: LP asset name matching current `poolType`
578
- Example success payload (abridged):
579
- ```json
580
- {
581
- "status": "success",
582
- "data": {
583
- "confirmation": {
584
- "confirmed": true,
585
- "txHash": "0x..."
586
- },
587
- "lpAssetNames": {
588
- "baseSymbol": "BTC",
589
- "quoteSymbol": "USDC",
590
- "baseLpAssetName": "mBTC.USDC",
591
- "quoteLpAssetName": "mUSDC.BTC",
592
- "operatedPoolType": "QUOTE",
593
- "operatedLpAssetName": "mUSDC.BTC"
594
- }
595
- }
105
+ "name": "get_account_snapshot",
106
+ "arguments": { "poolId": "BTC" }
596
107
  }
597
108
  ```
598
109
 
599
- ### `get_lp_price`
110
+ ### `get_orders`
111
+ Unified list for both active (OPEN) and historical (HISTORY) orders.
600
112
  ```json
601
113
  {
602
- "name": "get_lp_price",
603
- "arguments": {
604
- "poolType": "QUOTE",
605
- "poolId": "0xPOOL_ID"
114
+ "name": "get_orders",
115
+ "arguments": {
116
+ "status": "ALL",
117
+ "limit": 10
606
118
  }
607
119
  }
608
120
  ```
609
121
 
610
- ### `create_perp_market`
122
+ ### `get_positions_all`
123
+ Current open positions and closed history.
611
124
  ```json
612
125
  {
613
- "name": "create_perp_market",
614
- "arguments": {
615
- "baseToken": "0xBASE_TOKEN",
616
- "marketId": "0xMARKET_CONFIG_HASH"
617
- }
126
+ "name": "get_positions_all",
127
+ "arguments": { "status": "OPEN" }
618
128
  }
619
129
  ```
620
130
 
621
131
  ---
622
132
 
623
- ## 4) Practical Tips for AI Agents
133
+ ## 💡 Important Rules
624
134
 
625
- - Always discover/validate `poolId` before mutation tools.
626
- - Prefer `open_position_simple` for new-position UX unless strict low-level control is required.
627
- - Before trading, call `get_account` and `check_approval`.
628
- - For limit-order support conversations, include `get_open_orders` and `get_order_history` in the loop.
629
- - If any mutation fails, read structured error fields: `error.code`, `error.hint`, `error.action`.
135
+ 1. **Unit Prefixing**: Use `human:` for readable amounts and `raw:` for exact on-chain units. Default is usually human-readable for high-level tools.
136
+ 2. **Pool Discovery**: Always run `find_pool` first to get the correct `poolId`.
137
+ 3. **Pre-trade Check**: Use `check_account_ready` to ensure enough collateral is in the trading account before opening positions.