From 38e866995f4e5a01abaa8b4233e1da6ed3355e22 Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 28 Feb 2021 17:18:29 +0700 Subject: [PATCH] Bisq markets dashboard: 24H Volume. WIP. --- backend/src/api/bisq/markets-api.ts | 24 +++++++++++++++++++ backend/src/index.ts | 1 + backend/src/routes.ts | 9 +++++++ frontend/src/app/bisq/bisq-api.service.ts | 4 ++++ .../bisq-dashboard.component.html | 24 ++++++++++++------- .../bisq-dashboard.component.ts | 9 +++++-- .../bisq-market/bisq-market.component.html | 5 ++-- 7 files changed, 63 insertions(+), 13 deletions(-) diff --git a/backend/src/api/bisq/markets-api.ts b/backend/src/api/bisq/markets-api.ts index acc8093c7..c29a4dc70 100644 --- a/backend/src/api/bisq/markets-api.ts +++ b/backend/src/api/bisq/markets-api.ts @@ -457,6 +457,30 @@ class BisqMarketsApi { } } + get24hVolumes(): MarketVolume[] { + const timestamp_from = new Date().getTime() / 1000 - 86400; + const timestamp_to = new Date().getTime() / 1000; + + const trades = this.getTradesByCriteria(undefined, timestamp_to, timestamp_from, + undefined, undefined, undefined, 'asc', Number.MAX_SAFE_INTEGER); + + const markets: any = {}; + + for (const trade of trades) { + if (!markets[trade._market]) { + markets[trade._market] = { + 'volume': 0, + 'num_trades': 0, + }; + } + + markets[trade._market]['volume'] += this.fiatCurrenciesIndexed[trade.currency] ? trade._tradeAmount : trade._tradeVolume; + markets[trade._market]['num_trades']++; + } + + return markets; + } + private getTradesSummarized(trades: TradesData[], timestamp_from: number, interval?: string): SummarizedIntervals { const intervals: any = {}; const intervals_prices: any = {}; diff --git a/backend/src/index.ts b/backend/src/index.ts index 2389d38b5..6f52fe20b 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -203,6 +203,7 @@ class Server { .get(config.MEMPOOL.API_URL_PREFIX + 'bisq/markets/ticker', routes.getBisqMarketTicker.bind(routes)) .get(config.MEMPOOL.API_URL_PREFIX + 'bisq/markets/trades', routes.getBisqMarketTrades.bind(routes)) .get(config.MEMPOOL.API_URL_PREFIX + 'bisq/markets/volumes', routes.getBisqMarketVolumes.bind(routes)) + .get(config.MEMPOOL.API_URL_PREFIX + 'bisq/markets/24hvolumes', routes.getBisqMarket24hVolumes.bind(routes)) ; } diff --git a/backend/src/routes.ts b/backend/src/routes.ts index c03c08b75..fc9acfc28 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -401,6 +401,15 @@ class Routes { } } + public getBisqMarket24hVolumes(req: Request, res: Response) { + const result = bisqMarket.get24hVolumes(); + if (result) { + res.json(result); + } else { + res.status(500).json(this.getBisqMarketErrorResponse('getBisqMarket24hVolumes error')); + } + } + private parseRequestParameters(requestParams: object, params: RequiredSpec): { [name: string]: any; } { const final = {}; for (const i in params) { diff --git a/frontend/src/app/bisq/bisq-api.service.ts b/frontend/src/app/bisq/bisq-api.service.ts index 9967269cf..90324e516 100644 --- a/frontend/src/app/bisq/bisq-api.service.ts +++ b/frontend/src/app/bisq/bisq-api.service.ts @@ -59,4 +59,8 @@ export class BisqApiService { | 'week' | 'month' | 'year' | 'auto'): Observable { return this.httpClient.get(API_BASE_URL + '/markets/hloc?market=' + market + '&interval=' + interval); } + + getMarket24hVolumes$(): Observable { + return this.httpClient.get(API_BASE_URL + '/markets/24hvolumes'); + } } diff --git a/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.html b/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.html index 92fff717b..1da618e8b 100644 --- a/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.html +++ b/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.html @@ -4,20 +4,28 @@ - - - - - + + + + + + - + + + +
CoinPairPrice24h volumeVolume %RankCurrencyPairPriceVolume (24h)Trades (24h)
{{ i + 1 }} {{ ticker.market.lname }} {{ ticker.pair }} - {{ ticker.last | currency: ticker.market.rsymbol }} + + {{ ticker.last | currency: ticker.market.rsymbol }} + + + {{ ticker.volume?.num_trades }}
@@ -29,6 +37,6 @@ - + \ No newline at end of file diff --git a/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.ts b/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.ts index bc1303fd6..f9178cd07 100644 --- a/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.ts +++ b/frontend/src/app/bisq/bisq-dashboard/bisq-dashboard.component.ts @@ -19,18 +19,23 @@ export class BisqDashboardComponent implements OnInit { ngOnInit(): void { this.tickers$ = combineLatest([ this.bisqApiService.getMarketsTicker$(), - this.bisqApiService.getMarkets$() + this.bisqApiService.getMarkets$(), + this.bisqApiService.getMarket24hVolumes$(), ]) .pipe( - map(([tickers, markets]) => { + map(([tickers, markets, volumes]) => { const newTickers = []; for (const t in tickers) { tickers[t].pair_url = t; tickers[t].pair = t.replace('_', '/').toUpperCase(); tickers[t].market = markets[t]; + tickers[t].volume = volumes[t]; newTickers.push(tickers[t]); } console.log(newTickers); + + newTickers.sort((a, b) => (b.volume && b.volume.volume || 0) - (a.volume && a.volume.volume || 0)); + return newTickers; }) ); diff --git a/frontend/src/app/bisq/bisq-market/bisq-market.component.html b/frontend/src/app/bisq/bisq-market/bisq-market.component.html index f7d9f9df2..6eec86396 100644 --- a/frontend/src/app/bisq/bisq-market/bisq-market.component.html +++ b/frontend/src/app/bisq/bisq-market/bisq-market.component.html @@ -5,18 +5,17 @@

{{ currency.market.lname }} - {{ currency.pair }}

- {{ hlocData[hlocData.length - 1].close | currency: currency.market.rsymbol }} + {{ hlocData[hlocData.length - 1].close | currency: currency.market.rsymbol }} + {{ hlocData[hlocData.length - 1].close | number: '1.' + currency.market.rprecision + '-' + currency.market.rprecision }} {{ currency.market.rsymbol }}
-