diff --git a/CHANGELOG.md b/CHANGELOG.md index fc1e9285..99830aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added a skeleton loader to the market mood component in the markets overview + ### Changed - Moved the build pipeline from _Travis_ to _GitHub Actions_ +- Increased the caching of the benchmarks ### Fixed diff --git a/apps/api/src/app/benchmark/benchmark.controller.ts b/apps/api/src/app/benchmark/benchmark.controller.ts index d3dcb0bb..4638e0c4 100644 --- a/apps/api/src/app/benchmark/benchmark.controller.ts +++ b/apps/api/src/app/benchmark/benchmark.controller.ts @@ -1,30 +1,20 @@ import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor'; import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response.interceptor'; -import { PropertyService } from '@ghostfolio/api/services/property/property.service'; -import { PROPERTY_BENCHMARKS } from '@ghostfolio/common/config'; -import { BenchmarkResponse, UniqueAsset } from '@ghostfolio/common/interfaces'; +import { BenchmarkResponse } from '@ghostfolio/common/interfaces'; import { Controller, Get, UseInterceptors } from '@nestjs/common'; import { BenchmarkService } from './benchmark.service'; @Controller('benchmark') export class BenchmarkController { - public constructor( - private readonly benchmarkService: BenchmarkService, - private readonly propertyService: PropertyService - ) {} + public constructor(private readonly benchmarkService: BenchmarkService) {} @Get() @UseInterceptors(TransformDataSourceInRequestInterceptor) @UseInterceptors(TransformDataSourceInResponseInterceptor) public async getBenchmark(): Promise { - const benchmarkAssets: UniqueAsset[] = - ((await this.propertyService.getByKey( - PROPERTY_BENCHMARKS - )) as UniqueAsset[]) ?? []; - return { - benchmarks: await this.benchmarkService.getBenchmarks(benchmarkAssets) + benchmarks: await this.benchmarkService.getBenchmarks() }; } } diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 2e8ee61d..f7238654 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -1,10 +1,13 @@ import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { MarketDataService } from '@ghostfolio/api/services/market-data.service'; +import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service'; +import { PROPERTY_BENCHMARKS } from '@ghostfolio/common/config'; import { BenchmarkResponse, UniqueAsset } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; import Big from 'big.js'; +import ms from 'ms'; @Injectable() export class BenchmarkService { @@ -13,25 +16,32 @@ export class BenchmarkService { public constructor( private readonly dataProviderService: DataProviderService, private readonly marketDataService: MarketDataService, + private readonly propertyService: PropertyService, private readonly redisCacheService: RedisCacheService, private readonly symbolProfileService: SymbolProfileService ) {} - public async getBenchmarks( - benchmarkAssets: UniqueAsset[] - ): Promise { + public async getBenchmarks({ useCache = true } = {}): Promise< + BenchmarkResponse['benchmarks'] + > { let benchmarks: BenchmarkResponse['benchmarks']; - try { - benchmarks = JSON.parse( - await this.redisCacheService.get(this.CACHE_KEY_BENCHMARKS) - ); + if (useCache) { + try { + benchmarks = JSON.parse( + await this.redisCacheService.get(this.CACHE_KEY_BENCHMARKS) + ); - if (benchmarks) { - return benchmarks; - } - } catch {} + if (benchmarks) { + return benchmarks; + } + } catch {} + } + const benchmarkAssets: UniqueAsset[] = + ((await this.propertyService.getByKey( + PROPERTY_BENCHMARKS + )) as UniqueAsset[]) ?? []; const promises: Promise[] = []; const [quotes, assetProfiles] = await Promise.all([ @@ -76,7 +86,8 @@ export class BenchmarkService { await this.redisCacheService.set( this.CACHE_KEY_BENCHMARKS, - JSON.stringify(benchmarks) + JSON.stringify(benchmarks), + ms('4 hours') / 1000 ); return benchmarks; diff --git a/apps/api/src/services/twitter-bot/twitter-bot.module.ts b/apps/api/src/services/twitter-bot/twitter-bot.module.ts index 02213ef6..5e9b304e 100644 --- a/apps/api/src/services/twitter-bot/twitter-bot.module.ts +++ b/apps/api/src/services/twitter-bot/twitter-bot.module.ts @@ -7,7 +7,7 @@ import { Module } from '@nestjs/common'; @Module({ exports: [TwitterBotService], - imports: [BenchmarkModule, ConfigurationModule, PropertyModule, SymbolModule], + imports: [BenchmarkModule, ConfigurationModule, SymbolModule], providers: [TwitterBotService] }) export class TwitterBotModule {} diff --git a/apps/api/src/services/twitter-bot/twitter-bot.service.ts b/apps/api/src/services/twitter-bot/twitter-bot.service.ts index 402159ad..9deb8fb1 100644 --- a/apps/api/src/services/twitter-bot/twitter-bot.service.ts +++ b/apps/api/src/services/twitter-bot/twitter-bot.service.ts @@ -1,9 +1,7 @@ import { BenchmarkService } from '@ghostfolio/api/app/benchmark/benchmark.service'; import { SymbolService } from '@ghostfolio/api/app/symbol/symbol.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { - PROPERTY_BENCHMARKS, ghostfolioFearAndGreedIndexDataSource, ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config'; @@ -11,7 +9,6 @@ import { resolveFearAndGreedIndex, resolveMarketCondition } from '@ghostfolio/common/helper'; -import { UniqueAsset } from '@ghostfolio/common/interfaces'; import { Injectable, Logger } from '@nestjs/common'; import { isWeekend } from 'date-fns'; import { TwitterApi, TwitterApiReadWrite } from 'twitter-api-v2'; @@ -23,7 +20,6 @@ export class TwitterBotService { public constructor( private readonly benchmarkService: BenchmarkService, private readonly configurationService: ConfigurationService, - private readonly propertyService: PropertyService, private readonly symbolService: SymbolService ) { this.twitterClient = new TwitterApi({ @@ -82,14 +78,9 @@ export class TwitterBotService { } private async getBenchmarkListing(aMax: number) { - const benchmarkAssets: UniqueAsset[] = - ((await this.propertyService.getByKey( - PROPERTY_BENCHMARKS - )) as UniqueAsset[]) ?? []; - - const benchmarks = await this.benchmarkService.getBenchmarks( - benchmarkAssets - ); + const benchmarks = await this.benchmarkService.getBenchmarks({ + useCache: false + }); const benchmarkListing: string[] = []; diff --git a/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.html b/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.html index 16b2ea60..6bc52fa1 100644 --- a/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.html +++ b/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.html @@ -1,13 +1,23 @@ -
-
{{ fearAndGreedIndexEmoji }}
-
-
- {{ fearAndGreedIndexText }} - {{ fearAndGreedIndex }}/100 +
+
+
{{ fearAndGreedIndexEmoji }}
+
+
+ {{ fearAndGreedIndexText }} + {{ fearAndGreedIndex }}/100 +
+ Current Market Mood
- Current Market Mood
+
diff --git a/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.scss b/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.scss index 5d4e87f3..dfe024a0 100644 --- a/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.scss +++ b/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.component.scss @@ -1,3 +1,8 @@ :host { display: block; + + ngx-skeleton-loader { + bottom: 0; + top: 0; + } } diff --git a/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.module.ts b/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.module.ts index ad2143aa..42632634 100644 --- a/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.module.ts +++ b/apps/client/src/app/components/fear-and-greed-index/fear-and-greed-index.module.ts @@ -1,11 +1,12 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; +import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { FearAndGreedIndexComponent } from './fear-and-greed-index.component'; @NgModule({ declarations: [FearAndGreedIndexComponent], exports: [FearAndGreedIndexComponent], - imports: [CommonModule] + imports: [CommonModule, NgxSkeletonLoaderModule] }) export class GfFearAndGreedIndexModule {} diff --git a/apps/client/src/app/components/home-market/home-market.html b/apps/client/src/app/components/home-market/home-market.html index fe6cba14..ba34c1fa 100644 --- a/apps/client/src/app/components/home-market/home-market.html +++ b/apps/client/src/app/components/home-market/home-market.html @@ -20,7 +20,6 @@