Phemex Trading
Trade on Phemex via the phemex-cli tool. Supports USDT-M futures, Coin-M futures, and Spot markets.
Before you start
Ensure you have the latest version installed:
npm install -g phemex-trade-mcp@latest
How to call tools
phemex-cli <tool_name> --param1 value1 --param2 value2
Or with JSON args:
phemex-cli <tool_name> '{"param1":"value1","param2":"value2"}'
Output is always JSON. Environment variables PHEMEX_API_KEY, PHEMEX_API_SECRET, and PHEMEX_API_URL are read automatically.
Contract types
Every tool accepts an optional --contractType flag:
linear (default) — USDT-M perpetual futures. Symbols end in USDT (e.g. BTCUSDT).
inverse — Coin-M perpetual futures. Symbols end in USD (e.g. BTCUSD).
spot — Spot trading. Symbols end in USDT (e.g. BTCUSDT). The server auto-prefixes s for the API.
Tools
Market data (no auth needed)
get_ticker — 24hr price ticker. Example: phemex-cli get_ticker --symbol BTCUSDT
get_orderbook — Order book (30 levels). Example: phemex-cli get_orderbook --symbol BTCUSDT
get_klines — Candlestick data. Example: phemex-cli get_klines --symbol BTCUSDT --resolution 3600 --limit 100
get_recent_trades — Recent trades. Example: phemex-cli get_recent_trades --symbol BTCUSDT
get_funding_rate — Funding rate history. Example: phemex-cli get_funding_rate --symbol .BTCFR8H --limit 20
Account (read-only, auth required)
get_account — Balance and margin info. Example: phemex-cli get_account --currency USDT
get_spot_wallet — Spot wallet balances. Example: phemex-cli get_spot_wallet
get_positions — Current positions with PnL. Example: phemex-cli get_positions --currency USDT
get_open_orders — Open orders. Example: phemex-cli get_open_orders --symbol BTCUSDT
get_order_history — Closed/filled orders. Example: phemex-cli get_order_history --symbol BTCUSDT --limit 50
get_trades — Trade execution history. Example: phemex-cli get_trades --symbol BTCUSDT --limit 50
Trading (auth required)
place_order — Place an order (Market, Limit, Stop, StopLimit). Key params: --symbol, --side (Buy/Sell), --orderQty, --ordType, --price (Limit/StopLimit), --stopPx (Stop/StopLimit), --timeInForce (GoodTillCancel/PostOnly/ImmediateOrCancel/FillOrKill), --reduceOnly, --posSide (Long/Short/Merged), --stopLoss, --takeProfit, --qtyType (spot only). orderQty units differ by contract type:
linear (USDT-M): orderQty = base currency amount (e.g. 0.01 = 0.01 BTC). To buy 10 USDT worth, calculate qty = 10 / current price.
inverse (Coin-M): orderQty = number of contracts as integer (e.g. 10 = 10 contracts). Each contract has a fixed USD value (e.g. 1 USD/contract for BTCUSD).
spot: depends on --qtyType. ByBase (default) = base currency (e.g. 0.01 = 0.01 BTC). ByQuote = quote currency (e.g. 50 = 50 USDT worth of BTC).
- Example:
phemex-cli place_order --symbol BTCUSDT --side Buy --orderQty 0.01 --ordType Market
amend_order — Modify an open order. Example: phemex-cli amend_order --symbol BTCUSDT --orderID xxx --price 95000
cancel_order — Cancel one order. Example: phemex-cli cancel_order --symbol BTCUSDT --orderID xxx
cancel_all_orders — Cancel all orders for a symbol. Example: phemex-cli cancel_all_orders --symbol BTCUSDT
set_leverage — Set leverage. Example: phemex-cli set_leverage --symbol BTCUSDT --leverage 10
switch_pos_mode — Switch OneWay/Hedged. Example: phemex-cli switch_pos_mode --symbol BTCUSDT --targetPosMode OneWay
Transfers (auth required)
transfer_funds — Move funds between spot and futures. Example: phemex-cli transfer_funds --currency USDT --amount 100 --direction spot_to_futures
get_transfer_history — Transfer history. Example: phemex-cli get_transfer_history --currency USDT --limit 20
Safety rules
- Always confirm before placing orders. Before calling
place_order, show the user exactly what the order will do: symbol, side, quantity, type, price. Ask for confirmation.
- Always confirm before cancelling all orders. Before calling
cancel_all_orders, list the open orders first and confirm with the user.
- Explain leverage changes. Before calling
set_leverage, explain the implications (higher leverage = higher liquidation risk).
- Show context before trading. Before suggesting a trade, show current positions and account balance so the user can make an informed decision.
- Never auto-trade. Do not place orders without explicit user instruction.
Common workflows
Check a price
phemex-cli get_ticker --symbol BTCUSDT
Place a market buy (USDT-M futures)
phemex-cli place_order --symbol BTCUSDT --side Buy --orderQty 0.01 --ordType Market
Place a limit sell (Coin-M futures)
phemex-cli place_order --symbol BTCUSD --side Sell --orderQty 10 --ordType Limit --price 100000 --contractType inverse
Buy spot
phemex-cli place_order --symbol BTCUSDT --side Buy --orderQty 10 --ordType Market --contractType spot --qtyType ByQuote
Check positions
phemex-cli get_positions --currency USDT
Setup
- Create a Phemex account at https://phemex.com
- Create an API key (Account → API Management)
- Set environment variables
PHEMEX_API_KEY and PHEMEX_API_SECRET
- Optionally set
PHEMEX_API_URL (defaults to testnet https://testnet-api.phemex.com for safety; set to https://api.phemex.com for real trading)
- Optionally set
PHEMEX_MAX_ORDER_VALUE to limit maximum order size (USD)
1---2name: phemex-trade3description: Trade on Phemex (USDT-M futures, Coin-M futures, Spot) — place orders, manage positions, check balances, and query market data. Use when the user wants to (1) check crypto prices or market data on Phemex, (2) place, amend, or cancel orders, (3) view account balances or positions, (4) set leverage or switch position modes, (5) transfer funds between spot and futures wallets, or (6) any task involving the Phemex exchange.4---5
6# Phemex Trading
7
8Trade on Phemex via the phemex-cli tool. Supports USDT-M futures, Coin-M futures, and Spot markets.
9
10## Before you start
11
12Ensure you have the latest version installed:
13
14```bash
15npm install -g phemex-trade-mcp@latest
16```
17
18## How to call tools
19
20```bash
21phemex-cli <tool_name> --param1 value1 --param2 value2
22```
23
24Or with JSON args:
25
26```bash
27phemex-cli <tool_name> '{"param1":"value1","param2":"value2"}'
28```
29
30Output is always JSON. Environment variables `PHEMEX_API_KEY`, `PHEMEX_API_SECRET`, and `PHEMEX_API_URL` are read automatically.
31
32## Contract types
33
34Every tool accepts an optional `--contractType` flag:
35
36- `linear` (default) — USDT-M perpetual futures. Symbols end in USDT (e.g. BTCUSDT).
37- `inverse` — Coin-M perpetual futures. Symbols end in USD (e.g. BTCUSD).
38- `spot` — Spot trading. Symbols end in USDT (e.g. BTCUSDT). The server auto-prefixes `s` for the API.
39
40## Tools
41
42### Market data (no auth needed)
43
44- `get_ticker` — 24hr price ticker. Example: `phemex-cli get_ticker --symbol BTCUSDT`
45- `get_orderbook` — Order book (30 levels). Example: `phemex-cli get_orderbook --symbol BTCUSDT`
46- `get_klines` — Candlestick data. Example: `phemex-cli get_klines --symbol BTCUSDT --resolution 3600 --limit 100`
47- `get_recent_trades` — Recent trades. Example: `phemex-cli get_recent_trades --symbol BTCUSDT`
48- `get_funding_rate` — Funding rate history. Example: `phemex-cli get_funding_rate --symbol .BTCFR8H --limit 20`
49
50### Account (read-only, auth required)
51
52- `get_account` — Balance and margin info. Example: `phemex-cli get_account --currency USDT`
53- `get_spot_wallet` — Spot wallet balances. Example: `phemex-cli get_spot_wallet`
54- `get_positions` — Current positions with PnL. Example: `phemex-cli get_positions --currency USDT`
55- `get_open_orders` — Open orders. Example: `phemex-cli get_open_orders --symbol BTCUSDT`
56- `get_order_history` — Closed/filled orders. Example: `phemex-cli get_order_history --symbol BTCUSDT --limit 50`
57- `get_trades` — Trade execution history. Example: `phemex-cli get_trades --symbol BTCUSDT --limit 50`
58
59### Trading (auth required)
60
61- `place_order` — Place an order (Market, Limit, Stop, StopLimit). Key params: `--symbol`, `--side` (Buy/Sell), `--orderQty`, `--ordType`, `--price` (Limit/StopLimit), `--stopPx` (Stop/StopLimit), `--timeInForce` (GoodTillCancel/PostOnly/ImmediateOrCancel/FillOrKill), `--reduceOnly`, `--posSide` (Long/Short/Merged), `--stopLoss`, `--takeProfit`, `--qtyType` (spot only). **orderQty units differ by contract type:**
62 - `linear` (USDT-M): orderQty = base currency amount (e.g. `0.01` = 0.01 BTC). To buy 10 USDT worth, calculate qty = 10 / current price.
63 - `inverse` (Coin-M): orderQty = number of contracts as integer (e.g. `10` = 10 contracts). Each contract has a fixed USD value (e.g. 1 USD/contract for BTCUSD).
64 - `spot`: depends on `--qtyType`. `ByBase` (default) = base currency (e.g. `0.01` = 0.01 BTC). `ByQuote` = quote currency (e.g. `50` = 50 USDT worth of BTC).
65 - Example: `phemex-cli place_order --symbol BTCUSDT --side Buy --orderQty 0.01 --ordType Market`
66- `amend_order` — Modify an open order. Example: `phemex-cli amend_order --symbol BTCUSDT --orderID xxx --price 95000`
67- `cancel_order` — Cancel one order. Example: `phemex-cli cancel_order --symbol BTCUSDT --orderID xxx`
68- `cancel_all_orders` — Cancel all orders for a symbol. Example: `phemex-cli cancel_all_orders --symbol BTCUSDT`
69- `set_leverage` — Set leverage. Example: `phemex-cli set_leverage --symbol BTCUSDT --leverage 10`
70- `switch_pos_mode` — Switch OneWay/Hedged. Example: `phemex-cli switch_pos_mode --symbol BTCUSDT --targetPosMode OneWay`
71
72### Transfers (auth required)
73
74- `transfer_funds` — Move funds between spot and futures. Example: `phemex-cli transfer_funds --currency USDT --amount 100 --direction spot_to_futures`
75- `get_transfer_history` — Transfer history. Example: `phemex-cli get_transfer_history --currency USDT --limit 20`
76
77## Safety rules
78
791. **Always confirm before placing orders.** Before calling `place_order`, show the user exactly what the order will do: symbol, side, quantity, type, price. Ask for confirmation.
802. **Always confirm before cancelling all orders.** Before calling `cancel_all_orders`, list the open orders first and confirm with the user.
813. **Explain leverage changes.** Before calling `set_leverage`, explain the implications (higher leverage = higher liquidation risk).
824. **Show context before trading.** Before suggesting a trade, show current positions and account balance so the user can make an informed decision.
835. **Never auto-trade.** Do not place orders without explicit user instruction.
84
85## Common workflows
86
87### Check a price
88
89```bash
90phemex-cli get_ticker --symbol BTCUSDT
91```
92
93### Place a market buy (USDT-M futures)
94
95```bash
96phemex-cli place_order --symbol BTCUSDT --side Buy --orderQty 0.01 --ordType Market
97```
98
99### Place a limit sell (Coin-M futures)
100
101```bash
102phemex-cli place_order --symbol BTCUSD --side Sell --orderQty 10 --ordType Limit --price 100000 --contractType inverse
103```
104
105### Buy spot
106
107```bash
108phemex-cli place_order --symbol BTCUSDT --side Buy --orderQty 10 --ordType Market --contractType spot --qtyType ByQuote
109```
110
111### Check positions
112
113```bash
114phemex-cli get_positions --currency USDT
115```
116
117## Setup
118
1191. Create a Phemex account at https://phemex.com
1202. Create an API key (Account → API Management)
1213. Set environment variables `PHEMEX_API_KEY` and `PHEMEX_API_SECRET`
1224. Optionally set `PHEMEX_API_URL` (defaults to testnet `https://testnet-api.phemex.com` for safety; set to `https://api.phemex.com` for real trading)
1235. Optionally set `PHEMEX_MAX_ORDER_VALUE` to limit maximum order size (USD)