node-dsx-api
Version:
Node api for DSX.uk crypto exchange
80 lines (79 loc) • 2.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const exchange_1 = require("./exchange");
const _ = require("lodash");
const debug = require("debug")("DSX.Api:");
function converToPriceAndQty(pq) {
return {
price: pq[0],
qty: pq[1]
};
}
exports.converToPriceAndQty = converToPriceAndQty;
function checkPair(pair) {
if (!pair) {
debug("Empty symbol!");
throw "Empty symbol!";
}
return _.toLower(pair);
}
class ExchangeMarket extends exchange_1.Exchange {
info() {
let params = this.sign("info");
debug("info params", params);
return this.request(params);
}
async orderBook(pair) {
pair = checkPair(pair);
const res = await this.request(this.sign("depth/{pair}", "mapi", "GET", { pair }));
if (!res[pair]) {
throw "Error response: did not receive messages.";
}
return res[pair];
}
async trades(pair, limit) {
pair = checkPair(pair);
const res = await this.request(this.sign("trades/{pair}", "mapi", "GET", { pair, limit }));
if (!res[pair]) {
throw "Error response: did not receive messages.";
}
return res[pair];
}
async ticker(pair) {
pair = checkPair(pair);
const res = await this.request(this.sign("ticker/{pair}", "mapi", "GET", { pair }));
if (!res[pair]) {
throw "Error response: did not receive messages.";
}
return res[pair];
}
async lastBars(pair, period, amount) {
pair = checkPair(pair);
const res = await this.request(this.sign("lastBars/{pair}/{period}/{amount}", "mapi", "GET", {
pair,
period,
amount
}));
if (!res[pair]) {
throw "Error response: did not receive messages.";
}
return res[pair];
}
async barsFromMoment(pair, period, first_bar_close_time) {
pair = checkPair(pair);
const res = await this.request(this.sign("barsFromMoment/{pair}/{period}/{first_bar_close_time}", "mapi", "GET", { pair, period, first_bar_close_time }));
if (!res[pair]) {
throw "Error response: did not receive messages.";
}
return res[pair];
}
async periodBars(pair, period, first_bar_close_time, last_bar_close_time) {
pair = checkPair(pair);
const res = await this.request(this.sign("periodBars/{pair}/{period}/{first_bar_close_time}/{last_bar_close_time}", "mapi", "GET", { pair, period, first_bar_close_time, last_bar_close_time }));
if (!res[pair]) {
throw "Error response: did not receive messages.";
}
return res[pair];
}
}
exports.ExchangeMarket = ExchangeMarket;