@derp-trade/sdk
v0.2.0
Published
An SDK for derp.trade
Readme
@derp-trade/sdk
A TypeScript SDK for derp.trade, a Solana-based derivatives trading platform for DERPs, a new asset class based on perpetual futures.
Installation
npm install @derp-trade/sdkQuickstart
Initialize the SDK
import { DerpSDK } from '@derp-trade/sdk';
import { Connection, Keypair } from '@solana/web3.js';
import { Wallet } from '@coral-xyz/anchor';
// Create connection to Solana
const connection = new Connection('https://api.mainnet-beta.solana.com');
// Create wallet (replace with your keypair)
const keypair = Keypair.fromSecretKey(/* your secret key */);
const wallet = new Wallet(keypair);
// Initialize SDK
const sdk = new DerpSDK(connection, wallet);⚠️ Important: The wallet provided when constructing the SDK should have funds (SOL) on it, otherwise some SDK functions will fail.
Place Your First Order
import { BN } from '@coral-xyz/anchor';
async function placeOrder() {
const mintAddress = 'your_token_mint_address';
// Create order instructions
const orderInstructions = await sdk.getOrderInstructions(mintAddress, {
reduceOnly: false,
side: 'long',
// Order size in tokens with 6 decimals (e.g. this would be an order for 1 token)
size: new BN(1000000),
// 2x leverage (200% in basis points)
// NOTE: This argument is only provided for presentation purposes, the position will be opened at max leverage!
// To actually add margin to your position, use the deposit instruction.
leverageBps: new BN(20000)
});
// Send transaction
const signature = await sdk.provider.sendAndConfirm(
new web3.Transaction().add(...orderInstructions)
);
console.log('Order placed:', signature);
}Features
Market Support
- Pump.fun markets - Integrated with pump.fun tokens
- Bonk (Raydium Launch Lab) markets - Raydium Launch Lab integrated markets
- External markets - Support for external pools (currently RETARDIO token)
Core Functionality
- Place and manage DERPs orders
- Deposit and withdraw collateral
- Query market data and positions
- Real-time price updates from multiple DEX sources
- Automatic market type detection
Available Methods
Trading Operations
// Create order
await sdk.getOrderInstructions(mintAddress, orderParams);
// Deposit collateral
await sdk.rawDepositInstruction(mintAddress, amount);
// Close position and withdraw collateral
await sdk.getClosePositionInstructions(mintAddress);
// Withdraw collateral
await sdk.rawWithdrawInstruction(mintAddress);Market Data
// Get market status (prices, funding, etc.)
const status = await sdk.marketStatus(mintAddress);
// Fetch and decode the market state account
const market = await sdk.rawMarket(mintAddress);
// Fetch and decode the position state account
const position = await sdk.positionState(mintAddress, userAddress);
// Fetch and decode the global config account
const config = await sdk.config();Advanced Usage
The SDK exposes a fully featured and typed Anchor client instance via sdk.program. This allows you to implement any custom use cases directly:
// Access the underlying Anchor program
const program = sdk.program;
// Use any program method directly
const accounts = await program.account.marketState.all();
// Build custom instructions
const customIx = await program.methods
.someCustomMethod()
.accounts({
// your accounts
})
.instruction();Market Types
The SDK automatically detects market types based on the mint address:
- pump: Pump.fun integrated markets
- bonk: Raydium Launch Lab (Bonk) integrated markets
- external: External pools (currently supports RETARDIO token)
Documentation
For comprehensive documentation, examples, and API reference, visit docs.derp.trade.
Development
# Install dependencies
npm install
# Build the SDK
npm run build
# Run tests
npm run test:run
# Clean build
npm run build:cleanLicense
MIT
