Poloniex

Poloniex

Cryptocurrency

Buy, sell & Trade for BTC, ETH, USDT, TRX, and the best altcoins on the market.

Visit API

📚 Documentation & Examples

Everything you need to integrate with Poloniex

🚀 Quick Start Examples

Poloniex Javascript Examplejavascript
// Poloniex API Example
const response = await fetch('https://docs.poloniex.com/', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

An Overview of the Poloniex Public API

The Poloniex API allows you to access a wide variety of data related to trading on the Poloniex exchange, including ticker data, order book information, trade history, and more. In this article, we'll take a look at some sample JavaScript code that demonstrates how to use the Poloniex API to retrieve data and perform various functions.

Getting Started

Before we dive into the sample code, let's first take a look at how to set up the API and obtain an API key and secret. To get started, simply follow these steps:

  1. Sign up for an account on Poloniex.
  2. Log in to your account and navigate to the API Keys page.
  3. Generate a new API key and secret.
  4. Be sure to keep your secret key safe and secure.

Once you have your API key and secret, you can begin using the API to retrieve data from the exchange.

Sample Code

To get started, we'll first need to use a JavaScript library to send HTTP requests to the Poloniex API. In this example, we'll be using the request library, which can be installed using npm. To install the request library, simply run the following command:

npm install request

Once you've installed the request library, you can begin using it to send requests to the Poloniex API.

Example 1: Retrieving Ticker Data

To retrieve ticker data for a particular cryptocurrency on the Poloniex exchange, you can use the following code:

const request = require('request');

const currencyPair = 'BTC_ETH';

const options = {
  url: `https://poloniex.com/public?command=returnTicker&currencyPair=${currencyPair}`,
  json: true,
};

request(options, (error, response, body) => {
  if (!error && response.statusCode === 200) {
    console.log(body);
  }
});

In this example, we're retrieving ticker data for the BTC_ETH currency pair. We're using the returnTicker API command to retrieve this data, and we're using the json option to automatically parse the response as JSON.

Example 2: Retrieving Order Book Data

To retrieve order book data for a particular currency pair, you can use the following code:

const request = require('request');

const currencyPair = 'BTC_ETH';
const depth = 10;

const options = {
  url: `https://poloniex.com/public?command=returnOrderBook&currencyPair=${currencyPair}&depth=${depth}`,
  json: true,
};

request(options, (error, response, body) => {
  if (!error && response.statusCode === 200) {
    console.log(body);
  }
});

In this example, we're retrieving order book data for the BTC_ETH currency pair. We're using the returnOrderBook API command to retrieve this data, and we're specifying a depth of 10 levels.

Example 3: Retrieving Trade History

To retrieve trade history for a particular currency pair, you can use the following code:

const request = require('request');

const currencyPair = 'BTC_ETH';
const start = 1609459200;
const end = 1612137600;

const options = {
  url: `https://poloniex.com/public?command=returnTradeHistory&currencyPair=${currencyPair}&start=${start}&end=${end}`,
  json: true,
};

request(options, (error, response, body) => {
  if (!error && response.statusCode === 200) {
    console.log(body);
  }
});

In this example, we're retrieving trade history data for the BTC_ETH currency pair. We're using the returnTradeHistory API command to retrieve this data, and we're specifying a start and end timestamp for the trade data.

Conclusion

In this article, we've looked at some sample JavaScript code that demonstrates how to use the Poloniex API to retrieve data and perform various functions. Whether you're interested in retrieving ticker data, order book information, or trade history, the Poloniex API provides a wide variety of functionality for traders and developers alike.

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jun 5Jun 7Jun 9Jun 11Jun 13Jun 15Jun 17Jun 19Jun 21Jun 23Jun 25Jun 27Jun 29Jul 1Jul 404008001440Minutes
Online
Offline

Related APIs in Cryptocurrency