Skip to content

maicoin/max-exchange-api-node

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

MAX Exchange API for Node.js

A node.js implementation of MAX exchange API

  • REST API V2
  • Websocket API

Documentations

Installation

npm install max-exchange-api-node

see /docs for MAX and RESTV2, WebSocketAPI methods.

see /examples for WebSocket Usages.

Usage

MAX constructor will return a client manager to support REST API.

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

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

MAX object will cache client by versions.

const rest = max.rest() // default version is 2
const rest2 = max.rest(2) // the same client as rest

// get current markets
rest.markets()
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.log(error.message)
  })

// retrieve orders which is in `wait`, `convert`, or `done` state
rest.orders({ market: 'maxtwd', state: ['wait', 'convert', 'done'] })
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.log(error.message)
  })
})

Example for subscribing orderbook from websocket API

const ws = max.ws()
const book = new WebSocketBook(ws, 'btctwd', 10)

book.onUpdate((book) => {
  book.pretty()
})

ws.on('error', (errors) => {
  console.error(errors)
})
// ws.on('raw', (body) => console.log(body) )
ws.connect()