cobinhood-rx
Version:
CobinhoodRx is a rxjs node wrapper for the CobinhoodRx Api.
57 lines • 3.05 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Model = require("../../Model");
const DataKeys_1 = require("../../Enum/DataKeys");
const Observable_1 = require("rxjs/Observable");
const HttpMethod_1 = require("../../Enum/HttpMethod");
const Validator_1 = require("../../Helpers/Validator");
class MarketAPI {
constructor(transportManager, config) {
this.transportManager = transportManager;
this.apiVersion = config.apiVersion;
this.baseUrl = config.baseUrl;
this.baseEndPoint = `${this.baseUrl}${this.apiVersion}/market`;
}
getCurrencies() {
return this.transportManager.publicRequest(HttpMethod_1.HttpMethod.GET, `${this.baseEndPoint}/currencies`)
.map(data => this.transportManager.processResponse(data, Model.Currency, DataKeys_1.DataKeyValues.Currencies))
.catch(this.catchErrorHandler);
}
getTradingPairs() {
return this.transportManager.publicRequest(HttpMethod_1.HttpMethod.GET, `${this.baseEndPoint}/trading_pairs`)
.map(data => this.transportManager.processResponse(data, Model.TradingPair, DataKeys_1.DataKeyValues.TradingPairs))
.catch(this.catchErrorHandler);
}
getOrderBook(market, limit = 10) {
return this.transportManager.publicRequest(HttpMethod_1.HttpMethod.GET, `${this.baseEndPoint}/orderbooks/${Validator_1.default.market(market)}`, Validator_1.default.queryObject({ limit }))
.map(data => this.transportManager.processResponse(data, Model.Orderbook, DataKeys_1.DataKeyValues.Orderbook))
.catch(this.catchErrorHandler);
}
getMarketStats() {
return this.transportManager.publicRequest(HttpMethod_1.HttpMethod.GET, `${this.baseEndPoint}/stats`)
.map(this.hashmapToArray)
.map(data => this.transportManager.processResponse(data, Model.MarketStats))
.catch(this.catchErrorHandler);
}
getTicker(market) {
return this.transportManager.publicRequest(HttpMethod_1.HttpMethod.GET, `${this.baseEndPoint}/tickers/${Validator_1.default.market(market)}`)
.map(data => this.transportManager.processResponse(data, Model.Ticker, DataKeys_1.DataKeyValues.Ticker))
.catch(this.catchErrorHandler);
}
getRecentTrades(market, limit = 10) {
return this.transportManager.publicRequest(HttpMethod_1.HttpMethod.GET, `${this.baseEndPoint}/trades/${Validator_1.default.market(market)}`, Validator_1.default.queryObject({ limit }))
.map(data => this.transportManager.processResponse(data, Model.RecentTrade, DataKeys_1.DataKeyValues.Trades))
.catch(this.catchErrorHandler);
}
catchErrorHandler(res) {
return Observable_1.Observable.throw(res);
}
hashmapToArray(res) {
if (res.success) {
res.result = Object.values(res.result);
}
return res;
}
}
exports.MarketAPI = MarketAPI;
//# sourceMappingURL=MarketAPI.js.map