Introduction#
The OKX DEX SDK is a typescript toolkit for developers to integrate OKX DEX API functionalities into their applications.
GitHub Repository https://github.com/okx/okx-dex-sdk
To get started, follow the guide here: https://github.com/okx/okx-dex-sdk?tab=readme-ov-file#usage
Install the SDK#
npm install @okx-dex/okx-dex-sdk
# or
yarn add @okx-dex/okx-dex-sdk
# or
pnpm add @okx-dex/okx-dex-sdk
Setup Your Environment#
Create a .env file with your API credentials and wallet information.
# OKX API Credentials
OKX_API_KEY=your_api_key
OKX_SECRET_KEY=your_secret_key
OKX_API_PASSPHRASE=your_passphrase
OKX_PROJECT_ID=your_project_id
# Solana Configuration
SOLANA_RPC_URL=your_solana_rpc_url
SOLANA_WALLET_ADDRESS=your_solana_wallet_address
SOLANA_PRIVATE_KEY=your_solana_private_key
Initialize the Client#
Create a file for your DEX client (e.g., DexClient.ts): We use Solana as an example. You can change the dependency components according to your development needs :
# OKX API Credentials
// DexClient.ts
import { OKXDexClient } from '@okx-dex/okx-dex-sdk';
import 'dotenv/config';
// Validate environment variables
const requiredEnvVars = [
'OKX_API_KEY',
'OKX_SECRET_KEY',
'OKX_API_PASSPHRASE',
'OKX_PROJECT_ID',
'SOLANA_WALLET_ADDRESS',
'SOLANA_PRIVATE_KEY',
'SOLANA_RPC_URL'
];
for (const envVar of requiredEnvVars) {
if (!process.env[envVar]) {
throw new Error(`Missing required environment variable: ${envVar}`);
}
}
// Initialize the client
export const client = new OKXDexClient({
apiKey: process.env.OKX_API_KEY!,
secretKey: process.env.OKX_SECRET_KEY!,
apiPassphrase: process.env.OKX_API_PASSPHRASE!,
projectId: process.env.OKX_PROJECT_ID!,
solana: {
connection: {
rpcUrl: process.env.SOLANA_RPC_URL!,
wsEndpoint: process.env.SOLANA_WS_URL,
confirmTransactionInitialTimeout: 5000
},
walletAddress: process.env.SOLANA_WALLET_ADDRESS!,
privateKey: process.env.SOLANA_PRIVATE_KEY!,
computeUnits: 300000,
maxRetries: 3
}
});
Table of contents