# dYdX MCP

> dYdX (Decentralized Perpetual Exchange API) provides full access to perpetual trading on dYdX v4. Use this MCP to monitor markets, analyze orderbooks, and execute complex trades directly from any AI agent. Get real-time data—from 24h market statistics to account balances—all without leaving your research environment.

## Overview
- **Category:** finance-accounting
- **Price:** Free
- **Tags:** crypto-trading, perpetuals, dex, orderbook, defi

## Description

You can connect your crypto trading workflow to the leading decentralized perpetual exchange using this MCP. It lets your AI client monitor live markets and execute complex trades across dYdX v4 infrastructure. Instead of opening multiple dashboards, you tell your agent what you want—say, 'Place a limit order for BTC-USD when it hits $25,000.' The system handles the rest. This capability means crypto developers, quants, and analysts can run full trading simulations or manage live positions directly within their coding tools. By connecting to this MCP via Vinkius, you gain programmatic access to everything from historical OHLCV data for deep technical analysis to current account equity checks. It's about making your entire research stack—your terminal, your IDE, your custom scripts—into a single, actionable trading platform.

## Tools

### v3_create_order
Places a new order directly onto the dYdX v3 exchange environment.

### v3_get_accounts
Retrieves comprehensive account information available on the dYdX v3 platform.

### v3_get_orderbook
Fetches the current L2 order book for any specified dYdX v3 market pair.

### v3_list_markets
Lists all active perpetual markets available on the dYdX v3 platform.

### v4_cancel_order
Cancels an open order by providing its specific ID on the dYdX v4 system.

### v4_create_order
Places a new limit or market order directly onto the modern dYdX v4 exchange platform.

### v4_get_account
Retrieves your current account balances, open positions, and total equity on dYdX v4.

### v4_get_candles
Gets historical OHLCV candlestick data for any specified dYdX v4 market pair.

### v4_get_market
Retrieves detailed information about a specific perpetual market on dYdX v4.

### v4_get_orderbook
Fetches the current L2 order book for any specified dYdX v4 market pair.

### v4_get_stats
Gets aggregate 24-hour statistics for a given dYdX v4 market.

### v4_get_trades
Retrieves recent public trades that occurred on the specified dYdX v4 market.

### v4_list_fills
Lists all recent trade fills associated with your account on dYdX v4.

### v4_list_markets
Lists every available perpetual market pair operating on the dYdX v4 platform.

### v4_list_orders
Lists both active and historical orders placed under your account on dYdX v4.

### v4_list_positions
Retrieves a list of all open, current positions held by the account on dYdX v4.

## Prompt Examples

**Prompt:** 
```
List all active markets on dYdX v4.
```

**Response:** 
```
I've retrieved the active markets. Currently, there are several pairs available including BTC-USD, ETH-USD, and SOL-USD. Would you like details on a specific one?
```

**Prompt:** 
```
What is the current orderbook for ETH-USD?
```

**Response:** 
```
Fetching the L2 orderbook for ETH-USD... The best bid is at $2,450.50 and the best ask is at $2,450.60. There is significant liquidity within the 1% range.
```

**Prompt:** 
```
Show my open positions and account balance for address dydx1...
```

**Response:** 
```
Checking account state... You have one open long position in BTC-USD (size: 0.1 BTC). Your total equity is $5,200.40 with a buying power of $15,000.
```

## Capabilities

### Review and Compare Market Data
List all available perpetual markets and pull detailed market information, including 24h rolling statistics.

### Monitor Order Book Depth
Get the current L2 orderbook for any dYdX v3 or v4 market to assess immediate liquidity.

### Manage Account State
Check your account balances, open positions, and overall equity on the dYdX Chain address.

### Execute Trading Actions
Place new limit or market orders, cancel existing ones, and view order history through natural language commands.

### Analyze Historical Trends
Retrieve historical OHLCV candlestick data and recent public trades for deep technical analysis.

## Use Cases

### Analyzing market structure before entry
A DeFi Analyst notices BTC-USD volatility. Instead of watching a live chart, they ask their agent: 'Get me the v4_get_orderbook and the v4_get_stats for BTC-USD.' The agent instantly pulls both the deep liquidity profile and the 24h summary, allowing the analyst to confirm if current movement is supported by underlying order book depth.

### Automating trade rebalancing
A Portfolio Manager wants to reduce risk. They instruct their agent to 'List my open positions (v4_list_positions) and calculate the total notional value.' The agent returns this list, allowing the manager to programmatically decide which position needs to be trimmed or closed.

### Auditing a complex trade sequence
A Quant Developer finishes a multi-step simulation. They ask their agent to 'Show me all recent trades (v4_get_trades) and the corresponding fills (v4_list_fills).' This gives an immediate, auditable trail of every executed action against the account.

### Validating market availability
A new product launches. A developer first uses v4_list_markets to see all available pairs on dYdX v4. This confirms if their target asset pair is live before attempting any trade execution.

## Benefits

- Real-time position tracking. Instead of manually checking multiple tabs, use v4_list_positions to pull all open positions into your agent's memory for instant risk assessment.
- Deep technical analysis from history. You get historical OHLCV candlestick data via v4_get_candles, letting you build backtesting models without leaving your research environment.
- Instant market depth visibility. Use v4_get_orderbook to see the best bids and asks (L2) for any pair, giving you a real-time view of immediate liquidity that simple price feeds miss.
- Full lifecycle trade management. You don't just place orders; you can cancel them using v4_cancel_order or review all your history with v4_list_orders and v4_list_fills.
- Comprehensive status checks. Before making a move, check your total buying power and equity balance using v4_get_account to ensure funds are available for the trade.

## How It Works

The bottom line is, your agent talks directly to dYdX, giving you instant market and account status updates without requiring manual API calls.

1. Subscribe to this MCP and provide your dYdX API Key, Secret, and Passphrase.
2. Your AI agent uses the credentials to connect to the v4 infrastructure.
3. The agent executes commands—like 'List all markets' or 'Get account balance'—and returns structured data for you to use.

## Frequently Asked Questions

**How do I check my account balance using v4_get_account?**
Call v4_get_account with your credentials. This tool returns all current financial data, including total equity and available buying power on dYdX v4.

**Can I get historical price data using v4_get_candles?**
Yes. You must specify the market pair and time range when calling v4_get_candles. This returns OHLCV candlestick data necessary for backtesting strategies.

**What is the difference between v3_get_orderbook and v4_get_orderbook?**
Both retrieve the L2 order book, but v4_get_orderbook connects to the current dYdX v4 infrastructure. For new development, always use the v4 tool.

**How do I list all available perpetual markets?**
You can call v4_list_markets for a full inventory of pairs on dYdX v4, or use v3_list_markets if you need the older v3 market listing.

**What tool should I use to cancel an order?**
Use v4_cancel_order. You must provide the specific Order ID for the cancellation to succeed on dYdX v4.

**What parameters do I need to use when I call `v4_create_order`?**
The `v4_create_order` tool requires specifying the market ID, side (buy/sell), quantity, and price. You must also define whether you want a limit or market order type for execution.

**How does `v4_list_positions` help me manage my risk?**
It gives you a consolidated view of all your current open positions, showing the asset, size, and entry price. This allows your agent to check exposure levels across different markets before executing new trades.

**What specific metrics does `v4_get_stats` provide for a market?**
The tool retrieves key 24-hour performance data, including trading volume, highest bid/ask, and price changes. This helps you analyze immediate market momentum without fetching historical candles.

**Can I check my current open positions and account balance?**
Yes. You can use `v4_list_positions` to see all active trades and `v4_get_account` with your address to retrieve balances and equity.

**How do I get the latest market price and orderbook depth?**
Use the `v4_get_market` tool for general info or `v4_get_orderbook` for the current L2 state of any specific market like BTC-USD.

**Is it possible to place or cancel trades through the AI?**
Yes. The `v4_create_order` tool allows you to place limit or market orders, and `v4_cancel_order` lets you cancel them using their Order ID.