Markets API: Adding cache for general /ticker requests

This commit is contained in:
softsimon 2020-09-19 23:02:02 +07:00
parent 84f0ebaba6
commit 508b5c0f4e
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
2 changed files with 11 additions and 0 deletions

View File

@ -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) {

View File

@ -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) {