Markets API: Adding cache for general /ticker requests
This commit is contained in:
		
							parent
							
								
									84f0ebaba6
								
							
						
					
					
						commit
						508b5c0f4e
					
				@ -11,6 +11,7 @@ class BisqMarketsApi {
 | 
				
			|||||||
  private fiatCurrenciesIndexed: { [code: string]: true } = {};
 | 
					  private fiatCurrenciesIndexed: { [code: string]: true } = {};
 | 
				
			||||||
  private allCurrenciesIndexed: { [code: string]: Currency } = {};
 | 
					  private allCurrenciesIndexed: { [code: string]: Currency } = {};
 | 
				
			||||||
  private tradeDataByMarket: { [market: string]: TradesData[] } = {};
 | 
					  private tradeDataByMarket: { [market: string]: TradesData[] } = {};
 | 
				
			||||||
 | 
					  private tickersCache: Ticker | Tickers | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor() { }
 | 
					  constructor() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -49,6 +50,11 @@ class BisqMarketsApi {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  updateCache() {
 | 
				
			||||||
 | 
					    this.tickersCache = null;
 | 
				
			||||||
 | 
					    this.tickersCache = this.getTicker();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getCurrencies(
 | 
					  getCurrencies(
 | 
				
			||||||
    type: 'crypto' | 'fiat' | 'all' = 'all',
 | 
					    type: 'crypto' | 'fiat' | 'all' = 'all',
 | 
				
			||||||
  ): Currencies {
 | 
					  ): Currencies {
 | 
				
			||||||
@ -281,6 +287,10 @@ class BisqMarketsApi {
 | 
				
			|||||||
      return this.getTickerFromMarket(market);
 | 
					      return this.getTickerFromMarket(market);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (this.tickersCache) {
 | 
				
			||||||
 | 
					      return this.tickersCache;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const allMarkets = this.getMarkets();
 | 
					    const allMarkets = this.getMarkets();
 | 
				
			||||||
    const tickers = {};
 | 
					    const tickers = {};
 | 
				
			||||||
    for (const m in allMarkets) {
 | 
					    for (const m in allMarkets) {
 | 
				
			||||||
 | 
				
			|||||||
@ -93,6 +93,7 @@ class Bisq {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
      const time = new Date().getTime() - start;
 | 
					      const time = new Date().getTime() - start;
 | 
				
			||||||
      if (marketsDataUpdated) {
 | 
					      if (marketsDataUpdated) {
 | 
				
			||||||
 | 
					        bisqMarket.updateCache();
 | 
				
			||||||
        console.log('Bisq market data updated in ' + time + ' ms');
 | 
					        console.log('Bisq market data updated in ' + time + ' ms');
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user