Okx dex
OKX DEX Starter
A comprehensive integration example for using OKX DEX with Solana Agent Kit. This package provides a CLI-based trading bot that allows you to get quotes, execute swaps, and manage tokens directly from your terminal.
Features
- Token Swapping: Swap between any tokens available on OKX DEX
- Price Quotes: Get real-time quotes with price impact and fee information
- Token Discovery: Automatic token resolution and information caching
- Interactive CLI: User-friendly command-line interface for trading
- AI-Powered Assistance: Optional AI trading assistant using LangChain
- Transaction Monitoring: Real-time feedback for transaction status
Prerequisites
- Node.js 16 or higher
- Solana wallet with private key
- OKX account with API credentials
Installation
- Clone the repository or create a new project:
- Install dependencies:
- Set up environment variables by creating a
.env
file:
Quick Start
Create a file named okx-dex-solana.ts
with the implementation code and run:
Usage
Once the trading bot is running, you can use the following commands:
swap [amount] [from_token] to [to_token]
- Prepare a token swapquote [amount] [from_token] to [to_token]
- Get a quote without executingconfirm
- Execute the prepared swapcancel
- Cancel the current swaptokens
- List all known tokenstokens [search]
- Search for a specific tokenhelp
- Show available commandsexit
- Exit the bot
Examples
You can also ask natural language questions and get AI-powered trading assistance:
Core Components
Token Management
The integration includes a token cache system that learns about tokens as they’re used:
Getting Quotes
The integration uses the OKX DEX API to fetch quotes for token swaps:
Executing Swaps
Swaps are executed using the OKX DEX SDK:
AI Trading Assistant (Optional)
The integration includes an optional AI trading assistant using LangChain:
Configuration Details
OKX DEX Client Initialization
Amount Formatting
The integration includes utilities for formatting token amounts correctly:
Error Handling
The integration includes comprehensive error handling:
Token Resolution
The integration can resolve tokens by symbol or address:
Common Tokens
Here are some common tokens you can use with this integration:
Symbol | Address | Decimals |
---|---|---|
SOL | So11111111111111111111111111111111111111112 | 9 |
USDC | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v | 6 |
USDT | Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB | 6 |
Troubleshooting
Common Issues
-
Invalid private key
- Ensure your private key is in base58 format
- Check for extra whitespace or special characters
-
Connection errors
- Verify your OKX API credentials
- Check your internet connection
- Try using a different RPC URL
-
Swap failures
- Check token balances
- Verify token addresses
- Increase slippage for volatile tokens
Debugging Tips
The integration includes extensive debug logging:
Advanced Features
Custom Slippage
Token Price Monitoring
Resources
License
MIT
Was this page helpful?