@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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.5 - 2026-03-18
4
+
5
+ ### Changed
6
+ - **Major Tool Consolidation**: Unified 40+ specialized tools into ~26 high-level semantic tools for easier AI steering.
7
+ - `get_market_price` & `get_oracle_price` → `get_price`
8
+ - `get_market_detail`, `get_pool_info`, `get_liquidity_info`, `get_pool_level_config` → `get_pool_metadata`
9
+ - `get_pool_list` & `get_pool_symbol_all` → `list_pools`
10
+ - `get_pool_by_symbol` & `search_market` → `find_pool` (Discovery)
11
+ - `cancel_order` & `cancel_all_orders` → `cancel_orders` (Batch support)
12
+ - `set_tp_sl` & `update_order_tp_sl` → `manage_tp_sl`
13
+ - `get_open_orders` & `get_order_history` → `get_orders`
14
+ - `get_positions` & `get_position_history` → `get_positions_all`
15
+ - `get_account` & `get_account_vip_info` → `get_account_snapshot`
16
+ - Updated `README.md` and `TOOL_EXAMPLES.md` to reflect the new unified toolset.
17
+ - Enhanced `trading_best_practices` prompt with updated v3.0.4 workflows.
18
+ - Improved `zodSchemaToJsonSchema` to correctly expose `Enum` values to LLMs.
19
+ - Removed 18+ obsolete tool files from the codebase.
20
+ - Verified build and server initialization with the new structure.
21
+
22
+ ### Added
23
+ - `get_my_lp_holdings` tool for listing all wallet LP balances with standardized naming.
24
+ - Enriched `manage_liquidity` response with `lpAssetNames` (e.g., `mBTC.USDC`).
25
+
3
26
  ## 3.0.3 - 2026-03-17
4
27
 
5
28
  ### Changed
package/README.md CHANGED
@@ -1,444 +1,84 @@
1
1
  # MYX MCP Trading Server
2
2
 
3
- A production-ready MCP (Model Context Protocol) server that exposes tools, resources, and prompts for AI agents.
4
-
5
- This server allows AI assistants (like Claude Desktop, Cursor, etc.) to securely autonomously trade, manage liquidity, and fetch real-time market data on **MYX Finance**—a decentralized perpetual exchange. It interacts with smart contracts entirely via terminal/backend without requiring API keys or browser extensions.
3
+ A production-ready MCP (Model Context Protocol) server for deep integration with **MYX Finance**—a decentralized perpetual exchange. It allows AI assistants to autonomously trade, manage liquidity, and analyze markets via terminal/backend using pure on-chain logic.
6
4
 
7
5
  ---
8
6
 
9
7
  # Release Notes
10
8
 
11
- - Current release: **3.0.0**
12
- - Breaking change: `get_account_info`, `get_balances`, and `get_margin_balance` were removed.
13
- - Replacement: use `get_account` for unified wallet + trading-account balance view.
14
- - Detailed history: `CHANGELOG.md`
9
+ - **Current release: 3.0.4**
10
+ - **Refinement**: Consolidated 40+ specialized tools into ~26 high-level unified tools.
11
+ - **Improved UX**: Enhanced AI parameter parsing, automated unit conversion, and structured error reporting.
12
+ - **Breaking changes**: Many low-level tools (e.g., `get_market_price`, `get_oracle_price`, `get_open_orders`) have been merged into unified counterparts.
15
13
 
16
14
  ---
17
15
 
18
16
  # Features
19
17
 
20
- * MCP compliant server
21
- * AI-friendly tool design (Unit normalization, Automated ID resolution)
22
- * Structured input/output schemas for Web3 execution
23
- * Resource browsing support (`system://state`)
24
- * Prompt templates for trading decisions
25
- * Modular architecture
26
- * Logging and error handling
27
-
28
- ---
29
-
30
- # Architecture
31
-
32
- The project follows a modular architecture separating tools from trading services.
33
-
34
- AI Agents
35
-
36
- MCP Server
37
-
38
- Tools → Services → MYX SDK → Web3 RPC (EVM)
39
-
40
- Project structure:
41
-
42
- ```text
43
- src/
44
- server.ts
45
-
46
- tools/ # MCP exposed operations (e.g. executeTrade, searchMarket)
47
- resources/ # MCP contextual data (e.g. systemStateResource)
48
- prompts/ # MCP reusable templates (e.g. tradeAnalysisPrompt)
49
- services/ # Business logic calling the MYX SDK
50
- auth/ # Web3 wallet & client resolution
51
- utils/ # logger.ts, errors.ts, units.ts
52
-
53
- schemas/
54
- examples/
55
- tests/
56
- ```
57
-
58
- ---
59
-
60
- # Installation
61
-
62
- quick-start `npx @michaleffffff/mcp-trading-server`
18
+ * **Unified Toolset**: High-level semantic tools for simpler AI steering.
19
+ * **AI-First Design**: Automated Pool ID resolution and flexible unit handling (`human:` vs `raw:`).
20
+ * **Deep Liquidity Support**: Tools for both traders and liquidity providers.
21
+ * **Production Ready**: Robust error handling with actionable hints for LLMs.
22
+ * **Compliant**: Full Model Context Protocol (MCP) support.
63
23
 
64
24
  ---
65
25
 
66
26
  # Configuration
67
27
 
68
- Copy the example configuration:
28
+ Copy `.env.example` to `.env` and configure your trading wallet:
69
29
 
70
30
  ```bash
71
- cp .env.example .env
72
- ```
73
-
74
- ## Non-Auth Mode (No AccessToken)
75
-
76
- This MCP server runs in **non-auth mode**:
77
-
78
- - It does **not** call `myxClient.auth()` and does **not** manage AccessTokens.
79
- - All tools are designed to work without AccessToken authentication.
80
-
81
- ## User Key Configuration (Safe Practices)
82
-
83
- - **Local dev**: Put `PRIVATE_KEY` in a local `.env` (ignored by `.gitignore`) and never commit it.
84
- - **Production**: Inject via environment variables or a secrets manager, never store in code or repo.
85
- - **Best practice**: Use a dedicated low‑fund wallet, avoid reusing your main wallet, and rotate regularly.
86
-
87
- Environment variables needed for the trading wallet:
88
-
89
- ```bash
90
- # BNB Smart Chain (BSC Mainnet) (Default)
91
- PRIVATE_KEY=0xYourPrivateKey
31
+ PRIVATE_KEY=0x...
92
32
  RPC_URL=https://bsc-dataseed.bnbchain.org
93
33
  CHAIN_ID=56
94
- BROKER_ADDRESS=0xEb8C74fF05e76F85791dD2E4B972E7E78F6287C3
95
- QUOTE_TOKEN_ADDRESS=0x55d398326f99059fF775485246999027B3197955
34
+ BROKER_ADDRESS=0x...
35
+ QUOTE_TOKEN_ADDRESS=0x...
96
36
  QUOTE_TOKEN_DECIMALS=18
97
- IS_TESTNET=false
98
- MAX_TRADE_AMOUNT=5000 # Optional safety constraint limit for AI
99
37
  ```
100
38
 
101
- Testnet quick mapping:
102
-
103
- - `Arbitrum Sepolia (421614)`: `BROKER_ADDRESS=0x8f3153C18f698166f5D6124d8ba5B567F5f120f9`, `QUOTE_TOKEN_ADDRESS=0x7E248Ec1721639413A280d9E82e2862Cae2E6E28`
104
- - `Linea Sepolia (59141)`: `BROKER_ADDRESS=0x0FB08D3A1Ea6bE515fe78D3e0CaEb6990b468Cf3`, `QUOTE_TOKEN_ADDRESS=0xD984fd34f91F92DA0586e1bE82E262fF27DC431b`
105
-
106
39
  ---
107
40
 
108
- # Running the Server
109
-
110
- Build and Start the MCP server:
111
-
112
- ```bash
113
- npm run build
114
- npm run start
115
- ```
116
-
117
- The server will run using `stdio` transport and can be connected by any MCP-compatible client.
41
+ # Core Tools Reference
42
+
43
+ ### 📈 Market Analysis
44
+ * **`find_pool`**: Discover active markets by keyword/symbol (e.g., "BTC", "ETH").
45
+ * **`list_pools`**: List all tradable assets on the current chain.
46
+ * **`get_price`**: Fetch real-time prices (Impact Market Price or Oracle Price).
47
+ * **`get_pool_metadata`**: Comprehensive metrics (Fees, Open Interest, Liquidity Depth).
48
+ * **`get_kline`**: Fetch candlestick data for technical analysis.
49
+
50
+ ### ⚔️ Trading Operations
51
+ * **`open_position_simple`**: The recommended entry point for new trades. Handles size/price/fee computation. Supports Stop-Loss/Take-Profit.
52
+ * **`execute_trade`**: Low-level trade execution (Increase orders).
53
+ * **`close_position`**: Strategy-based closing of specific positions.
54
+ * **`close_all_positions`**: Emergency exit for all positions in a specific pool.
55
+ * **`cancel_orders`**: Unified cancellation (Single ID, Pool-wide, or Account-wide).
56
+ * **`manage_tp_sl`**: Adjust protection orders for active positions or pending orders.
57
+ * **`adjust_margin`**: Add or remove collateral to manage liquidation risk.
58
+
59
+ ### 📁 Account & Portfolio
60
+ * **`get_account_snapshot`**: Unified overview of balances, trading metrics, and VIP tier.
61
+ * **`get_orders`**: Historical and active order ledger.
62
+ * **`get_positions_all`**: Currently open and recently closed positions.
63
+ * **`get_trade_flow`**: Granular transaction history.
64
+ * **`check_account_ready`**: Pre-trade balance validator with auto-deposit support.
118
65
 
119
66
  ---
120
67
 
121
- ## Quick Start for Regular Users
68
+ # Quick Start Flow
122
69
 
123
- 1. **Prepare a wallet**: Use a testnet or a small dedicated wallet (avoid your main wallet).
124
- 2. **Configure env**: Copy `.env.example` to `.env` and fill in `PRIVATE_KEY`, `RPC_URL`, etc.
125
- 3. **Start the server**: Run `npm run build` then `npm run start` (use `npm run dev` for development).
126
- 4. **Configure your MCP client**: Set `command/args/env` in your MCP client (see Claude Desktop example below).
127
- 5. **Common flow**: Use `search_market` (or `get_pool_list`) to get `poolId`, then optionally `get_market_price` / `get_oracle_price` to view prices, and finally use `open_position_simple` (recommended) to open a position.
128
- 6. **Tool examples**: See `TOOL_EXAMPLES.md` for practical examples for every tool, common workflows, and parameter-unit guidance.
129
-
130
- **Minimal open position example:**
131
-
132
- ```json
133
- {
134
- "keyword": "BTC",
135
- "direction": 0,
136
- "collateralAmount": "100",
137
- "leverage": 5,
138
- "orderType": "MARKET",
139
- "autoDeposit": false
140
- }
141
- ```
142
-
143
- **Dry run (no transaction) example:**
144
-
145
- ```json
146
- {
147
- "keyword": "BTC",
148
- "direction": 0,
149
- "collateralAmount": "100",
150
- "leverage": 5,
151
- "orderType": "MARKET",
152
- "autoDeposit": false,
153
- "dryRun": true
154
- }
155
- ```
156
-
157
- ## Units & Precision
158
-
159
- - **Human by default**: For trading tools (e.g. `open_position_simple`), amounts like `"100"` mean **human-readable units**.
160
- - **Raw units (explicit)**: Prefix with `raw:` to pass raw units exactly (e.g. `raw:100000000` for 100 USDC with 6 decimals).
161
- - **Price**: `"price"` is human by default and will be converted to **30-decimal** format internally. Use `raw:` to pass a 30-decimal integer directly.
162
- - **Slippage**: `slippagePct` uses 4-decimal raw units: `100` = `1%`, `50` = `0.5%`, `1000` = `10%`.
163
- - **Note**: Some account-transfer tools (e.g. `account_deposit`, `account_withdraw`, `check_approval`) use **raw integer strings**.
164
- - **`adjust_margin` units**: human amount is supported (e.g. `"1"` means 1 quote token). For exact atomic amount, use `raw:` (e.g. `"raw:1"`).
165
-
166
- ## P0 Reliability Contract (AI-friendly)
167
-
168
- Starting with P0, tool failures are normalized to a structured JSON envelope:
169
-
170
- ```json
171
- {
172
- "status": "error",
173
- "error": {
174
- "tool": "execute_trade",
175
- "code": "INVALID_PARAM",
176
- "message": "Invalid arguments for tool \"execute_trade\".",
177
- "hint": "Fix \"positionId\": positionId must be empty string for new position, or a bytes32 hex string.",
178
- "action": "Call list_tools and resend valid arguments.",
179
- "details": {
180
- "issues": [
181
- {
182
- "field": "positionId",
183
- "code": "custom",
184
- "message": "positionId must be empty string for new position, or a bytes32 hex string."
185
- }
186
- ]
187
- }
188
- }
189
- }
190
- ```
191
-
192
- Common error codes:
193
- - `INVALID_PARAM`: input schema/field error.
194
- - `INSUFFICIENT_BALANCE`: wallet or trading-account amount is not enough.
195
- - `INSUFFICIENT_ALLOWANCE`: token approval/allowance is insufficient.
196
- - `NOT_FOUND`: bad tool name or bad identifiers (`poolId`, `orderId`, `marketId`).
197
- - `TIMEOUT`: tx confirmation/query timeout.
198
- - `NETWORK_ERROR`: RPC or network issue.
199
-
200
- Search behavior in P0:
201
- - `search_market` now accepts empty `keyword` and returns active markets.
202
- - When `search_market` returns empty/unstable data, server-side fallback uses SDK `api.getMarketList()` and `api.getPoolList()` to rebuild active-market results.
203
- - For robust discovery, you can also call `get_pool_list` directly.
204
-
205
- Example:
206
-
207
- ```json
208
- {
209
- "name": "search_market",
210
- "arguments": {
211
- "keyword": "",
212
- "limit": 20
213
- }
214
- }
215
- ```
70
+ 1. **Find Target**: `find_pool(keyword="BTC")`
71
+ 2. **Check State**: `get_account_snapshot(poolId="...")`
72
+ 3. **Execute**: `open_position_simple(poolId="...", direction="LONG", leverage=5, collateralAmount="100")`
73
+ 4. **Monitor**: `get_positions_all(status="OPEN")`
216
74
 
217
75
  ---
218
76
 
219
- ## Secure Deployment Template (Systemd Example)
220
-
221
- **1) Put secrets in a system env file (chmod 600)**
77
+ # Documentation
222
78
 
223
- ```bash
224
- # /etc/myx-mcp.env
225
- PRIVATE_KEY=0xYourPrivateKey
226
- RPC_URL=https://bsc-dataseed.bnbchain.org
227
- CHAIN_ID=56
228
- BROKER_ADDRESS=0xEb8C74fF05e76F85791dD2E4B972E7E78F6287C3
229
- QUOTE_TOKEN_ADDRESS=0x55d398326f99059fF775485246999027B3197955
230
- QUOTE_TOKEN_DECIMALS=18
231
- IS_TESTNET=false
232
- ```
233
-
234
- ```bash
235
- sudo chmod 600 /etc/myx-mcp.env
236
- ```
237
-
238
- **2) Systemd service**
239
-
240
- ```ini
241
- # /etc/systemd/system/myx-mcp.service
242
- [Unit]
243
- Description=MYX MCP Trading Server
244
- After=network.target
245
-
246
- [Service]
247
- Type=simple
248
- User=myx
249
- Group=myx
250
- WorkingDirectory=/opt/myx-mcp-trading-server-v2
251
- EnvironmentFile=/etc/myx-mcp.env
252
- ExecStart=/usr/bin/node /opt/myx-mcp-trading-server-v2/dist/server.js
253
- Restart=on-failure
254
-
255
- [Install]
256
- WantedBy=multi-user.target
257
- ```
258
-
259
- **3) Start**
260
-
261
- ```bash
262
- sudo systemctl daemon-reload
263
- sudo systemctl enable --now myx-mcp
264
- ```
265
-
266
- ### Connecting Claude Desktop (MacOS)
267
- Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
268
- ```json
269
- {
270
- "mcpServers": {
271
- "myx-trading-v2": {
272
- "command": "node",
273
- "args": [
274
- "[/Absolute/Path/To/Your/Directory]/myx-mcp-trading-server-v2/dist/server.js"
275
- ],
276
- "env": {
277
- "PRIVATE_KEY": "0xYourPrivateKey"
278
- }
279
- }
280
- }
281
- }
282
- ```
283
-
284
- ---
285
-
286
- # Tools
287
-
288
- The server exposes tools categorized for AI:
289
-
290
- For practical tool-by-tool examples, see: `TOOL_EXAMPLES.md`
291
-
292
- ### Trading Operations
293
- * **open_position_simple**: High-level open position helper (recommended). Computes price/size/tradingFee internally.
294
- * **execute_trade**: Execute a new trade or add to an existing position (includes parameter preflight, supports `human:`/`raw:` amount prefixes, auto-computes `tradingFee` when omitted).
295
- * **close_position**: Close an open position.
296
- * **close_all_positions**: Emergency: close ALL open positions in a pool at once.
297
- * **cancel_order**: Cancel an open order by its order ID.
298
- * **cancel_all_orders**: Cancel open orders by IDs (supports array, JSON-array string, comma string, or single ID; use `get_open_orders` first).
299
- * **set_tp_sl**: Set take profit and stop loss prices for an open position.
300
- * **update_order_tp_sl**: Update TP/SL fields for an existing order. Accepts boolean-like values for `useOrderCollateral` / `isTpSlOrder`.
301
- * **adjust_margin**: Adjust the margin (collateral) of an open position.
302
- * **get_user_trading_fee_rate**: Query current maker/taker fee rates by asset class and risk tier.
303
- * **get_network_fee**: Query estimated network fee requirements for a market.
304
-
305
- ### Market Data
306
- * **search_market**: Search for an active market (e.g., "BTC") to retrieve its unique `poolId` (Crucial prerequisite).
307
- * **get_market_price**: Get the current ticker market price for a specific pool.
308
- * **get_oracle_price**: Get the current EVM oracle price for a specific pool.
309
- * **get_kline_latest_bar**: Get only the latest bar for an interval.
310
- * **get_all_tickers**: Get all ticker snapshots in one request.
311
- * **get_kline**, **get_pool_info**... (`get_pool_info` auto-retries with oracle/ticker price on divide-by-zero reads)
312
- * **get_pool_symbol_all**, **get_base_detail**, **get_pool_level_config**...
313
-
314
- ### Account & Portfolio
315
- * **get_positions**: Get all open positions for the current account.
316
- * **get_account**: Unified account snapshot. Clearly separates **wallet balance** and **trading-account balance** (provide `poolId` for full trading-account metrics).
317
- * **get_my_lp_holdings**: Scan pools and return your base/quote LP token balances on the current chain, with standardized LP asset names (`base: mBASE.QUOTE`, `quote: mQUOTE.BASE`).
318
- * **get_account_vip_info**: Query account VIP tier details.
319
- * **get_position_history**, **get_open_orders**, **get_order_history**...
320
-
321
- `get_account` note:
322
- - `poolId` omitted: wallet-focused snapshot only.
323
- - `poolId` provided: wallet + trading-account + margin snapshot.
324
- - If one section fails (wallet or trading-account), the tool may return a **partial** snapshot with `meta.partial=true` and section-level `error` details.
325
-
326
- ### Liquidity Provision (LP)
327
- * **manage_liquidity**: Add or withdraw liquidity from a BASE or QUOTE pool (aliases: `add/remove/increase/decrease` are supported). `poolId` is pre-validated on target `chainId` for clearer errors. Response includes LP naming metadata (`baseLpAssetName=mBASE.QUOTE`, `quoteLpAssetName=mQUOTE.BASE`, `operatedLpAssetName`).
328
- - Example (`BTC/USDC`, `poolType=QUOTE`): `operatedLpAssetName = mUSDC.BTC`.
329
- * **create_perp_market**: Create a new perpetual trading pair.
330
-
331
- ---
332
-
333
- # Resources
334
-
335
- Resources provide contextual data that AI agents can read.
336
-
337
- Available resources:
338
-
339
- **`system://state`**
340
-
341
- Description:
342
- Readonly contextual data about the active EVM network, connected wallet address, chain ID, and RPC health available to the AI.
343
-
344
- ---
345
-
346
- # Prompts
347
-
348
- Reusable prompt templates for AI tasks.
349
-
350
- ## `analyze_positions`
351
-
352
- Analyze the user's current trading positions based on real-time market action.
353
-
354
- **Arguments:**
355
-
356
- * `marketContext` (string, optional) - Provide the latest market insights or news to contextualize the analysis.
357
-
358
- **Returns:**
359
- Messages including a stringified dump of the user's active portfolio on MYX ready to be sent to an LLM for trading advice.
360
-
361
- ---
362
-
363
- # Example Usage
364
-
365
- Example MCP client usage workflow:
366
-
367
- 1. Connect to the MCP server.
368
- 2. Read the `system://state` resource to confirm wallet connectivity.
369
- 3. Call the `search_market` tool (e.g., `keyword: "ETH"`) to retrieve the `poolId`.
370
- 4. Call `open_position_simple` passing the retrieved `poolId` to open a 10x long position.
371
-
372
- ## Limit Order Lifecycle (P0)
373
-
374
- Use this query/mutation loop for limit-order management:
375
-
376
- 1. Place order with `execute_trade` (`orderType=LIMIT`).
377
- 2. Query active orders with `get_open_orders`.
378
- 3. If still pending, you can cancel/update order-level fields; if filled into a position, prefer `set_tp_sl` for position TP/SL.
379
- 4. Check historical fills/cancellations with `get_order_history`.
380
- 5. Cancel one order via `cancel_order` or batch via `cancel_all_orders`.
381
-
382
- ## Unit Safety (P0)
383
-
384
- - Monetary fields in major mutation tools support `human:` and `raw:` prefixes.
385
- - Default behavior is human-readable units (e.g. `1` means `1.0` token), while `raw:<int>` enforces exact raw units.
386
- - `execute_trade` and `adjust_margin` responses include normalized raw values for auditability.
387
-
388
- Minimal query examples:
389
-
390
- ```json
391
- {
392
- "name": "get_open_orders",
393
- "arguments": {}
394
- }
395
- ```
396
-
397
- ```json
398
- {
399
- "name": "get_order_history",
400
- "arguments": {
401
- "poolId": "0x...",
402
- "limit": 20
403
- }
404
- }
405
- ```
406
-
407
- Example integration scripts are located in:
408
- `examples/basicUsage.ts`
409
-
410
- ---
411
-
412
- # Development
413
-
414
- Run in development mode (watcher):
415
-
416
- ```bash
417
- npm run dev
418
- ```
419
-
420
- Run tests:
421
-
422
- ```bash
423
- npm test
424
- npm run test:new-tools
425
- ```
79
+ For detailed implementation examples and parameter guides, see:
80
+ * **[TOOL_EXAMPLES.md](./TOOL_EXAMPLES.md)**: Payload examples for every tool.
81
+ * **[CHANGELOG.md](./CHANGELOG.md)**: Version history and migration paths.
82
+ * **[mcp_config_guide.md](./mcp_config_guide.md)**: Client setup instructions.
426
83
 
427
84
  ---
428
-
429
- # Extending the Server
430
-
431
- To add a new tool:
432
-
433
- 1. Create a new file in `src/tools/myNewTool.ts`
434
- 2. Define the Zod input schema and description
435
- 3. Implement the `handler(args)` executing the trading logic
436
- 4. Export and register it in `src/tools/index.ts`
437
-
438
- ---
439
-
440
- # Contributing
441
-
442
- Contributions are welcome.
443
-
444
- Please open an issue or submit a pull request.