🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@pear-protocol/exchanges-sdk

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pear-protocol/exchanges-sdk

Pear Protocol Exchanges SDK

npmnpm
Version
0.1.1
Version published
Weekly downloads
58
-55.04%
Maintainers
3
Weekly downloads
 
Created
Source

@pear-protocol/exchanges-sdk

Unified SDK for real-time account state (balance, positions, per-asset leverage) across supported derivative exchanges.

Supported Exchanges

ExchangeConnectorMarket
BinancebinanceUSDM Futures
BybitbybitLinear Perpetuals
HyperliquidhyperliquidPerpetuals
LighterlighterPerpetuals
OKXokxLinear SWAP

Installation

npm install @pear-protocol/exchanges-sdk

Quick Start

import PearSDK from '@pear-protocol/core-sdk';
import { ExchangesSDK } from '@pear-protocol/exchanges-sdk';

const sdk = new PearSDK({ /* ... */ });
const exchanges = new ExchangesSDK({ sdk });

const connection = await exchanges.connect(tradeAccountId, 'binance');
const tracker = exchanges.createTracker(connection);
await tracker.start();

const offBalance = tracker.trackBalance((balance) => {
  console.log(balance.totalEquity, balance.unrealizedPnl);
});

const offPositions = tracker.trackPosition((positions) => {
  for (const p of positions) console.log(p.symbol, p.side, p.size);
});

// Cleanup
offBalance();
offPositions();
await tracker.disconnect();

Pass demo: true to target testnet:

const exchanges = new ExchangesSDK({ sdk, demo: true });

Tracking

Each track* method returns an unsubscribe function. Callbacks fire with the current snapshot on subscribe (if available) and on every update.

Balance

tracker.trackBalance((balance) => {
  balance.totalEquity;
  balance.walletBalance;
  balance.unrealizedPnl;
  balance.availableToTrade;
  balance.initialMarginUsed;
  balance.maintenanceMargin;
  balance.marginRatio;
  balance.accountType;

  for (const a of balance.assets) {
    a.asset;         // "USDT", "USDC", ...
    a.free;
    a.used;
    a.total;
    a.usdValue;
  }
});

Positions

tracker.trackPosition((positions) => {
  for (const p of positions) {
    p.symbol;
    p.side;             // "long" | "short" | "both"
    p.size;
    p.entryPrice;
    p.unrealizedPnl;
    p.leverage;
    p.marginType;       // "cross" | "isolated"
    p.liquidationPrice; // string | null
  }
});

Closed positions (size === '0') are dropped automatically.

Per-Asset Leverage & Margin

tracker.trackAsset('ETH', (info) => {
  info.coin;
  info.leverage;
  info.marginType;
});

Asset symbol format per exchange:

ExchangeFormatExample
Binance<BASE><QUOTE>BTCUSDT
Bybit<BASE><QUOTE>BTCUSDT
Hyperliquidbase coinBTC
Lighterbase coinBTC
OKXinstIdBTC-USDT-SWAP

Snapshot Reads

Synchronous getters for the latest cached state:

tracker.getBalance();            // AccountBalance | null
tracker.getPositions();          // AccountPosition[]
tracker.getTrackedAsset('ETH');  // TrackedAssetInfo | null
tracker.isConnected;
tracker.isInitialized;           // true after first snapshot

Account Type Labels

balance.accountType is an exchange-specific enum. Render with:

import { ACCOUNT_TYPE_LABELS } from '@pear-protocol/exchanges-sdk';

ACCOUNT_TYPE_LABELS[balance.accountType]; // "Cross Margin", "Portfolio Margin", ...

Cleanup

await tracker.disconnect();

Credentials are fetched automatically on connect; for Hyperliquid and Lighter the account index is resolved from the backend.

FAQs

Package last updated on 29 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts