Javascript SDK
A powerful JavaScript SDK for integrating with the 1DEX decentralized exchange platform, providing seamless access to trading functionality and market data.
1DEX JavaScript SDK
A powerful JavaScript SDK for integrating with the 1DEX decentralized exchange platform, providing seamless access to trading functionality and market data.
Installation
npm install 1dex-js-sdkGetting Started
Initializing the SDK
import { DexKit, ETradeSide, EOrderType } from "1dex-js-sdk";
// Create a new DexKit instance
const dexKit = new DexKit({
apiKey: "YOUR_API_KEY",
secretKey: "YOUR_SECRET_KEY",
enableProxy: false, // Optional, defaults to true
apiClientConfig: {
baseUrl: "https://api-v1.example.com", // Optional, defaults to 'https://api-v1.1dex.com'
},
blockchainRpcClientConfig: {
chainID: "YOUR_CHAIN_ID", // Optional, defaults to 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'
rpcUrl: "https://rpc.example.com", // Optional, defaults to 'https://spring-rpc.1dex.com'
},
devMode: false, // Optional, if set to true, it will output debug information of certain methods in the console
version: "v2" // Optional, if set to 'v2', it will enable AMM listing, default is 'v1'
});
// Initialize the DexKit instance
await dexKit.initialize();DexKit Interface
The DexKit class provides methods for trading operations on 1DEX.
Core Methods
initialize()
Initializes the DexKit instance by fetching system metadata, account information, and pool data.
initializeWithProvidedConfig(config)
Initializes the DexKit instance using the provided configuration instead of getting it from the server.
All parameters are optional.
placeLimitOrder(params)
Places a limit order on the specified pool.
If it is a buy order, the amount is the quantity of quote coin, if it is a sell order, the amount is the quantity of base coin.
For example, there is a BTC/USDT trading pair. If it is a buy order, 'amount = 80000' means '80000 USDT', if it is a sell order, 'amount = 1' means '1 BTC'.
Note: the amount will be rounded up to the precision unit, which means that if you enter 10.00001 EOS, it will be formatted as 10.0001 EOS, so it is recommended to enter the amount according to the token decimals.
placeMarketOrder(params)
Places a market order on the specified pool.
If it is a buy order, the amount is the quantity of quote coin, if it is a sell order, the amount is the quantity of base coin.
For example, there is a BTC/USDT trading pair. If it is a buy order, 'amount = 80000' means '80000 USDT', if it is a sell order, 'amount = 1' means '1 BTC'.
Note: the amount will be rounded up to the precision unit, which means that if you enter 10.00001 EOS, it will be formatted as 10.0001 EOS, so it is recommended to enter the amount according to the token decimals.
cancelOrder(params)
Cancels an existing order.
cancelOrderByCid(cid)
Cancels an existing order by client order id.
Client order id will be returned by placeMarketOrder and placeLimitOrder.
batchCancelOrders(params)
Cancels multiple open orders at once.
Resource Management
getAccountResources(account)
Gets the account resources including CPU, NET, and RAM information.
If name is empty, the default sub-account's name obtained during initialization is used.
powerup(params)
Powers up the account with CPU and NET resources.
Constructor Options
When creating a new DexKit instance, you can provide various configuration options:
HTTP API Client
The DexKit instance exposes an httpApiClient property that provides access to various API endpoints for retrieving market data and account information.
Account and Balance
getAccount()
Retrieves account information.
getBalance()
Retrieves the user's balance information.
Market Data
getAllPools(params?)
Retrieves all available trading pools.
getPoolInfo(symbolOrPoolID)
Retrieves detailed information about a specific pool.
getDepth(params)
Retrieves order book depth data for a specific pool.
getKline(params)
Retrieves kline/candlestick data for a specific pool.
getLatestTrades(params)
Retrieves the latest trades for a specific pool.
Order Management
getOpenOrders(params)
Retrieves open (active) orders.
getOrderHistory(params)
Retrieves order history.
getOrderDetail(params)
Retrieves detailed information about a specific order.
getOrderDetailByCid(cid)
Retrieves detailed information about a specific order by client order id.
Token Information
getSupportedTokens()
Retrieves all supported tokens.
getTokenInfo(token)
Retrieves detailed information about a specific token.
Complete Trading Example
Powerup Example
Error Handling
The SDK uses standardized error handling. Errors thrown by the SDK include detailed information about what went wrong. It's recommended to use try-catch blocks when interacting with the SDK:
Last updated
