poloniex-api-node is a simple node.js wrapper for Poloniex REST API.
Both Callback and Promise are supported.
npm install --save poloniex-api-node
When calling the methods, Callback is always the last parameter. When callback parameter is not present the method will return a Promise.
Example 1 (using Callback):
const Poloniex = require('poloniex-api-node');
let poloniex = new Poloniex();
poloniex.returnTicker((err, ticker) => {
if (err) {
console.log(err.message);
} else {
console.log(ticker);
}
});
Example 2 (using Callback):
const Poloniex = require('poloniex-api-node');
let poloniex = new Poloniex();
poloniex.returnTicker(function (err, ticker) {
if (err) {
console.log(err.message);
} else {
console.log(ticker);
}
});
Example 3 (using Promise):
const Poloniex = require('poloniex-api-node');
let poloniex = new Poloniex();
poloniex.returnTicker().then((ticker) => {
console.log(ticker);
}).catch((err) => {
console.log(err.message);
});
Example 4 (set socketTimeout to 15 seconds):
const Poloniex = require('poloniex-api-node');
let poloniex = new Poloniex('your_key', 'your_secret', { socketTimeout: 15000 });
poloniex.returnLoanOrders('BTC', null, function (err, ticker) {
if (!err) console.log(ticker);
});
See additional examples in examples folder
To access the private Poloniex API methods you must supply your API key id and key secret as the first two arguments. If you are only accessing the public API endpoints you can leave these two arguments out.
Default options:
{
socketTimeout: 60000,
keepAlive: true
}
Examples:
let poloniex;
poloniex = new Poloniex();
poloniex = new Poloniex({ socketTimeout: 10000 });
poloniex = new Poloniex('myKey', 'mySecret');
poloniex = new Poloniex('myKey', 'mySecret', { socketTimeout: 130000 });
socketTimeout
- the number of milliseconds to wait for the server to send the response before aborting the requestkeepAlive
- keep open and reuse the underlying TCP connection
For details about the API endpoints see full documentation at https://poloniex.com/support/api/
Note: For calling a method with optional parameters, the parameters, when not wanted, need to be passed as null
Both Callback and Promise are supported.
Callback is always the last parameter. When callback parameter is not present the method will return a Promise.
The arguments passed to the callback function for each method are:
- An error or
null
if no error occurred. - An object containing the data returned by the Poloniex API.
Examples:
poloniex.returnTicker((err, ticker) => {
if (err) {
console.log(err.message);
} else {
console.log(ticker);
}
});
poloniex.returnTicker().then((ticker) => {
console.log(ticker);
}).catch((err) => {
console.log(err.message);
});
Examples:
poloniex.returnLoanOrders('BTC', null, (err, loanOrders) => {
if (err) {
console.log(err.message);
} else {
console.log(loanOrders);
}
});
poloniex.returnLoanOrders('BTC', null).then((loanOrders) => {
console.log(loanOrders);
}).catch((err) => {
console.log(err.message);
});
poloniex.returnBalances(function (err, balances) {
if (err) {
console.log(err.message);
} else {
console.log(balances);
}
});
poloniex.returnBalances().then((balances) => {
console.log(balances);
}).catch((err) => {
console.log(err.message);
});
See detailed ChangeLog