From 059e4d079ab1f57f9bc011ee69de421fefaefdc8 Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 17 Sep 2020 15:38:25 +0700 Subject: [PATCH] Markets api: Add missing "timestamp" parameter for /hloc and /volumes --- backend/src/api/bisq/interfaces.ts | 2 +- backend/src/api/bisq/markets-api.ts | 6 ++++-- backend/src/routes.ts | 12 ++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/src/api/bisq/interfaces.ts b/backend/src/api/bisq/interfaces.ts index f7cfaba43..85c59aee5 100644 --- a/backend/src/api/bisq/interfaces.ts +++ b/backend/src/api/bisq/interfaces.ts @@ -110,7 +110,7 @@ interface Market { } export interface HighLowOpenClose { - period_start: number; + period_start: number | string; open: string; high: string; low: string; diff --git a/backend/src/api/bisq/markets-api.ts b/backend/src/api/bisq/markets-api.ts index 18262307d..38733047f 100644 --- a/backend/src/api/bisq/markets-api.ts +++ b/backend/src/api/bisq/markets-api.ts @@ -212,6 +212,7 @@ class BisqMarketsApi { timestamp_to?: number, interval: Interval = 'auto', milliseconds?: boolean, + timestamp: 'no' | 'yes' = 'yes', ): MarketVolume[] { if (milliseconds) { timestamp_from = timestamp_from ? timestamp_from / 1000 : timestamp_from; @@ -256,7 +257,7 @@ class BisqMarketsApi { if (intervals.hasOwnProperty(p)) { const period = intervals[p]; marketVolumes.push({ - period_start: period['period_start'], + period_start: timestamp === 'no' ? new Date(period['period_start'] * 1000).toISOString() : period['period_start'], num_trades: period['num_trades'], volume: this.intToBtc(period['volume']), }); @@ -358,6 +359,7 @@ class BisqMarketsApi { timestamp_from?: number, timestamp_to?: number, milliseconds?: boolean, + timestamp: 'no' | 'yes' = 'yes', ): HighLowOpenClose[] { if (milliseconds) { timestamp_from = timestamp_from ? timestamp_from / 1000 : timestamp_from; @@ -386,7 +388,7 @@ class BisqMarketsApi { if (intervals.hasOwnProperty(p)) { const period = intervals[p]; hloc.push({ - period_start: period['period_start'], + period_start: timestamp === 'no' ? new Date(period['period_start'] * 1000).toISOString() : period['period_start'], open: this.intToBtc(period['open']), close: this.intToBtc(period['close']), high: this.intToBtc(period['high']), diff --git a/backend/src/routes.ts b/backend/src/routes.ts index f4939f52c..ecf827dee 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -317,6 +317,10 @@ class Routes { required: false, types: ['@boolean'] }, + 'timestamp': { + required: false, + types: ['no', 'yes'] + }, }; const p = this.parseRequestParameters(req, constraints); @@ -325,7 +329,7 @@ class Routes { return; } - const result = bisqMarket.getVolumes(p.market, p.timestamp_from, p.timestamp_to, p.interval, p.milliseconds); + const result = bisqMarket.getVolumes(p.market, p.timestamp_from, p.timestamp_to, p.interval, p.milliseconds, p.timestamp); if (result) { res.json(result); } else { @@ -355,6 +359,10 @@ class Routes { required: false, types: ['@boolean'] }, + 'timestamp': { + required: false, + types: ['no', 'yes'] + }, }; const p = this.parseRequestParameters(req, constraints); @@ -363,7 +371,7 @@ class Routes { return; } - const result = bisqMarket.getHloc(p.market, p.interval, p.timestamp_from, p.timestamp_to, p.milliseconds); + const result = bisqMarket.getHloc(p.market, p.interval, p.timestamp_from, p.timestamp_to, p.milliseconds, p.timestamp); if (result) { res.json(result); } else {