Browse Source

Feature/extend market data in admin panel (#716)

* Extend market data view

* Update changelog
pull/717/head
Thomas Kaul 3 years ago
committed by GitHub
parent
commit
fed771525e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
  3. 3
      apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.html
  4. 43
      apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts
  5. 1
      apps/client/src/app/components/admin-market-data/admin-market-data.html

1
CHANGELOG.md

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Displayed features in features overview page based on permissions - Displayed features in features overview page based on permissions
- Extended the data points of historical data in the admin control panel
## 1.117.0 - 19.02.2022 ## 1.117.0 - 19.02.2022

6
apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

@ -25,7 +25,7 @@ import {
@Injectable() @Injectable()
export class YahooFinanceService implements DataProviderInterface { export class YahooFinanceService implements DataProviderInterface {
private yahooFinanceHostname = 'https://query1.finance.yahoo.com'; private readonly yahooFinanceHostname = 'https://query1.finance.yahoo.com';
public constructor( public constructor(
private readonly cryptocurrencyService: CryptocurrencyService private readonly cryptocurrencyService: CryptocurrencyService
@ -274,7 +274,9 @@ export class YahooFinanceService implements DataProviderInterface {
name: value.name name: value.name
}); });
} }
} catch {} } catch (error) {
Logger.error(error);
}
return { items }; return { items };
} }

3
apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.html

@ -18,8 +18,7 @@
available: available:
marketDataByMonth[itemByMonth.key][ marketDataByMonth[itemByMonth.key][
i + 1 < 10 ? '0' + (i + 1) : i + 1 i + 1 < 10 ? '0' + (i + 1) : i + 1
]?.day === ]?.marketPrice,
i + 1,
today: isToday( today: isToday(
itemByMonth.key + '-' + (i + 1 < 10 ? '0' + (i + 1) : i + 1) itemByMonth.key + '-' + (i + 1 < 10 ? '0' + (i + 1) : i + 1)
) )

43
apps/client/src/app/components/admin-market-data-detail/admin-market-data-detail.component.ts

@ -12,7 +12,15 @@ import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config';
import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { DATE_FORMAT } from '@ghostfolio/common/helper';
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface'; import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
import { DataSource, MarketData } from '@prisma/client'; import { DataSource, MarketData } from '@prisma/client';
import { format, isBefore, isSameDay, isValid, parse } from 'date-fns'; import {
addDays,
format,
isBefore,
isSameDay,
isValid,
parse,
parseISO
} from 'date-fns';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, takeUntil } from 'rxjs'; import { Subject, takeUntil } from 'rxjs';
@ -26,6 +34,7 @@ import { MarketDataDetailDialog } from './market-data-detail-dialog/market-data-
}) })
export class AdminMarketDataDetailComponent implements OnChanges, OnInit { export class AdminMarketDataDetailComponent implements OnChanges, OnInit {
@Input() dataSource: DataSource; @Input() dataSource: DataSource;
@Input() dateOfFirstActivity: string;
@Input() marketData: MarketData[]; @Input() marketData: MarketData[];
@Input() symbol: string; @Input() symbol: string;
@ -36,7 +45,9 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {
public deviceType: string; public deviceType: string;
public historicalDataItems: LineChartItem[]; public historicalDataItems: LineChartItem[];
public marketDataByMonth: { public marketDataByMonth: {
[yearMonth: string]: { [day: string]: MarketData & { day: number } }; [yearMonth: string]: {
[day: string]: Pick<MarketData, 'date' | 'marketPrice'> & { day: number };
};
} = {}; } = {};
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
@ -57,9 +68,30 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {
value: marketDataItem.marketPrice value: marketDataItem.marketPrice
}; };
}); });
let date = parseISO(this.dateOfFirstActivity);
const missingMarketData: Partial<MarketData>[] = [];
if (this.historicalDataItems?.[0]?.date) {
while (
isBefore(
date,
parse(this.historicalDataItems[0].date, DATE_FORMAT, new Date())
)
) {
missingMarketData.push({
date,
marketPrice: undefined
});
date = addDays(date, 1);
}
}
this.marketDataByMonth = {}; this.marketDataByMonth = {};
for (const marketDataItem of this.marketData) { for (const marketDataItem of [...missingMarketData, ...this.marketData]) {
const currentDay = parseInt(format(marketDataItem.date, 'd'), 10); const currentDay = parseInt(format(marketDataItem.date, 'd'), 10);
const key = format(marketDataItem.date, 'yyyy-MM'); const key = format(marketDataItem.date, 'yyyy-MM');
@ -70,8 +102,9 @@ export class AdminMarketDataDetailComponent implements OnChanges, OnInit {
this.marketDataByMonth[key][ this.marketDataByMonth[key][
currentDay < 10 ? `0${currentDay}` : currentDay currentDay < 10 ? `0${currentDay}` : currentDay
] = { ] = {
...marketDataItem, date: marketDataItem.date,
day: currentDay day: currentDay,
marketPrice: marketDataItem.marketPrice
}; };
} }
} }

1
apps/client/src/app/components/admin-market-data/admin-market-data.html

@ -64,6 +64,7 @@
<td class="p-1" colspan="6"> <td class="p-1" colspan="6">
<gf-admin-market-data-detail <gf-admin-market-data-detail
[dataSource]="item.dataSource" [dataSource]="item.dataSource"
[dateOfFirstActivity]="item.date"
[marketData]="marketDataDetails" [marketData]="marketDataDetails"
[symbol]="item.symbol" [symbol]="item.symbol"
(marketDataChanged)="onMarketDataChanged($event)" (marketDataChanged)="onMarketDataChanged($event)"

Loading…
Cancel
Save