|
@ -1,5 +1,7 @@ |
|
|
|
|
|
import { DATE_FORMAT } from '@ghostfolio/common/helper'; |
|
|
import { |
|
|
import { |
|
|
DataProviderGhostfolioStatusResponse, |
|
|
DataProviderGhostfolioStatusResponse, |
|
|
|
|
|
HistoricalResponse, |
|
|
LookupResponse, |
|
|
LookupResponse, |
|
|
QuotesResponse |
|
|
QuotesResponse |
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
} from '@ghostfolio/common/interfaces'; |
|
@ -7,6 +9,7 @@ import { |
|
|
import { CommonModule } from '@angular/common'; |
|
|
import { CommonModule } from '@angular/common'; |
|
|
import { HttpClient, HttpParams } from '@angular/common/http'; |
|
|
import { HttpClient, HttpParams } from '@angular/common/http'; |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
|
import { format, startOfYear } from 'date-fns'; |
|
|
import { map, Observable, Subject, takeUntil } from 'rxjs'; |
|
|
import { map, Observable, Subject, takeUntil } from 'rxjs'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
@ -18,6 +21,7 @@ import { map, Observable, Subject, takeUntil } from 'rxjs'; |
|
|
templateUrl: './api-page.html' |
|
|
templateUrl: './api-page.html' |
|
|
}) |
|
|
}) |
|
|
export class GfApiPageComponent implements OnInit { |
|
|
export class GfApiPageComponent implements OnInit { |
|
|
|
|
|
public historicalData$: Observable<HistoricalResponse['historicalData']>; |
|
|
public quotes$: Observable<QuotesResponse['quotes']>; |
|
|
public quotes$: Observable<QuotesResponse['quotes']>; |
|
|
public status$: Observable<DataProviderGhostfolioStatusResponse>; |
|
|
public status$: Observable<DataProviderGhostfolioStatusResponse>; |
|
|
public symbols$: Observable<LookupResponse['items']>; |
|
|
public symbols$: Observable<LookupResponse['items']>; |
|
@ -27,6 +31,7 @@ export class GfApiPageComponent implements OnInit { |
|
|
public constructor(private http: HttpClient) {} |
|
|
public constructor(private http: HttpClient) {} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
|
|
|
this.historicalData$ = this.fetchHistoricalData({ symbol: 'AAPL.US' }); |
|
|
this.quotes$ = this.fetchQuotes({ symbols: ['AAPL.US', 'VOO.US'] }); |
|
|
this.quotes$ = this.fetchQuotes({ symbols: ['AAPL.US', 'VOO.US'] }); |
|
|
this.status$ = this.fetchStatus(); |
|
|
this.status$ = this.fetchStatus(); |
|
|
this.symbols$ = this.fetchSymbols({ query: 'apple' }); |
|
|
this.symbols$ = this.fetchSymbols({ query: 'apple' }); |
|
@ -37,6 +42,24 @@ export class GfApiPageComponent implements OnInit { |
|
|
this.unsubscribeSubject.complete(); |
|
|
this.unsubscribeSubject.complete(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fetchHistoricalData({ symbol }: { symbol: string }) { |
|
|
|
|
|
const params = new HttpParams() |
|
|
|
|
|
.set('from', format(startOfYear(new Date()), DATE_FORMAT)) |
|
|
|
|
|
.set('to', format(new Date(), DATE_FORMAT)); |
|
|
|
|
|
|
|
|
|
|
|
return this.http |
|
|
|
|
|
.get<HistoricalResponse>( |
|
|
|
|
|
`/api/v1/data-providers/ghostfolio/historical/${symbol}`, |
|
|
|
|
|
{ params } |
|
|
|
|
|
) |
|
|
|
|
|
.pipe( |
|
|
|
|
|
map(({ historicalData }) => { |
|
|
|
|
|
return historicalData; |
|
|
|
|
|
}), |
|
|
|
|
|
takeUntil(this.unsubscribeSubject) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private fetchQuotes({ symbols }: { symbols: string[] }) { |
|
|
private fetchQuotes({ symbols }: { symbols: string[] }) { |
|
|
const params = new HttpParams().set('symbols', symbols.join(',')); |
|
|
const params = new HttpParams().set('symbols', symbols.join(',')); |
|
|
|
|
|
|
|
|