mirror of
https://github.com/mempool/mempool.git
synced 2025-01-18 05:12:35 +01:00
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 allCurrenciesIndexed: { [code: string]: Currency } = {};
|
||||
private tradeDataByMarket: { [market: string]: TradesData[] } = {};
|
||||
private tickersCache: Ticker | Tickers | null = null;
|
||||
|
||||
constructor() { }
|
||||
|
||||
@ -49,6 +50,11 @@ class BisqMarketsApi {
|
||||
});
|
||||
}
|
||||
|
||||
updateCache() {
|
||||
this.tickersCache = null;
|
||||
this.tickersCache = this.getTicker();
|
||||
}
|
||||
|
||||
getCurrencies(
|
||||
type: 'crypto' | 'fiat' | 'all' = 'all',
|
||||
): Currencies {
|
||||
@ -281,6 +287,10 @@ class BisqMarketsApi {
|
||||
return this.getTickerFromMarket(market);
|
||||
}
|
||||
|
||||
if (this.tickersCache) {
|
||||
return this.tickersCache;
|
||||
}
|
||||
|
||||
const allMarkets = this.getMarkets();
|
||||
const tickers = {};
|
||||
for (const m in allMarkets) {
|
||||
|
@ -93,6 +93,7 @@ class Bisq {
|
||||
}
|
||||
const time = new Date().getTime() - start;
|
||||
if (marketsDataUpdated) {
|
||||
bisqMarket.updateCache();
|
||||
console.log('Bisq market data updated in ' + time + ' ms');
|
||||
}
|
||||
} catch (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user