@bluefin-exchange/pro-sdk

中文文档
2.4.0发布于 2026/10/30UnlicenseTypeScriptES Module近 30 天下载 3910

OpenAPI client for @bluefin-exchange/pro-sdk

原始使用文档
文档目录17 节
  1. Installation
  2. Peer Dependencies
  3. Quick Start
  4. 1. Initialize the SDK
  5. 2. Get Market Data
  6. 3. Place an Order
  7. 4. Get Account Information
  8. WebSocket Streams
  9. Market Data Stream
  10. Account Data Stream
  11. Advanced Features
  12. Deposit and Withdraw
  13. Update Leverage
  14. Adjust Isolated Margin
  15. Batch Claim Rewards
  16. API Reference
  17. Environment Configuration

Bluefin Pro SDK for TypeScript/JavaScript

TypeScript/JavaScript SDK for interacting with the Bluefin Pro exchange API and Sui blockchain contracts.

npm version

Installation

Install the SDK using npm or yarn:

npm install @bluefin-exchange/pro-sdk
# or
yarn add @bluefin-exchange/pro-sdk

Peer Dependencies

The SDK requires the following peer dependencies:

npm install @mysten/sui

Quick Start

1. Initialize the SDK

import {
  BluefinProSdk,
  BluefinRequestSigner,
  makeSigner,
} from "@bluefin-exchange/pro-sdk";
import { SuiGrpcClient } from "@mysten/sui/grpc";
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 SuiGrpcClient({ network: "mainnet", baseUrl: "https://fullnode.mainnet.sui.io:443" })
);

// Initialize the SDK (authenticates and loads exchange configuration)
await client.initialize();

The SDK accepts any @mysten/sui client implementing the Core API. Use SuiGrpcClient — Sui's JSON-RPC interface is deprecated. If you are upgrading from SuiJsonRpcClient, swapping the client is the only change required.

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 leverage

Adjust Isolated Margin

// Add margin to isolated position
await client.adjustIsolatedMargin("BTC-PERP", "100000000000", true); // Add 100 USDC

Batch 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.

版本与发布记录

@bluefin-exchange/pro-sdk 共发布 89 个版本,首次发布于 2025/02/20;过去 12 个月发布了 26 个版本。

版本发布日期距今
2.4.0latest2026/10/309 天前
2.3.12026/10/0830 天前
2.2.02026/09/091 个月前
2.1.0pre-release2026/07/084 个月前
2.0.02026/04/106 个月前
2.0.0-beta.32026/04/077 个月前

关于 @bluefin-exchange/pro-sdk 的常见问题

@bluefin-exchange/pro-sdk 是什么?

OpenAPI client for @bluefin-exchange/pro-sdk

如何安装 @bluefin-exchange/pro-sdk?

在项目目录运行 npm install @bluefin-exchange/pro-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@mysten/sui(^2.13.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bluefin-exchange/pro-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bluefin-exchange/pro-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bluefin-exchange/pro-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bluefin-exchange/pro-sdk 可以商用吗?

@bluefin-exchange/pro-sdk 使用 Unlicense 许可。作者将代码贡献到公共领域,可不受限制地使用。以上为概括,不构成法律意见,请以许可原文为准。

@bluefin-exchange/pro-sdk 的下载量有多少?

根据 npm 官方下载统计,@bluefin-exchange/pro-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,910 次,日均约 130 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bluefin-exchange/pro-sdk 还在维护吗?

最新版本 2.4.0 发布于 2026/10/30(9 天前);至今共发布 89 个版本,其中过去 12 个月发布了 26 个;首次发布于 2025/02/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。