DeltaTradeSDK is a JavaScript SDK for interacting with the Delta Trade platform, supporting both NEAR and Solana blockchains.
Install DeltaTradeSDK using npm or pnpm:
npm install @delta-trade/core
# or
pnpm add @delta-trade/core
Before using the SDK, you need to initialize it. You can do this using the DeltaTradeSDK.initEnv
method.
import DeltaTradeSDK from '@delta-trade/core';
const sdk = DeltaTradeSDK.initEnv({
chain: 'near', // or 'solana'
network: 'testnet', // or 'mainnet'
accountId: 'your-account-id', // optional
nearConfig: {
jsonRpcUrls: ['https://rpc.testnet.near.org'], // optional
},
solanaConfig: {
endpoint: 'https://api.testnet.solana.com', // optional
},
});
sdk.changeEnv({
chain: 'near',
network: 'testnet',
accountId: 'your-account-id',
});
For more detailed examples, please refer to the examples directory in the repository.
To create a vault, you need a pairId
. You can retrieve available pairs using the following method:
const pairs = await sdk.getPairs({ type: 'dca' });
console.log('Available Pairs:', pairs);
// Example: Selecting a pairId
const pairId = pairs[0]?.pair_id;
console.log('Selected Pair ID:', pairId);
const createParams = {
pairId: 'pair-id',
tradeType: 'buy',
startTime: Date.now() + 1000 * 60 * 5,
intervalTime: 0,
singleAmountIn: 10,
count: 10,
name: 'test-dca-vault',
recommender: '',
lowestPrice: 0,
highestPrice: 0,
};
const errors = await sdk.validateDCAVaultParams(createParams);
if (!errors) {
const transaction = await sdk.createDCAVault(createParams);
console.log('Transaction:', transaction);
// sign and send transaction
const wallet = await walletSelector?.wallet();
await wallet.signAndSendTransactions(transaction);
} else {
console.error('Validation Errors:', errors);
}
const gridParams = {
pairId: 'pair-id',
minPrice: '0.1',
maxPrice: '1.0',
gridAmount: 10,
quantityPreGrid: '100',
name: 'test-grid-vault',
slippage: 1,
};
const gridErrors = await sdk.validateGridVaultParams(gridParams);
if (!gridErrors) {
const gridTransaction = await sdk.createGridVault(gridParams);
console.log('Grid Transaction:', gridTransaction);
} else {
console.error('Grid Validation Errors:', gridErrors);
}
const swingParams = {
pairId: 'pair-id',
tradeType: 'buy',
buyPrice: '0.5',
sellPrice: '1.0',
everyPhasedAmount: '50',
name: 'test-swing-vault',
};
const swingErrors = await sdk.validateSwingVaultParams('classic', swingParams);
if (!swingErrors) {
const swingTransaction = await sdk.createClassicSwingVault(swingParams);
console.log('Swing Transaction:', swingTransaction);
} else {
console.error('Swing Validation Errors:', swingErrors);
}
const phasedSwingParams = {
pairId: 'pair-id',
tradeType: 'buy',
gridAmount: 5,
intervalPrice: '0.1',
everyPhasedAmount: '50',
highestBuyPrice: '1.0',
name: 'test-phased-swing-vault',
};
const phasedSwingErrors = await sdk.validateSwingVaultParams('phased', phasedSwingParams);
if (!phasedSwingErrors) {
const phasedSwingTransaction = await sdk.createPhasedSwingVault(phasedSwingParams);
console.log('Phased Swing Transaction:', phasedSwingTransaction);
} else {
console.error('Phased Swing Validation Errors:', phasedSwingErrors);
}
const myGridVaults = await sdk.getMyGridVaults();
console.log('My Grid Vaults:', myGridVaults);
const mySwingVaults = await sdk.getMySwingVaults();
console.log('My Swing Vaults:', mySwingVaults);
const myDCAVaults = await sdk.getMyDCAVaults();
console.log('My DCA Vaults:', myDCAVaults);
const claimResult = await sdk.claimGridVault({ botId: 'your-vault-id' });
console.log('Claim Result:', claimResult);
const closeResult = await sdk.closeGridVault({ botId: 'your-vault-id' });
console.log('Close Result:', closeResult);
const marketInfo = await sdk.getMarketInfo();
console.log('Market Info:', marketInfo);
const assets = await sdk.getAccountAssets();
console.log('Account Assets:', assets);
const result = await sdk.withdrawAccountAsset({ assetId: 'your-asset-id', amount: 100 });
console.log('Withdraw Result:', result);
const referralUrl = await sdk.generateReferralUrl();
console.log('Referral URL:', referralUrl);
-
DeltaTradeSDK.initEnv(params)
: Initialize the SDK environment.- Parameters:
params.chain
:'near' | 'solana'
params.network
:'mainnet' | 'testnet'
params.accountId
:string
(optional)params.nearConfig
:{ jsonRpcUrls?: string[] }
(optional)params.solanaConfig
:{ endpoint?: string }
(optional)
- Returns:
DeltaTradeSDK
instance
- Parameters:
-
sdk.changeEnv(params)
: Change the SDK environment.- Parameters:
Partial<SDKParams>
- Parameters:
-
sdk.getMarketInfo()
: Get market information.- Returns:
Promise<MarketInfo>
- Returns:
-
sdk.getPairs(params)
: Retrieve available trading pairs.- Parameters:
{ type: string }
- Returns:
Promise<Pair[]>
- Parameters:
-
sdk.getPairPrices(pairIds)
: Get prices for specific pairs.- Parameters:
string[]
- Returns:
Promise<Price[]>
- Parameters:
-
sdk.validateDCAVaultParams(params)
: Validate parameters for creating a DCA vault.- Parameters:
CreateDCAVaultParams
- Returns:
Promise<ValidationErrors | null>
- Parameters:
-
sdk.createDCAVault(params)
: Create a DCA vault.- Parameters:
CreateDCAVaultParams
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.claimDCAVault(id)
: Claim a DCA vault.- Parameters:
string
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.closeDCAVault(id)
: Close a DCA vault.- Parameters:
string
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.validateGridVaultParams(params)
: Validate parameters for creating a grid vault.- Parameters:
CreateGridVaultParams
- Returns:
Promise<ValidationErrors | null>
- Parameters:
-
sdk.createGridVault(params)
: Create a grid vault.- Parameters:
CreateGridVaultParams
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.claimGridVault(id)
: Claim a grid vault.- Parameters:
string
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.closeGridVault(id)
: Close a grid vault.- Parameters:
string
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.validateSwingVaultParams(type, params)
: Validate parameters for creating a swing vault.- Parameters:
SwingVaultType
,CreateSwingVaultParams
- Returns:
Promise<ValidationErrors | null>
- Parameters:
-
sdk.createClassicSwingVault(params)
: Create a classic swing vault.- Parameters:
CreateClassicSwingVaultParams
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.createPhasedSwingVault(params)
: Create a phased swing vault.- Parameters:
CreatePhasedSwingVaultParams
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.claimSwingVault(id)
: Claim a swing vault.- Parameters:
string
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.closeSwingVault(id)
: Close a swing vault.- Parameters:
string
- Returns:
Promise<Transaction[]>
- Parameters:
-
sdk.getAccountAssets()
: Get account assets.- Returns:
Promise<AccountAssets>
- Returns:
-
sdk.withdrawAccountAsset(params)
: Withdraw an account asset.- Parameters:
{ assetId: string, amount: number }
- Returns:
Promise<Transaction[]>
- Parameters:
sdk.generateReferralUrl()
: Generate a referral URL.- Returns:
Promise<string>
- Returns:
Contributions are welcome! Please read CONTRIBUTING.md for more information.
ISC © Delta Trade