@bluefin-exchange/pro-sdk
v2.0.0
Published
OpenAPI client for @bluefin-exchange/pro-sdk
Downloads
4,489
Readme
Bluefin Pro SDK for TypeScript/JavaScript
TypeScript/JavaScript SDK for interacting with the Bluefin Pro exchange API and Sui blockchain contracts.
Installation
Install the SDK using npm or yarn:
npm install @bluefin-exchange/pro-sdk
# or
yarn add @bluefin-exchange/pro-sdkPeer Dependencies
The SDK requires the following peer dependencies:
npm install @mysten/suiQuick Start
1. Initialize the SDK
import {
BluefinProSdk,
BluefinRequestSigner,
makeSigner,
} from "@bluefin-exchange/pro-sdk";
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import { hexToBytes } from "@noble/hashes/utils.js";
// Create wallet from private key
const wallet = Ed25519Keypair.fromSecretKey(
hexToBytes("YOUR_PRIVATE_KEY_HEX")
);
// Or create wallet from mnemonic
// const wallet = Ed25519Keypair.deriveKeypair("your mnemonic phrase here");
// Create request signer
const signer = new BluefinRequestSigner(makeSigner(wallet, false));
// Initialize SDK client
const client = new BluefinProSdk(
signer,
"mainnet", // or "testnet" for staging, "devnet" for development
new SuiJsonRpcClient({ url: "https://fullnode.mainnet.sui.io:443", network: "mainnet" })
);
// Initialize the SDK (authenticates and loads exchange configuration)
await client.initialize();2. Get Market Data
// Get exchange information and available markets
const exchangeInfo = await client.exchangeDataApi.getExchangeInfo();
console.log("Available markets:", exchangeInfo.data.markets);
// Get market ticker
const ticker = await client.exchangeDataApi.getMarketTicker("BTC-PERP");
console.log("BTC-PERP ticker:", ticker.data);
// Get orderbook depth
const orderbook = await client.exchangeDataApi.getOrderbookDepth("BTC-PERP");
console.log("Orderbook:", orderbook.data);
// Get recent trades
const trades = await client.exchangeDataApi.getRecentTrades("BTC-PERP");
console.log("Recent trades:", trades.data);3. Place an Order
import { OrderType, OrderSide, OrderTimeInForce } from "@bluefin-exchange/pro-sdk";
const orderParams = {
clientOrderId: "unique-order-id-123",
type: OrderType.Limit,
symbol: "BTC-PERP",
priceE9: "45000000000000", // Price in E9 format (45000 * 1e9)
quantityE9: "100000000", // Quantity in E9 format (0.1 BTC * 1e9)
side: OrderSide.Long,
leverageE9: "2000000000", // 2x leverage
isIsolated: false,
expiresAtMillis: Date.now() + 24 * 60 * 60 * 1000, // 24 hours
postOnly: false,
reduceOnly: false,
timeInForce: OrderTimeInForce.Gtt,
};
const result = await client.createOrder(orderParams);
console.log("Order created:", result.data);4. Get Account Information
import { TradeType } from "@bluefin-exchange/pro-sdk";
// Get account details
const accountDetails = await client.accountDataApi.getAccountDetails(
wallet.getPublicKey().toSuiAddress()
);
console.log("Account details:", accountDetails.data);
// Get account trade history
const tradeHistory = await client.accountDataApi.getAccountTrades(
"BTC-PERP",
Date.now() - 7 * 24 * 60 * 60 * 1000, // Last 7 days
Date.now(),
100,
TradeType.Order,
1
);
console.log("Trade history:", tradeHistory.data);WebSocket Streams
Market Data Stream
Subscribe to real-time market data updates:
import { MarketDataStreamName } from "@bluefin-exchange/pro-sdk";
// Create market data stream listener
const marketListener = await client.createMarketDataStreamListener(
async (msg) => {
console.log("Market update:", msg);
}
);
// Subscribe to market data streams
await marketListener.send(
JSON.stringify({
method: "Subscribe",
dataStreams: [
{
symbol: "BTC-PERP",
streams: [
MarketDataStreamName.Ticker,
MarketDataStreamName.RecentTrade,
MarketDataStreamName.PartialDepth5,
],
},
],
})
);Account Data Stream
Subscribe to account updates:
import { AccountDataStream } from "@bluefin-exchange/pro-sdk";
// Create account data stream listener
const accountListener = await client.createAccountDataStreamListener(
async (msg) => {
console.log("Account update:", msg);
}
);
// Subscribe to account data streams
await accountListener.send(
JSON.stringify({
method: "Subscribe",
dataStreams: [
AccountDataStream.AccountOrderUpdate,
AccountDataStream.AccountPositionUpdate,
AccountDataStream.AccountTradeUpdate,
AccountDataStream.AccountTransactionUpdate,
AccountDataStream.AccountUpdate,
],
})
);Advanced Features
Deposit and Withdraw
// Deposit USDC to exchange (amount in base units)
await client.deposit("1000000000"); // 1 USDC (1 * 1e9)
// Withdraw USDC from exchange
await client.withdraw("USDC", "500000000"); // 0.5 USDC (0.5 * 1e9)Update Leverage
// Update leverage for a specific market
await client.updateLeverage("BTC-PERP", "5000000000"); // 5x leverageAdjust Isolated Margin
// Add margin to isolated position
await client.adjustIsolatedMargin("BTC-PERP", "100000000000", true); // Add 100 USDCBatch Claim Rewards
// Get available rewards
const rewards = await client.rewardsDataApi.getCampaignRewards(
"TRADE_AND_EARN",
wallet.getPublicKey().toSuiAddress()
);
// Claim rewards (see docs/batch-claim-rewards-guide.md for detailed guide)
const claimPayloads = /* transform rewards to BatchClaimParams */;
const txResult = await client.batchClaimRewards(claimPayloads);See docs/batch-claim-rewards-guide.md for a complete guide on claiming rewards.
API Reference
The SDK provides access to the following API categories:
- ExchangeDataApi: Market data, tickers, orderbooks, candles, funding rates
- AccountDataApi: Account details, positions, orders, trade history, transactions
- TradeApi: Order placement, cancellation, leverage updates
- AuthApi: Authentication and session management
- RewardsApi: Campaign rewards and claiming
For detailed API documentation, see the auto-generated docs in the src/docs directory.
Environment Configuration
The SDK supports three environments:
- mainnet: Production environment
- testnet: Staging environment for testing
- devnet: Development environment
Each environment has different API endpoints configured automatically.
See example.ts for the complete example code.
