@machinemode/cryptopia
Version:
Node wrapper for Cryptopia's CLient API
148 lines • 5.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var Currency_1 = require("./Currency");
var TradePair_1 = require("./TradePair");
var Market_1 = require("./Market");
var MarketHistory_1 = require("./MarketHistory");
var MarketOrders_1 = require("./MarketOrders");
var MarketOrderGroup_1 = require("./MarketOrderGroup");
var MarketService = (function () {
function MarketService(httpsClient) {
this.httpsClient = httpsClient;
}
MarketService.prototype.getCurrencies = function () {
return this.httpsClient.get('/api/GetCurrencies')
.then(function (response) {
if (response.success) {
var currencies_1 = [];
response.data.forEach(function (currency) {
currencies_1.push(new Currency_1.default(currency));
});
return currencies_1;
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
MarketService.prototype.getTradePairs = function () {
return this.httpsClient.get('/api/GetTradePairs')
.then(function (response) {
if (response.success) {
var tradePairs_1 = [];
response.data.forEach(function (tradePair) {
tradePairs_1.push(new TradePair_1.default(tradePair));
});
return tradePairs_1;
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
MarketService.prototype.getMarkets = function (baseMarket, hours) {
var path = '/api/GetMarkets';
if (baseMarket) {
path += "/" + baseMarket;
}
if (hours) {
path += "/" + hours;
}
return this.httpsClient.get(path)
.then(function (response) {
if (response.success) {
var markets_1 = [];
response.data.forEach(function (market) {
markets_1.push(new Market_1.default(market));
});
return markets_1;
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
MarketService.prototype.getMarket = function (market, hours) {
var path = "/api/GetMarket";
if (market instanceof Market_1.default) {
path += "/" + market.tradePairId;
}
else if (typeof market === 'string') {
path += "/" + market.replace('/', '_');
}
else {
path += "/" + market;
}
if (hours) {
path += "/" + hours;
}
return this.httpsClient.get(path)
.then(function (response) {
if (response.success) {
return new Market_1.default(response.data);
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
MarketService.prototype.getMarketHistory = function (market, hours) {
var path = "/api/GetMarketHistory/" + market.tradePairId;
if (hours) {
path += "/" + hours;
}
return this.httpsClient.get(path)
.then(function (response) {
if (response.success) {
var marketHistories_1 = [];
response.data.forEach(function (marketHistory) {
marketHistories_1.push(new MarketHistory_1.default(marketHistory));
});
return marketHistories_1;
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
MarketService.prototype.getMarketOrders = function (market, orderCount) {
var path = "/api/GetMarketOrders/" + market.tradePairId;
if (orderCount) {
path += "/" + orderCount;
}
return this.httpsClient.get(path)
.then(function (response) {
if (response.success) {
return new MarketOrders_1.default(response.data);
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
MarketService.prototype.getMarketOrderGroups = function (markets, orderCount) {
if (!(markets instanceof Array)) {
markets = [markets];
}
var path = "/api/GetMarketOrderGroups/" + markets.map(function (market) { return market.tradePairId; }).join('-');
if (orderCount) {
path += "/" + orderCount;
}
return this.httpsClient.get(path)
.then(function (response) {
if (response.success) {
var marketOrderGroups_1 = [];
response.data.forEach(function (marketOrderGroup) {
marketOrderGroups_1.push(new MarketOrderGroup_1.default(marketOrderGroup));
});
return marketOrderGroups_1;
}
else {
throw new Error(response.error + " " + response.message);
}
});
};
return MarketService;
}());
exports.default = MarketService;
//# sourceMappingURL=MarketService.js.map