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 🙏

© 2024 – Pkg Stats / Ryan Hefner

max-exchange-api-node

v3.0.0

Published

Node.js client library for MAX Exchange API

Downloads

99

Readme

MAX Exchange API for Node.js

A Node.js implementation of MAX exchange API

  • MAX V3 RESTful API
  • WebSocket API
  • Supports both CommonJS and ES Modules

This library provides a flexible and easy-to-use interface for interacting with the MAX exchange API. It is designed to work seamlessly in both CommonJS and ES Module environments, allowing you to use it in a wide range of Node.js projects.

Features

  • Full support for MAX exchange REST API V3
  • Real-time data streaming with WebSocket API
  • Compatible with CommonJS (require()) and ES Modules (import)
  • Comprehensive error handling
  • Time synchronization utilities

Migration from v2

If you're upgrading from v2.0.0 to v3.0.x, please check our Migration Guide for detailed information about breaking changes and new features.

Documentation

Installation

npm install max-exchange-api-node

See /docs for MAX, MaxSDK, and WebSocketAPI methods.

See /examples for usage examples.

Usage

You can use this library with either CommonJS or ES Modules syntax:

ES Modules

import { MAX } from 'max-exchange-api-node';

const max = new MAX({
  accessKey: 'YOUR_ACCESS_KEY',
  secretKey: 'YOUR_SECRET_KEY'
});

CommonJS

const { MAX } = require('max-exchange-api-node');

const max = new MAX({
  accessKey: 'YOUR_ACCESS_KEY',
  secretKey: 'YOUR_SECRET_KEY'
});

REST API

Access the REST API through max.rest:

import { MAX } from 'max-exchange-api-node';

const { rest } = new MAX({
  accessKey: 'YOUR_ACCESS_KEY',
  secretKey: 'YOUR_SECRET_KEY'
});

// Get current markets
try {
  const markets = await rest.getMarkets();
  console.log(markets);
} catch (error) {
  console.error(error.message);
}

// Get account balances
try {
  const accounts = await rest.spotWallet.getAccounts({ market: 'btc' });
  console.log(accounts);
} catch (error) {
  console.error(error.message);
}

// Place a limit order
try {
  const order = await rest.spotWallet.submitOrder({
    market: 'btctwd',
    side: 'buy',
    volume: '0.001',
    price: '500000',
    ord_type: 'limit'
  });
  console.log(order);
} catch (error) {
  console.error(error.message);
}

// Get open orders
try {
  const orders = await rest.spotWallet.getOpenOrders({ market: 'btctwd' });
  console.log(orders);
} catch (error) {
  console.error(error.message);
}

WebSocket API

Access the WebSocket API through max.ws:

import { MAX } from 'max-exchange-api-node';

const { ws } = new MAX({
  accessKey: 'YOUR_ACCESS_KEY',
  secretKey: 'YOUR_SECRET_KEY'
});

// Subscribe to orderbook updates
ws.subscribe('book', 'btctwd', { depth: 5 });

// Subscribe to trade updates
ws.subscribe('trade', 'btctwd');

ws.on('open', () => {
  console.log('WebSocket connected');
});

ws.on('book.snapshot', (data) => {
  console.log('Orderbook snapshot:', data);
});

ws.on('book.update', (data) => {
  console.log('Orderbook update:', data);
});

ws.on('trade.update', (data) => {
  console.log('New trade:', data);
});

ws.on('error', (error) => {
  console.error('WebSocket error:', error);
});

ws.on('close', () => {
  console.log('WebSocket disconnected');
});

ws.connect();

Error Handling

Both REST and WebSocket methods may throw errors. It's recommended to use try-catch blocks to handle potential errors:

import { MAX } from 'max-exchange-api-node';

const { rest } = new MAX({
  accessKey: 'YOUR_ACCESS_KEY',
  secretKey: 'YOUR_SECRET_KEY'
});

try {
  const ticker = await rest.getTicker({ market: 'btctwd' });
  console.log(ticker);
} catch (error) {
  console.error('An error occurred:', error.message);
}

Calibrating Time

To ensure your local time is synchronized with the server time, you can use the calibrateTime method:

import { MAX } from 'max-exchange-api-node';

const { rest } = new MAX({
  accessKey: 'YOUR_ACCESS_KEY',
  secretKey: 'YOUR_SECRET_KEY'
});

try {
  const message = await rest.calibrateTime();
  console.log(message);
} catch (error) {
  console.error('Failed to calibrate time:', error.message);
}

For more detailed information about available methods and their parameters, please refer to the documentation in the /docs directory.

Contributing

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

License

This project is licensed under the MIT License.