diff --git a/src/controllers/rest-api/price/controller.js b/src/controllers/rest-api/price/controller.js index 21dfc95..92f58f5 100644 --- a/src/controllers/rest-api/price/controller.js +++ b/src/controllers/rest-api/price/controller.js @@ -64,6 +64,31 @@ class PriceRESTControllerLib { } } + // Get the XEC price. + // TODO: Add API docs. + async getXecPrice (ctx) { + try { + // Request options + const opt = { + method: 'get', + baseURL: 'https://api.coinex.com', + url: '/v1/market/ticker?market=xecusdt', + timeout: 15000 + } + // + + const response = await this.axios.request(opt) + console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`) + + ctx.body = { usd: Number(response.data.data.ticker.last) } + } catch (err) { + // Write out error to error log. + wlogger.error('Error in GET /price/xecusd.', err) + + this.handleError(ctx, err) + } + } + // DRY error handler handleError (ctx, err) { // If an HTTP status is specified by the buisiness logic, use that. diff --git a/src/controllers/rest-api/price/index.js b/src/controllers/rest-api/price/index.js index 2983153..f8188e5 100644 --- a/src/controllers/rest-api/price/index.js +++ b/src/controllers/rest-api/price/index.js @@ -52,6 +52,7 @@ class PriceRouter { // Define the routes and attach the controller. this.router.get('/usd', this.getPrice) + this.router.get('/xecusd', this.getXecPrice) // Attach the Controller routes to the Koa app. app.use(this.router.routes()) @@ -61,6 +62,10 @@ class PriceRouter { async getPrice (ctx, next) { await _this.priceRESTController.getUSD(ctx, next) } + + async getXecPrice (ctx, next) { + await _this.priceRESTController.getXecPrice(ctx, next) + } } module.exports = PriceRouter