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

View File

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