Browse Source
Merge pull request #49 from dandevaud/feature/refactor-transactionpoint-and-position-calculation
Added better cachettl handling
pull/5027/head
dandevaud
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
22 additions and
1 deletions
-
apps/api/src/services/data-provider/data-provider.service.ts
|
|
@ -325,6 +325,8 @@ export class DataProviderService { |
|
|
|
result |
|
|
|
)) { |
|
|
|
response[symbol] = dataProviderResponse; |
|
|
|
let quotesCacheTTL = |
|
|
|
this.getAppropriateCacheTTL(dataProviderResponse); |
|
|
|
|
|
|
|
this.redisCacheService.set( |
|
|
|
this.redisCacheService.getQuoteKey({ |
|
|
@ -332,7 +334,7 @@ export class DataProviderService { |
|
|
|
symbol |
|
|
|
}), |
|
|
|
JSON.stringify(dataProviderResponse), |
|
|
|
this.configurationService.get('CACHE_QUOTES_TTL') |
|
|
|
quotesCacheTTL |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
@ -384,6 +386,25 @@ export class DataProviderService { |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
private getAppropriateCacheTTL(dataProviderResponse: IDataProviderResponse) { |
|
|
|
let quotesCacheTTL = this.configurationService.get('CACHE_QUOTES_TTL'); |
|
|
|
|
|
|
|
if (dataProviderResponse.dataSource === 'MANUAL') { |
|
|
|
quotesCacheTTL = 14400; // 4h Cache for Manual Service
|
|
|
|
} else if (dataProviderResponse.marketState === 'closed') { |
|
|
|
let date = new Date(); |
|
|
|
let dayOfWeek = date.getDay(); |
|
|
|
if (dayOfWeek === 0 || dayOfWeek === 6) { |
|
|
|
quotesCacheTTL = 14400; |
|
|
|
} else if (date.getHours() > 16) { |
|
|
|
quotesCacheTTL = 14400; |
|
|
|
} else { |
|
|
|
quotesCacheTTL = 900; |
|
|
|
} |
|
|
|
} |
|
|
|
return quotesCacheTTL; |
|
|
|
} |
|
|
|
|
|
|
|
public async search({ |
|
|
|
includeIndices = false, |
|
|
|
query, |
|
|
|