Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

poloniex-api-node

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

poloniex-api-node

Simple node.js wrapper for Poloniex REST and WebSocket API.

  • 3.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
295
increased by132.28%
Maintainers
1
Weekly downloads
 
Created
Source

poloniex-api-node

Tests

poloniex-api-node is a simple node.js wrapper for Poloniex REST and WebSocket API.

Contents

Changelog

See detailed GitHub Releases

Breaking changes introduced in version 3.0.0

Legacy Poloniex API is no longer supported. Poloniex has announced that the legacy API is slated to be decommissioned on Jan 31st, 2023. Module supporting the legacy API has been moved to branch legacy_API, and it is not longer maintained.

Install

npm install --save poloniex-api-node

Usage

Constructor

  • new Poloniex({ apiKey, apiSecret })

To access the private Poloniex API methods you must supply your API key id and key secret. If you are only accessing the public API endpoints, you can leave the parameter out.

Examples:

const poloniex = new Poloniex({ apiKey: 'myKey', apiSecret: 'mySecret' })

REST API

Properties

  • apiCallRateLimits - API call rate limits for endpoints sets (resource-intensive and non-resource-intensive private and public endpoints)

    Example output:

    {
    riPub: 10,
    nriPub: 200,
    nriPriv: 50,
    riPriv: 10
    }
    
  • apiCallRates - Current call rate for resource-intensive and non-resource-intensive private and public API calls

    Example output:

    {
    riPub: 8,
    nriPub: 100,
    nriPriv: 5,
    riPriv: 7
    }
    

See https://docs.poloniex.com/#rate-limits.

Methods

All methods accept one object parameter, which is used to pass all request parameters for the API call.

Official Poloniex API documentation lists all valid Request Parameters for API calls. When a Request Parameter needs to be included, a property with the exact same name needs to be added to the object parameter.

All methods return a promise.

Example:

import Poloniex from 'poloniex-api-node'
let poloniex = new Poloniex({ apiKey: 'myKey', apiSecret: 'mySecret' })

const tradesHistory = poloniex.getTradesHistory({ limit: 1000, symbols: 'BTC_USDT' })
  .then((result) => console.log(result))
  .catch((err) => console.log(err))

An optional property getApiCallRateInfo can be specified. When set to true the corresponding API call is not sent to the exchange, instead the current API call rate is returned. See rate limits.

Example:

const callRateInfo = poloniex.getTradesHistory({ limit: 1000, symbols: 'BTC_USDT', getApiCallRateInfo: true })

Example output:

[
 'riPriv', // id of the API endpoind set (can be 'riPub', 'nriPub', 'riPriv' or 'nriPriv')  
 2,        // current API call rate
 10        // API call rate limit
]

Public API Methods

Reference Data
Market Data
Margin

Authenticated API Methods

Accounts
Subaccounts
Wallets
Margin
Orders
Smart Orders
Order History
Trades

Websocket API

The module uses forever-websocket to connect to Poloniex websocket server.
ForeverWebSocket extends WebSocket, and in additions supports:

  • automatic reconnection
  • configurable reconnecting timers
  • configurable timeouts and reconnects when no message received
  • automatic pings to keep connection alive

Connection

  • newPublicWebSocket(options) - establishes a WebSocket connection for public channels
  • newAuthenticatedWebSocket(options) - establishes a WebSocket connection for authenticated channels

options parameter properties (check ForeverWebSocket for additional explanations):

Property nameTypeAttributesDefaultDescription
reconnectobject or nulloptional{ factor: 1.5, initialDelay: 50, maxDelay: 10000, randomizeDelay: false }Reconnecting parameters. Defaults to exponential backoff strategy
timeoutnumberoptionalno timeoutTimeout in milliseconds after which the websockets reconnects when no messages are received

newPublicWebSocket() and newAuthenticatedWebSocket() return a ForeverWebSocket instance.

Ping

Ping function is activated by default, ping requests are issued every 30 seconds to keep the connection alive.

{
"event": "ping"
}

Public channels

See https://docs.poloniex.com/#public-channels

Example:

import Poloniex from 'poloniex-api-node'
const poloniex = new Poloniex()

// Create a new WebSocket connected to public endpoint. The WebSocket should not reconnect if disconnected. 
const ws = poloniex.newPublicWebSocket({ reconnect: null })

// Specify event handlers
ws.on('open', () => console.log('Websocket connection open'))
ws.on('message', (data) => console.log('Websocket data received'))
ws.on('error', () => console.log('Websocket error'))
ws.on('close', () => console.log('Websocket connection closed'))

Authenticated channels

See https://docs.poloniex.com/#authenticated-channels

When newAuthenticatedWebSocket() is used to open a WebSocket connection to access private channels, the authentication auth message is automatically sent to Poloniex immediately after the WebSocket connection is open. Subscriptions for authentication channels can be sent after poloniex server responds with successful authentication confirmation:

{
  "data":  {
    "success": true,
    "ts": 1645597033915
  },
  "channel": "auth"
}

Example:

import Poloniex from 'poloniex-api-node'
const poloniex = new Poloniex({ apiKey: 'myKey', apiSecret: 'mySecret' })

// Create a new WebSocket connected to private endpoint. 
const ws = poloniex.newAuthenticatedWebSocket()

// Specify event handlers
ws.on('open', () => console.log('Websocket connection open'))
ws.on('message', (data) => {
  // if 'auth` message is received and authentication is sucessfull, send subscribe message 
  if (data.channel === 'auth' && data.data.success) {
    ws.send({
      event: 'subscribe',
      channel: ['orders'],
      symbols: ['all']
    })
  }  
})

Contributors

This project exists thanks to all the people who contribute.

License

MIT

Keywords

FAQs

Package last updated on 03 Sep 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc