Bugfix/fix data source of fear and greed index (#663)

* Encode data source

* Update changelog
pull/664/head
Thomas Kaul 2 years ago committed by GitHub
parent fed28f29d1
commit 161cb82820
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
-Fixed the data source of the _Fear & Greed Index_ (market mood)
## 1.109.0 - 01.02.2022
### Added

@ -11,12 +11,14 @@ import {
PROPERTY_STRIPE_CONFIG,
PROPERTY_SYSTEM_MESSAGE
} from '@ghostfolio/common/config';
import { encodeDataSource } from '@ghostfolio/common/helper';
import { InfoItem } from '@ghostfolio/common/interfaces';
import { Statistics } from '@ghostfolio/common/interfaces/statistics.interface';
import { Subscription } from '@ghostfolio/common/interfaces/subscription.interface';
import { permissions } from '@ghostfolio/common/permissions';
import { Injectable, Logger } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { DataSource } from '@prisma/client';
import * as bent from 'bent';
import { subDays } from 'date-fns';
@ -49,6 +51,10 @@ export class InfoService {
globalPermissions.push(permissions.enableBlog);
}
if (this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX')) {
info.fearAndGreedDataSource = encodeDataSource(DataSource.RAKUTEN);
}
if (this.configurationService.get('ENABLE_FEATURE_IMPORT')) {
globalPermissions.push(permissions.enableImport);
}

@ -1,3 +1,4 @@
import { decodeDataSource } from '@ghostfolio/common/helper';
import {
CallHandler,
ExecutionContext,
@ -24,22 +25,14 @@ export class TransformDataSourceInRequestInterceptor<T>
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') === true) {
if (request.body.dataSource) {
request.body.dataSource = this.decodeDataSource(
request.body.dataSource
);
request.body.dataSource = decodeDataSource(request.body.dataSource);
}
if (request.params.dataSource) {
request.params.dataSource = this.decodeDataSource(
request.params.dataSource
);
request.params.dataSource = decodeDataSource(request.params.dataSource);
}
}
return next.handle();
}
private decodeDataSource(encodeDataSource: string) {
return Buffer.from(encodeDataSource, 'hex').toString();
}
}

@ -1,10 +1,10 @@
import { encodeDataSource } from '@ghostfolio/common/helper';
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor
} from '@nestjs/common';
import { DataSource } from '@prisma/client';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ConfigurationService } from '../services/configuration.service';
@ -28,22 +28,22 @@ export class TransformDataSourceInResponseInterceptor<T>
) {
if (data.activities) {
data.activities.map((activity) => {
activity.SymbolProfile.dataSource = this.encodeDataSource(
activity.SymbolProfile.dataSource = encodeDataSource(
activity.SymbolProfile.dataSource
);
activity.dataSource = this.encodeDataSource(activity.dataSource);
activity.dataSource = encodeDataSource(activity.dataSource);
return activity;
});
}
if (data.dataSource) {
data.dataSource = this.encodeDataSource(data.dataSource);
data.dataSource = encodeDataSource(data.dataSource);
}
if (data.holdings) {
for (const symbol of Object.keys(data.holdings)) {
if (data.holdings[symbol].dataSource) {
data.holdings[symbol].dataSource = this.encodeDataSource(
data.holdings[symbol].dataSource = encodeDataSource(
data.holdings[symbol].dataSource
);
}
@ -52,14 +52,14 @@ export class TransformDataSourceInResponseInterceptor<T>
if (data.items) {
data.items.map((item) => {
item.dataSource = this.encodeDataSource(item.dataSource);
item.dataSource = encodeDataSource(item.dataSource);
return item;
});
}
if (data.positions) {
data.positions.map((position) => {
position.dataSource = this.encodeDataSource(position.dataSource);
position.dataSource = encodeDataSource(position.dataSource);
return position;
});
}
@ -69,8 +69,4 @@ export class TransformDataSourceInResponseInterceptor<T>
})
);
}
private encodeDataSource(aDataSource: DataSource) {
return Buffer.from(aDataSource, 'utf-8').toString('hex');
}
}

@ -4,9 +4,8 @@ import { DataService } from '@ghostfolio/client/services/data.service';
import { UserService } from '@ghostfolio/client/services/user/user.service';
import { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config';
import { resetHours } from '@ghostfolio/common/helper';
import { User } from '@ghostfolio/common/interfaces';
import { InfoItem, User } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { DataSource } from '@prisma/client';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@ -19,6 +18,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
public fearAndGreedIndex: number;
public hasPermissionToAccessFearAndGreedIndex: boolean;
public historicalData: HistoricalDataItem[];
public info: InfoItem;
public isLoading = true;
public readonly numberOfDays = 90;
public user: User;
@ -33,6 +33,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
private dataService: DataService,
private userService: UserService
) {
this.info = this.dataService.fetchInfo();
this.isLoading = true;
this.userService.stateChanged
@ -49,7 +50,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
if (this.hasPermissionToAccessFearAndGreedIndex) {
this.dataService
.fetchSymbolItem({
dataSource: DataSource.RAKUTEN,
dataSource: this.info.fearAndGreedDataSource,
includeHistoricalData: this.numberOfDays,
symbol: ghostfolioFearAndGreedIndexSymbol
})

@ -141,7 +141,7 @@ export class DataService {
includeHistoricalData,
symbol
}: {
dataSource: DataSource;
dataSource: DataSource | string;
includeHistoricalData?: number;
symbol: string;
}) {

@ -1,4 +1,5 @@
import * as currencies from '@dinero.js/currencies';
import { DataSource } from '@prisma/client';
import { getDate, getMonth, getYear, parse, subDays } from 'date-fns';
import { ghostfolioScraperApiSymbolPrefix } from './config';
@ -7,6 +8,14 @@ export function capitalize(aString: string) {
return aString.charAt(0).toUpperCase() + aString.slice(1).toLowerCase();
}
export function decodeDataSource(encodedDataSource: string) {
return Buffer.from(encodedDataSource, 'hex').toString();
}
export function encodeDataSource(aDataSource: DataSource) {
return Buffer.from(aDataSource, 'utf-8').toString('hex');
}
export function getBackgroundColor() {
return getCssVariable(
window.matchMedia('(prefers-color-scheme: dark)').matches

@ -4,6 +4,7 @@ import { Subscription } from './subscription.interface';
export interface InfoItem {
currencies: string[];
demoAuthToken: string;
fearAndGreedDataSource?: string;
globalPermissions: string[];
isReadOnlyMode?: boolean;
lastDataGathering?: Date;

Loading…
Cancel
Save