Stacksavings - Poloniex Client
Hemos creado un paquete "@stacksavings/poloniex-client" para poder usar los metodos de Public y Trading API de Poloniex.
Table of contents
Getting Started
Installing
Para poder instalar el cliente solo basta con ejecutar el comando:
npm i @stacksavings/poloniex-client
Usage
Para empezar a usarlo solo debe de incluirlo en tu código asi:
const client = require('@stacksavings/poloniex-client')
Public API Methods
- currenciesAvailable:
Returns information about currencies.
Example to call it:const logger = require('@stacksavings/utils').log()
const client = require(@stacksavings/poloniex-client)
const currencies = client.currenciesAvailable()
currencies.then(data => {
logger.info(data);
}, err => {
logger.error(err);
})
Output:
{
"1CR":{
"maxDailyWithdrawal":10000,
"txFee":0.01,
"minConf":3,
"disabled":0
},
"ABY":{
"maxDailyWithdrawal":10000000,
"txFee":0.01,
"minConf":8,
"disabled":0
},
...
}
- returnChartData:
Returns candlestick chart data. Required GET parameters are "currencyPair", "period" (candlestick period in seconds; valid values are 300, 900, 1800, 7200, 14400, and 86400), "start", and "end". "Start" and "end" are given in UNIX timestamp format and used to specify the date range for the data returned.
Example to call it:const logger = require('@stacksavings/utils').log()
const client = require('./poloniex-client')
const TimeStamp = require('@stacksavings/utils')
let parameters = {
currencyPair: "BTC_LTC",
period: 14400,
start: TimeStamp.toTimeStampUnix(20171218),
end: TimeStamp.toTimeStampUnix(20171219)
}
const ChartData = client.returnChartData(parameters)
ChartData.then(data => {
logger.info(data);
}, err => {
logger.error(err);
})
Output:
[
{
"date":1405699200,
"high":0.0045388,
"low":0.00403001,
"open":0.00404545,
"close":0.00427592,
"volume":44.11655644,
"quoteVolume":10259.29079097,
"weightedAverage":0.00430015
},
...
]
Trading API Methods
Estos métodos requieren el "Key" y "Secret" asociado a la organización Stacksavings.
- buy:
Places a limit buy order in a given market. Required POST parameters are "currencyPair", "rate", and "amount". If successful, the method will return the order number.
Example to call it:
const logger = require('@stacksavings/utils').log()
const client = require(@stacksavings/poloniex-client)
let parameters = {
currencyPair: 'BTC_ETH',
amount: 0.008,
rate: 0.058,
}
let credentials = {
key: 'KEY STRING',
secret: 'SECRET STRING'
}
const buyer = client.buy(parameters,credentials)
buyer.then(data => {
logger.info(data);
}, err => {
logger.error(err);
})
Output:
{
"orderNumber":31226040,
"resultingTrades":[
{
"amount":"338.8732",
"date":"2014-10-18 23:03:21",
"rate":"0.00000173",
"total":"0.00058625",
"tradeID":"16164",
"type":"buy"
}
]
}
- sell:
Places a sell order in a given market. Parameters and output are the same as for the buy method.
Example to call it:
const logger = require('@stacksavings/utils').log()
const client = require(@stacksavings/poloniex-client)
let parameters = {
currencyPair: 'BTC_ETH',
amount: 0.008,
rate: 0.058,
}
let credentials = {
key: 'KEY STRING',
secret: 'SECRET STRING'
}
const seller = client.sell(parameters,credentials)
seller.then(data => {
logger.info(data);
}, err => {
logger.error(err);
})
Output:
{
"orderNumber":31226040,
"resultingTrades":[
{
"amount":"338.8732",
"date":"2014-10-18 23:03:21",
"rate":"0.00000173",
"total":"0.00058625",
"tradeID":"16164",
"type":"sell"
}
]
}
- returnBalances:
Returns all of your available balances.
Example to call it:
const logger = require('@stacksavings/utils').log()
const client = require(@stacksavings/poloniex-client)
let credentials = {
key: 'KEY STRING',
secret: 'SECRET STRING'
}
const balances = client.returnBalances(credentials)
balances.then(data => {
logger.info(data);
}, err => {
logger.error(err);
})
Output:
{
"BTC":"0.59098578",
"LTC":"3.31117268",
...
}
- returnCompleteBalances:
Returns all of your balances, including available balance, balance on orders, and the estimated BTC value of your balance. By default, this call is limited to your exchange account; set the "account" POST parameter to "all" to include your margin and lending accounts.
Example to call it:
const logger = require('@stacksavings/utils').log()
const client = require(@stacksavings/poloniex-client)
let credentials = {
key: 'KEY STRING',
secret: 'SECRET STRING'
}
const balances = client.returnCompleteBalances(credentials)
balances.then(data => {
logger.info(data);
}, err => {
logger.error(err);
})
Output:
{
"LTC":
{
"available":"5.015",
"onOrders":"1.0025",
"btcValue":"0.078"
},
"NXT:{...}
...
}
Creators
Stacksavings
David Molina