
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
OKX DEX Trading MCP Server - Model Context Protocol server for decentralized exchange trading via OKX API
A powerful Model Context Protocol (MCP) server that provides comprehensive decentralized exchange (DEX) trading capabilities through the OKX API. This server enables AI assistants and applications to interact with 27+ blockchain networks for real-time trading, price discovery, and cross-chain operations.
pip install okx-dex-mcp
Create a .env
file in your project directory:
# OKX API Configuration
OKX_API_KEY=your_api_key_here
OKX_SECRET_KEY=your_secret_key_here
OKX_PASSPHRASE=your_passphrase_here
# Optional: Enable sandbox mode for testing
OKX_SANDBOX=false
# Test the installation with demo mode
okx-dex-demo
Run directly from PyPI without installation:
# Run demo (one command)
uvx --from okx-dex-mcp okx-dex-demo
# Start MCP server (one command)
uvx --from okx-dex-mcp okx-dex-mcp
Install and run locally:
# Install the package
pip install okx-dex-mcp
# Run demo
okx-dex-demo
# Start MCP server
okx-dex-mcp
Start the MCP server for integration with AI assistants:
okx-dex-mcp
import asyncio
from okx_dex_mcp.analysis.dex_analysis import search_dex_tokens
from okx_dex_mcp.swap.quotes import get_quote
from okx_dex_mcp.swap.swaps import execute_swap
async def example_usage():
# Search for USDC on Ethereum
tokens = await search_dex_tokens("USDC", "1")
print(f"Found {len(tokens)} USDC tokens")
# Get a trading quote
quote = await get_dex_quote(
from_token="0xa0b86a33e6ba3e0e4ca4ba5e7e5e8e8e8e8e8e8e",
to_token="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
amount="1000000", # 1 USDC (6 decimals)
chain_id="1"
)
print(f"Quote: {quote}")
# Run the example
asyncio.run(example_usage())
The server provides 11 essential tools for DEX operations:
get_supported_dex_chains_tool
- Get list of supported blockchain networksget_chain_top_tokens_tool
- Get top tokens by market cap on specific chainssearch_dex_tokens_tool
- Search for tokens by name or symbolget_dex_market_summary_tool
- Get comprehensive market data for tokensget_dex_quote_tool
- Get DEX trading quotes with price impact analysisexecute_dex_swap_tool
- Execute same-chain swaps with automatic token approvalcheck_token_allowance_status_tool
- Check token allowances (debugging utility)get_quote
- Get trading quotes (both same-chain and cross-chain)get_bridge_token_suggestions_tool
- Get bridge token recommendationsexecute_swap
- Execute swaps (both same-chain and cross-chain)# Get top 10 tokens on Polygon
top_tokens = await get_chain_top_tokens("137", 10)
# Search for WETH tokens
weth_tokens = await search_dex_tokens("WETH", "1")
# Get market summary for ETH
eth_summary = await get_dex_market_summary("ETH", "1")
# Get quote for swapping 0.1 ETH to USDC on Ethereum
quote = await get_dex_quote(
from_token="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", # ETH
to_token="0xA0b86a33E6Ba3E0E4Ca4ba5E7E5E8E8E8E8E8E8E", # USDC
amount="100000000000000000", # 0.1 ETH (18 decimals)
chain_id="1"
)
# Execute the swap (requires wallet private key)
result = await execute_dex_swap(
from_token="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
to_token="0xA0b86a33E6Ba3E0E4Ca4ba5E7E5E8E8E8E8E8E8E",
amount="100000000000000000",
chain_id="1",
user_wallet_address="0x...",
private_key="your_private_key",
slippage="0.5" # 0.5%
)
"API credentials invalid"
"Insufficient liquidity"
"Transaction failed"
Enable detailed logging:
import logging
logging.basicConfig(level=logging.DEBUG)
Network | Chain ID | Native Token |
---|---|---|
Ethereum | 1 | ETH |
Polygon | 137 | MATIC/POL |
BSC | 56 | BNB |
Avalanche | 43114 | AVAX |
Arbitrum | 42161 | ETH |
Optimism | 10 | ETH |
Fantom | 250 | FTM |
Solana | 501 | SOL |
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/okx/okx-dex-mcp.git
cd okx-dex-mcp
pip install -e ".[dev]"
pytest tests/
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer: This software is for educational and development purposes. Always test with small amounts first and understand the risks involved in DeFi trading. The authors are not responsible for any financial losses.
FAQs
OKX DEX Trading MCP Server - Model Context Protocol server for decentralized exchange trading via OKX API
We found that okx-dex-mcp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.