Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

poloniex-node-api

vansergen81MIT8.0.3TypeScript support: included

Poloniex Node.js API

Poloniex, crypto, exchange, API

readme

Poloniex Node.js API CI Status npm version Coverage Status Known Vulnerabilities code style: prettier Contributor Covenant semantic-release Conventional Commits NPM license node version npm downloads GitHub top language

Node.js library for Poloniex.

Installation

npm install poloniex-node-api

Usage

PublicClient

import { PublicClient } from "poloniex-node-api";
const client = new PublicClient();
const markets = await client.getMarkets();
const symbol = "ETH_BTC";
const volume = await client.getMarket({ symbol });
const currency = "BNB";
const currency_info = await client.getCurrency({ currency });

or

const includeMultiChainCurrencies = true;
const all = await client.getCurrency({ includeMultiChainCurrencies });
const time = await client.getSystemTime();
const prices = await client.getPrices();
const symbol = "ETH_BTC";
const price = await client.getPrice({ symbol });
const prices = await client.getMarkPrices();
const symbol = "ZEC_USDT";
const price = await client.getMarkPrice({ symbol });
const symbol = "ZEC_USDT";
const prices = await client.getMarkPriceComponents({ symbol });
const symbol = "ETH_BTC";
const limit = 5;
const scale = "0.01";
const book = await client.getOrderBook({ symbol, limit, scale });
const symbol = "ETH_BTC";
const interval = "HOUR_1";
const limit = 2;
const endTime = Date.now();
const startTime = endTime - 1000 * 60 * 60 * 24;
const candles = await client.getOrderBook({
  symbol,
  interval,
  limit,
  startTime,
  endTime,
});
const symbol = "ETH_BTC";
const limit = 2;
const trades = await client.getPublicTrades({ symbol, limit });
const tickers = await client.getTickers();
const symbol = "ETH_BTC";
const ticker = await client.getTicker({ symbol });
const currency = "ETH";
const collateral = await client.getCollateral({ currency });

or

const all = await client.getCollateral();
const symbol = "ETH_BTC";
const ticker = await client.getTicker({ symbol });

AuthenticatedClient

import { AuthenticatedClient } from "poloniex-node-api";
const key = "poloniex-api-key";
const secret = "poloniex-api-secret";
const client = new AuthenticatedClient({ key, secret });

Accounts

const accounts = await client.getAccounts();
const balances = await client.getAccountBalances();
const activity = await client.getAccountActivity();
const currency = "USDT";
const amount = "10.5";
const fromAccount = "SPOT";
const toAccount = "FUTURES";
const { transferId } = await client.transfer({
  currency,
  amout,
  fromAccount,
  toAccount,
});
const transfers = await client.getAccountTransfers();
const fee_info = await client.getFeeInfo();

Wallets

const wallets = await client.getWallets();
const { deposits, withdrawals } = await client.getWalletsActivity();
const { address } = await client.newAddress();
const { withdrawalRequestsId } = await client.withdraw();

Margin

const info = await client.getMargin();
const status = await client.getBorrowStatus();
const size = await client.getMaxSize();

Orders

const symbol = "BTC_USDT";
const type = "LIMIT";
const quantity = "100";
const side = "BUY";
const price = "40000.50000";
const timeInForce = "IOC";
const clientOrderId = "1234Abc";
const { id, clientOrderId } = await client.createOrder({
  symbol,
  type,
  quantity,
  side,
  price,
  timeInForce,
  clientOrderId,
});

or

const symbol = "BTC_USDT";
const quantity = "100";
const side = "BUY";
const { id } = await client.createOrder({ symbol, quantity, side });
const orders = [
  { symbol: "BTC_USDT", amount: "100", side: "BUY" },
  {
    symbol: "BTC_USDT",
    type: "LIMIT",
    quantity: "100",
    side: "BUY",
    price: "40000.50000",
    timeInForce: "IOC",
    clientOrderId: "1234Abc",
  },
  { symbol: "ETH_USDT", amount: "1000", side: "BUY" },
  {
    symbol: "TRX_USDT",
    type: "LIMIT",
    quantity: "15000",
    side: "SELL",
    price: "0.0623423423",
    timeInForce: "IOC",
    clientOrderId: "456Xyz",
  },
];
const response = await client.createOrders(orders);
const id = "234235233423";
const price = "18000";
const clientOrderId = "1234";
const response = await client.replaceOrder({ id }, { price, clientOrderId });

or

const clientOrderId = "1234Abc";
const price = "18000";
const quantity = "20";
const response = await client.replaceOrder(
  { clientOrderId },
  { price, quantity },
);
const symbol = "ELON_USDC";
const side = "SELL";
const direction = "PRE";
const limit = 10;
const orders = await client.getOpenOrders({ symbol, side, direction, limit });

or

const orders = await client.getOpenOrders();
const id = "21934611974062080";
const order = await client.getOrder({ id });

or by clientOrderId

const clientOrderId = "123";
const order = await client.getOrder({ clientOrderId });
const id = "21934611974062080";
const order = await client.cancelOrder({ id });

or by clientOrderId

const clientOrderId = "123";
const order = await client.cancelOrder({ clientOrderId });
const orders = [{ id: "12345" }, { clientOrderId: "myId-1" }];
const results = await client.cancelOrders(orders);
const symbols = ["BTC_USDT", "ETH_USDT"];
const accountTypes = ["SPOT"];
const results = await client.cancelAllOrders({ symbols, accountTypes });

or (to cancel all orders)

const results = await client.cancelAllOrders();
const timeout = 60;
const status = await client.killSwitch({ timeout });
const status = await client.getKillSwitch();

Smart Orders

const symbol = "BTC_USDT";
const side = "BUY";
const type = "STOP_LIMIT";
const quantity = "100";
const price = "60100.00";
const timeInForce = "FOK";
const stopPrice = "60000.00";
const clientOrderId = "999999910";
const { id, clientOrderId } = await client.createSmartOrder({
  symbol,
  side,
  type,
  quantity,
  price,
  timeInForce,
  stopPrice,
  clientOrderId,
});
const id = "234235233423";
const stopPrice = "18000";
const clientOrderId = "1234Abc";
const response = await client.replaceOrder(
  { id },
  { stopPrice, clientOrderId },
);

or by clientOrderId

const clientOrderId = "1234Abc";
const price = "18000";
const quantity = "20";
const response = await client.replaceOrder(
  { clientOrderId },
  { stopPrice, quantity },
);
const limit = 10;
const orders = await client.getOpenSmartOrders({ limit });

or

const orders = await client.getOpenSmartOrders();
const id = "14368195657859072";
const order = await client.getSmartOrder({ id });

or by clientOrderId

const clientOrderId = "18113";
const order = await client.getSmartOrder({ clientOrderId });
const id = "9876543";
const order = await client.cancelSmartOrder({ id });

or by clientOrderId

const clientOrderId = "88888";
const order = await client.cancelSmartOrder({ clientOrderId });
const orders = [{ id: "12345" }, { clientOrderId: "myId-1" }];
const results = await client.cancelSmartOrders(orders);
const symbols = ["BTC_USDT", "ETH_USDT"];
const accountTypes = ["SPOT"];
const results = await client.cancelAllSmartOrders({ symbols, accountTypes });

or (to cancel all orders)

const results = await client.cancelAllSmartOrders();

Order history

const type = ["MARKET", "LIMIT"];
const side = "BUY";
const symbol = "TRX_USDC";
const states = ["FILLED", "PARTIALLY_CANCELED"];
const limit = 10;
const hideCancel = true;
const startTime = 1649106321040;
const endTime = 1649427963598;
const orders = await client.getOrders({
  type,
  side,
  symbol,
  states,
  limit,
  hideCancel,
  startTime,
  endTime,
});

Trades

const limit = 10;
const endTime = 1648635115535;
const startTime = endTime - 1000 * 60 * 60;
const direction = "PRE";
const symbols = ["BTC_USDT", "ETH_USDT"];
const trades = await client.getTrades({
  limit,
  startTime,
  endTime,
  direction,
  symbols,
});
const id = "30249408733945856";
const trades = await client.getOrderTrades({ id });

WebSocketClient

const key = "<POLONIEX API KEY>";
const secret = "<POLONIEX API SECRET>";
const client = new WebSocketClient({ key, secret })
  .on("message", (msg) => {
    console.log("Message:\t", msg);
  })
  .on("error", (error) => {
    console.log("Error:\t", error);
  });
await client.connectPublicWS();
await client.connectPrivateWS();
await client.disconnectPublicWS();
await client.disconnectPrivateWS();
await client.auth();
const ac = new AbortController();
setTimeout(() => {
  ac.abort();
}, 10000).unref();
await client.pingPublic({ signal: ac.signal });
await client.pingPrivate();
await client.unsubscribePublic();
await client.unsubscribePrivate();
const { subscriptions } = await client.getPublicSubscriptions();
const { subscriptions } = await client.getPrivateSubscriptions();
const payload = {
  event: "subscribe",
  channel: ["candles_minute_1", "ticker"],
  symbols: ["BTC_USDT", "ETH_USDT"],
};
await client.send(payload, "public");

or

const payload = {
  event: "subscribe",
  channel: ["orders", "balances"],
  symbols: ["all"],
};
await client.send(payload, "private");

Candlesticks

  • subscribeCandles
await client.subscribeCandles();
  • unsubscribeCandles
await client.unsubscribeCandles();
  • candles
const channel = "candles_day_1";
for await (const candle of client.candles()) {
  console.log(candle);
}

Trades

  • subscribeTrades
const symbols = ["BTC_USDT", "ETH_USDT"];
await client.subscribeTrades({ symbols });
  • unsubscribeTrades
const symbols = ["BTC_USDT"];
await client.unsubscribeTrades({ symbols });
  • trades
for await (const trade of client.trades()) {
  console.log(trade);
}

Ticker

  • subscribeTicker
const symbols = "all";
await client.subscribeTicker({ symbols });
  • unsubscribeTicker
const symbols = "all";
await client.unsubscribeTicker({ symbols });
  • tickers
for await (const ticker of client.tickers()) {
  console.log(ticker);
}

Book

  • subscribeBook
await client.subscribeBook();
  • unsubscribeBook
const symbols = "all";
await client.unsubscribeBook({ symbols });
  • books
const depth = 10;
for await (const book of client.books({ depth })) {
  console.log(book);
}

Book Level 2

  • subscribeLv2Book
const symbols = ["BTC_USDT"];
await client.subscribeLv2Book({ symbols });
  • unsubscribeLv2Book
const symbols = "all";
await client.unsubscribeLv2Book({ symbols });
  • booksLv2
for await (const book of client.booksLv2()) {
  console.log(book);
}

Orders

  • subscribeOrders
const symbols = "all";
await client.subscribeOrders({ symbols });
  • unsubscribeOrders
const symbols = "all";
await client.unsubscribeOrders({ symbols });
  • orders
for await (const order of client.orders()) {
  console.log(order);
}

Balances

  • subscribeBalances
await client.subscribeBalances();
  • unsubscribeBalances
await client.unsubscribeBalances();
  • balances
for await (const balance of client.balances()) {
  console.log(balance);
}

Test

npm test

Coverage

npm run coverage

changelog

Changelog

8.0.3 (2025-07-29)

Dependencies

  • bump rpc-request from 8.0.0 to 9.0.0 (cd240eb)

8.0.2 (2025-05-04)

Dependencies

  • bump ws from 8.18.0 to 8.18.1 (080fd1a)

8.0.1 (2024-12-08)

Dependencies

  • bump ws from 8.16.0 to 8.18.0 (ca99d0e)

8.0.0 (2024-12-08)

⚠ BREAKING CHANGES

  • drop Node.js<22 support

Performance Improvements

  • drop Node.js<22 support (7d72e0b)

Dependencies

  • bump rpc-request to v8.0.0 (cac8d52)

7.0.3 (2023-12-30)

Dependencies

  • bump rpc-request from 7.1.8 to 7.1.9 (f3bfea1)

7.0.2 (2023-12-29)

Dependencies

  • bump ws from 8.14.2 to 8.16.0 (a87028d)

7.0.1 (2023-11-27)

Dependencies

  • bump rpc-request from 7.1.7 to 7.1.8 (a2b2778)

7.0.0 (2023-10-22)

⚠ BREAKING CHANGES

  • drop Node <18.18.2 support
  • remove legacy API

Performance Improvements

  • drop Node <18.18.2 support (c6b9a4e)

Code Refactoring

6.0.10 (2023-09-27)

Dependencies

  • bump rpc-request from 7.1.6 to 7.1.7 (185ef64)

6.0.9 (2023-09-25)

Dependencies

  • bump rpc-request from 7.1.5 to 7.1.6 (5a09bac)

6.0.8 (2023-09-21)

Dependencies

  • bump ws from 8.14.1 to 8.14.2 (a224429)

6.0.7 (2023-09-17)

Dependencies

  • bump rpc-request from 7.1.4 to 7.1.5 (8f39b92)

6.0.6 (2023-09-08)

Dependencies

  • bump ws from 8.13.0 to 8.14.1 (c44ff53)

6.0.5 (2023-09-07)

Dependencies

  • bump rpc-request from 7.1.3 to 7.1.4 (dc82897)

6.0.4 (2023-05-24)

Dependencies

  • bump rpc-request from 7.1.2 to 7.1.3 (acc02c8)

6.0.3 (2023-05-13)

Bug Fixes

  • update the ITicker interface (c32f942)

Dependencies

  • bump rpc-request from 7.1.0 to 7.1.1 (eed93f3)
  • bump ws from 8.12.1 to 8.13.0 (afa791d)

6.0.2 (2023-03-09)

Dependencies

  • bump ws from 8.12.0 to 8.12.1 (749275c)

6.0.1 (2023-02-01)

Bug Fixes

  • types: update the types path (9c50469)
  • types: update WebSocket events (7a282f1)

6.0.0 (2023-01-31)

⚠ BREAKING CHANGES

  • drop Node <16.19.0 support
  • move legacy API to the legacy path

Features

Performance Improvements

  • drop Node <16.19.0 support (5e692c9)

Code Refactoring

  • move legacy API to the legacy path (c79a34f)

5.0.5 (2023-01-23)

Dependencies

  • bump rpc-request from 7.1.0 to 7.1.1 (d865b55)

5.0.4 (2023-01-12)

Dependencies

  • bump rpc-request from 6.0.2 to 7.1.0 (9107349)

5.0.3 (2023-01-11)

Bug Fixes

Dependencies

  • update ws from 8.8.0 to 8.12.0 (b5cf923)

5.0.2 (2022-06-26)

Bug Fixes

Dependencies

  • upgrade rpc-request to v6.0.2 (8126dfb)
  • upgrade ws to v8.8.0 (a8a2c37)

5.0.1 (2022-05-13)

Bug Fixes

Dependencies

5.0.0 (2021-10-30)

⚠ BREAKING CHANGES

  • drop Node.js <16.13.0 support
  • change package type from commonjs to module
  • rename the class WebsocketClient to WebSocketClient

Bug Fixes

  • add the epoch_ms field to WebSocket message (92da589)
  • update Currencies (eb3d647)
  • update CurrencyPairs (56d0cc0)

Performance Improvements

  • change package type from commonjs to module (99d3850)
  • drop Node.js <16.13.0 support (883abfe)

Dependencies

  • upgrade @types/ws to v8.2.0 (e99f935)
  • upgrade rpc-request to v6.0.0 (371d56a)
  • upgrade ws to v8.2.3 (c788e6d)

Code Refactoring

  • rename the class WebsocketClient to WebSocketClient (ba9780b)

4.0.1 (2021-06-03)

Metadata

4.0.0 (2021-06-03)

⚠ BREAKING CHANGES

  • drop Node <16.3.0 support

Bug Fixes

Performance Improvements

  • drop Node <16.3.0 support (c0800c1)

Dependencies

  • upgrade @types/ws to v7.4.4 (05e15ce)
  • upgrade ws to v7.4.6 (3b73402)

3.1.1 (2021-03-07)

Bug Fixes

Dependencies

  • upgrade rpc-request to v5.0.3 (0612abb)
  • upgrade ws to v7.4.4 (5f3f16f)

3.1.0 (2021-02-14)

Features

  • add the swapCurrencies method (a104dd8)

Dependencies

  • upgrade rpc-request to v5.0.2 (d24a753)

3.0.3 (2021-02-08)

Bug Fixes

3.0.2 (2021-02-07)

Dependencies

3.0.1 (2020-12-20)

Dependencies

  • update rpc-request to v5.0.1 (1ca8121)

3.0.0 (2020-12-20)

⚠ BREAKING CHANGES

  • drop Node <12.20.0 support
  • the main methods of the WebsocketClient class return promises
  • update AuthenticatedClient
  • class PublicClient extends FetchClient
  • pass body as string

Features

  • add extended currencies (64461d6)
  • add margin position update support to WebsocketClient (9d7766f)
  • add the clientOrderId property to Order (7a402e5)

Bug Fixes

  • do not format unnkown messages as a killed message (6956c84)
  • rename the interface Currencies to ICurrencies (82875e4)
  • update AuthenticatedClient (51a9df3)
  • update currencies (6039e76)
  • update currency pairs (e09ee85)
  • update interfaces (485d451)
  • upgrade @types/ws from 7.2.6 to 7.2.7 (e4b6ba1)
  • upgrade @types/ws from 7.2.7 to 7.2.8 (365c8e3)

Performance Improvements

  • class PublicClient extends FetchClient (b4bd1ef)
  • drop Node <14.15.3 support (e4245a4)
  • pass body as string (7c70743)
  • the main methods of the WebsocketClient class return promises (403ddef)

Dependencies

  • update @types/ws to v7.4.0 (35e20b1)
  • update rpc-request to v5.0.0 (9dcd30c)
  • update ws to v7.4.1 (dc7cd92)

Miscellaneous Chores

  • drop Node <12.20.0 support (b6786c7)