import { Injectable } from '@angular/core' ; import { BehaviorSubject , Observable , timer } from 'rxjs' ; import { HttpService } from 'src/app/core/services/http/http.service' ; import { map , switchMap } from 'rxjs/operators' ; import { TradeVolume } from '@core/services/backend/volume-api/models/trade-volume' ; import { TradeVolumeRequest } from '@core/services/backend/volume-api/models/trade-volume-request' ; import { BigNumber } from 'bignumber.js' ; @ Injectable ( { providedIn : 'root' } ) export class VolumeApiService { private tradeVolume$ : BehaviorSubject < TradeVolume > ; return public get tradingVolume$ ( ) : Observable < TradeVolume > { return this . tradeVolume$ . asObservable ( ) ; } constructor ( private httpService ) { this . tradeVolume$ = new BehaviorSubject ( undefined ) ; this . setTradeVolumeInterval ( ) ; } /**
     * Makes request for trade volumes with interval and updates data volume.
     */ private setTradeVolumeInterval ( ) { timer ( 0 , 1000 * 60 * 60 ) . pipe ( switchMap ( ( ) => this . fetchVolume ( ) ) ) . subscribe ( volume => this . tradeVolume$ . next ( volume ) ) ; } return private fetchVolume ( ) { return this . httpService . get ( 'total_values/' ) . pipe ( map ( ( volume ) => ( { instantTrades : new BigNumber ( volume . instant_trades_amount ) , bridges : new BigNumber ( volume . bridges_amount ) } ) ) ) ; } }