2021-04-13 21:53:58 +02:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { Injectable } from '@angular/core';
|
2021-12-19 10:57:50 +01:00
|
|
|
import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-data.dto';
|
|
|
|
import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces';
|
2021-12-11 11:45:13 +01:00
|
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper';
|
|
|
|
import { DataSource, MarketData } from '@prisma/client';
|
|
|
|
import { format } from 'date-fns';
|
2021-04-13 21:53:58 +02:00
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class AdminService {
|
|
|
|
public constructor(private http: HttpClient) {}
|
|
|
|
|
|
|
|
public gatherMax() {
|
|
|
|
return this.http.post<void>(`/api/admin/gather/max`, {});
|
|
|
|
}
|
2021-07-24 21:13:48 +02:00
|
|
|
|
|
|
|
public gatherProfileData() {
|
|
|
|
return this.http.post<void>(`/api/admin/gather/profile-data`, {});
|
|
|
|
}
|
2021-11-30 21:06:10 +01:00
|
|
|
|
|
|
|
public gatherSymbol({
|
|
|
|
dataSource,
|
2021-12-11 11:45:13 +01:00
|
|
|
date,
|
2021-11-30 21:06:10 +01:00
|
|
|
symbol
|
|
|
|
}: {
|
|
|
|
dataSource: DataSource;
|
2021-12-11 11:45:13 +01:00
|
|
|
date?: Date;
|
2021-11-30 21:06:10 +01:00
|
|
|
symbol: string;
|
|
|
|
}) {
|
2021-12-11 11:45:13 +01:00
|
|
|
let url = `/api/admin/gather/${dataSource}/${symbol}`;
|
|
|
|
|
|
|
|
if (date) {
|
|
|
|
url = `${url}/${format(date, DATE_FORMAT)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.http.post<MarketData | void>(url, {});
|
2021-11-30 21:06:10 +01:00
|
|
|
}
|
2021-12-19 10:57:50 +01:00
|
|
|
|
|
|
|
public fetchSymbolForDate({
|
|
|
|
dataSource,
|
|
|
|
date,
|
|
|
|
symbol
|
|
|
|
}: {
|
|
|
|
dataSource: DataSource;
|
|
|
|
date: Date;
|
|
|
|
symbol: string;
|
|
|
|
}) {
|
|
|
|
const url = `/api/symbol/${dataSource}/${symbol}/${format(
|
|
|
|
date,
|
|
|
|
DATE_FORMAT
|
|
|
|
)}`;
|
|
|
|
|
|
|
|
return this.http.get<IDataProviderHistoricalResponse>(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
public putMarketData({
|
|
|
|
dataSource,
|
|
|
|
date,
|
|
|
|
marketData,
|
|
|
|
symbol
|
|
|
|
}: {
|
|
|
|
dataSource: DataSource;
|
|
|
|
date: Date;
|
|
|
|
marketData: UpdateMarketDataDto;
|
|
|
|
symbol: string;
|
|
|
|
}) {
|
|
|
|
const url = `/api/admin/market-data/${dataSource}/${symbol}/${format(
|
|
|
|
date,
|
|
|
|
DATE_FORMAT
|
|
|
|
)}`;
|
|
|
|
|
|
|
|
return this.http.put<MarketData>(url, marketData);
|
|
|
|
}
|
2021-04-13 21:53:58 +02:00
|
|
|
}
|