npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@_0xboji/aster-connector-ts

v1.0.2

Published

TypeScript SDK for Aster DEX API

Readme

Aster DEX TypeScript SDK

npm version License: MIT TypeScript

A modern TypeScript SDK for the Aster DEX API.

✨ Features

  • 🖋️ 100% TypeScript - Full type safety and IntelliSense support
  • 🧪 Well-tested - Comprehensive test coverage
  • 📦 Tree-shakeable - Import only what you need for minimal bundle size
  • 🔧 Flexible Architecture - Multiple API access patterns (OOP & Functional)
  • 🌐 Cross-Environment - Works in Node.js, browsers, and edge runtimes
  • 🚀 Modern - Built with latest TypeScript and ES2022 features
  • 📚 Well-documented - JSDoc annotations and examples

📦 Installation

npm install @_0xboji/aster-connector-ts
yarn add @_0xboji/aster-connector-ts
pnpm add @_0xboji/aster-connector-ts

🚀 Quick Start

Market Data (Public API)

import { HttpTransport, MarketClient } from "@_0xboji/aster-connector-ts";

const transport = new HttpTransport();
const client = new MarketClient({ transport });

// Get 24hr ticker
const ticker = await client.ticker24hr({ symbol: "BTCUSDT" });
console.log(`BTC Price: ${ticker.lastPrice}`);

// Get order book
const depth = await client.depth({ symbol: "BTCUSDT", limit: 10 });
console.log(`Best Bid: ${depth.bids[0][0]}`);

// Get klines
const klines = await client.klines({
  symbol: "BTCUSDT",
  interval: "1h",
  limit: 24,
});

Trading (Authenticated API)

import { HttpTransport, TradingClient } from "@_0xboji/aster-connector-ts";

const transport = new HttpTransport();
const client = new TradingClient({
  transport,
  apiKey: "your-api-key",
  secretKey: "your-secret-key",
});

// Get account information
const account = await client.account();
console.log(`Balance: ${account.totalWalletBalance}`);

// Place a limit order
const order = await client.newOrder({
  symbol: "BTCUSDT",
  side: "BUY",
  type: "LIMIT",
  timeInForce: "GTC",
  quantity: "0.001",
  price: "50000",
});
console.log(`Order ID: ${order.orderId}`);

// Get open orders
const openOrders = await client.getOpenOrders({ symbol: "BTCUSDT" });

// Cancel an order
await client.cancelOrder({ symbol: "BTCUSDT", orderId: order.orderId });

// Create listen key for WebSocket user data stream
const { listenKey } = await client.newListenKey();
console.log(`Listen Key: ${listenKey}`);

// Keep-alive listen key (must be called every 30 minutes)
await client.renewListenKey();

// Close listen key when done
await client.closeListenKey();

WebSocket Streams

import { WebSocketTransport } from "@_0xboji/aster-connector-ts";

const ws = new WebSocketTransport({
  debug: true,
  reconnect: true,
});

await ws.connect();

// Subscribe to ticker updates
const tickerSub = await ws.subscribe("btcusdt@ticker", (data) => {
  console.log(`Price: ${data.c}, 24h Change: ${data.P}%`);
});

// Subscribe to trade updates
const tradeSub = await ws.subscribe("btcusdt@trade", (data) => {
  console.log(`Trade: ${data.p} @ ${data.q}`);
});

// Unsubscribe when done
await tickerSub.unsubscribe();
await tradeSub.unsubscribe();
ws.disconnect();

🌲 Tree-shakeable API Functions

For minimal bundle size in frontend applications, you can import individual API functions:

import { HttpTransport } from "@_0xboji/aster-connector-ts";
import { ticker24hr, depth } from "@_0xboji/aster-connector-ts/api/market";
import { account, newOrder } from "@_0xboji/aster-connector-ts/api/trading";

const transport = new HttpTransport();

// Market data
const ticker = await ticker24hr({ transport }, { symbol: "BTCUSDT" });
const orderBook = await depth({ transport }, { symbol: "BTCUSDT", limit: 10 });

// Trading (with credentials)
const context = {
  transport,
  apiKey: "your-api-key",
  secretKey: "your-secret-key",
};

const acc = await account(context);
const order = await newOrder(context, {
  symbol: "BTCUSDT",
  side: "BUY",
  type: "LIMIT",
  price: "50000",
  quantity: "0.001",
  timeInForce: "GTC",
});

Benefits:

  • ✅ Import only what you need
  • ✅ Smaller bundle size
  • ✅ Better for frontend applications
  • ✅ Same functionality as client classes

📖 API Documentation

Transport Layer

HttpTransport

import { HttpTransport } from "@_0xboji/aster-connector-ts";

const transport = new HttpTransport({
  baseUrl: "https://fapi.asterdex.com", // optional
  timeout: 10000, // optional (ms)
  debug: false, // optional
  headers: {}, // optional custom headers
});

WebSocketTransport

import { WebSocketTransport } from "@_0xboji/aster-connector-ts";

const ws = new WebSocketTransport({
  wsUrl: "wss://fstream.asterdex.com", // optional
  debug: false, // optional
  reconnect: true, // optional
  reconnectDelay: 5000, // optional (ms)
  maxReconnectAttempts: 10, // optional
});

Client Classes

MarketClient (Public API)

Methods:

  • ping() - Test connectivity
  • time() - Get server time
  • exchangeInfo() - Get exchange trading rules
  • depth(params) - Get order book
  • trades(params) - Get recent trades
  • historicalTrades(params) - Get historical trades
  • aggTrades(params) - Get aggregate trades
  • klines(params) - Get candlestick data
  • indexPriceKlines(params) - Get index price klines
  • markPriceKlines(params) - Get mark price klines
  • markPrice(params) - Get mark price and funding rate
  • fundingRate(params) - Get funding rate history
  • ticker24hr(params) - Get 24hr ticker statistics
  • tickerPrice(params) - Get symbol price
  • bookTicker(params) - Get best bid/ask

TradingClient (Authenticated API)

Order Management:

  • newOrder(params) - Place a new order
  • newBatchOrder(params) - Place multiple orders
  • queryOrder(params) - Query order status
  • cancelOrder(params) - Cancel an order
  • cancelAllOrders(params) - Cancel all open orders
  • cancelBatchOrders(params) - Cancel multiple orders
  • countdownCancelAll(params) - Auto-cancel all orders
  • getOpenOrders(params) - Get current open orders
  • getAllOrders(params) - Get all orders

Account & Balance:

  • balance() - Get account balance
  • account() - Get account information
  • getPositionRisk(params) - Get position information
  • getAccountTrades(params) - Get trade history
  • getIncomeHistory(params) - Get income history

Leverage & Margin:

  • changeLeverage(params) - Change leverage
  • changeMarginType(params) - Change margin type
  • modifyIsolatedPositionMargin(params) - Modify position margin
  • getPositionMarginHistory(params) - Get margin history
  • getLeverageBrackets(params) - Get leverage brackets

Risk Management:

  • getADLQuantile(params) - Get ADL quantile estimation
  • getForceOrders(params) - Get liquidation orders
  • getCommissionRate(params) - Get commission rate

Position Mode:

  • changePositionMode(params) - Change position mode
  • getPositionMode() - Get current position mode
  • changeMultiAssetMode(params) - Change multi-asset mode
  • getMultiAssetMode() - Get current multi-asset mode

Listen Key (User Data Stream):

  • newListenKey() - Create listen key for user data stream
  • renewListenKey() - Keep-alive user data stream
  • closeListenKey() - Close user data stream
  • getOpenOrder(params) - Query single open order

📝 Examples

Check out the /examples directory for more detailed examples:

🏗️ Architecture

This SDK is inspired by the Hyperliquid SDK architecture:

aster-connector-ts/
├── src/
│   ├── transport/          # Transport layer (HTTP, WebSocket)
│   ├── clients/            # Client classes (OOP style)
│   ├── api/                # Tree-shakeable functions
│   │   ├── market/         # Market data functions
│   │   └── trading/        # Trading functions
│   ├── types/              # TypeScript types
│   │   ├── common.ts       # Common types
│   │   ├── market.ts       # Market data types
│   │   └── trading.ts      # Trading types
│   └── utils/              # Utilities
│       ├── signature.ts    # HMAC signature generation
│       ├── formatters.ts   # Data formatters
│       └── errors.ts       # Error classes
├── examples/               # Usage examples
└── tests/                  # Test files

Design Principles

  1. Transport Pattern - Pluggable HTTP/WebSocket transports for flexibility
  2. Multiple API Patterns - Both OOP (client classes) and functional styles
  3. Tree-shaking - Import only what you need
  4. Type Safety - Full TypeScript support with comprehensive types
  5. Error Handling - Custom error classes for better debugging

🔒 Security

  • Never commit your API keys to version control
  • Use environment variables for credentials
  • Consider using a .env file (add to .gitignore)
  • Be careful when testing on mainnet
// Good practice
const apiKey = process.env.ASTER_API_KEY;
const secretKey = process.env.ASTER_SECRET_KEY;

🛠️ Development

# Install dependencies
npm install

# Build the project
npm run build

# Run type checking
npm run type-check

# Run linter
npm run lint

# Format code
npm run format

# Watch mode (development)
npm run dev

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support

⚠️ Disclaimer

This is an unofficial SDK. Use at your own risk. Always test thoroughly before using in production.


Made with ❤️ by the Aster DEX community