2021-03-05 15:38:46 +07:00
|
|
|
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
2021-02-27 04:19:56 +07:00
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
import { combineLatest, merge, Observable, of } from 'rxjs';
|
|
|
|
import { filter, map, mergeAll, switchMap, tap } from 'rxjs/operators';
|
2021-03-05 15:38:46 +07:00
|
|
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
2021-02-27 04:19:56 +07:00
|
|
|
import { BisqApiService } from '../bisq-api.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bisq-market',
|
|
|
|
templateUrl: './bisq-market.component.html',
|
2021-03-05 02:02:21 +07:00
|
|
|
styleUrls: ['./bisq-market.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2021-02-27 04:19:56 +07:00
|
|
|
})
|
2021-03-05 15:38:46 +07:00
|
|
|
export class BisqMarketComponent implements OnInit, OnDestroy {
|
2021-02-27 04:19:56 +07:00
|
|
|
hlocData$: Observable<any>;
|
|
|
|
currency$: Observable<any>;
|
2021-03-05 02:02:21 +07:00
|
|
|
offers$: Observable<any>;
|
2021-03-13 18:24:50 +07:00
|
|
|
trades$: Observable<any>;
|
2021-02-27 04:19:56 +07:00
|
|
|
radioGroupForm: FormGroup;
|
2021-03-13 18:24:50 +07:00
|
|
|
defaultInterval = 'day';
|
2021-02-27 04:19:56 +07:00
|
|
|
|
|
|
|
constructor(
|
2021-03-05 15:38:46 +07:00
|
|
|
private websocketService: WebsocketService,
|
2021-02-27 04:19:56 +07:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private bisqApiService: BisqApiService,
|
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.radioGroupForm = this.formBuilder.group({
|
|
|
|
interval: [this.defaultInterval],
|
|
|
|
});
|
|
|
|
|
|
|
|
this.currency$ = this.bisqApiService.getMarkets$()
|
|
|
|
.pipe(
|
|
|
|
switchMap((markets) => combineLatest([of(markets), this.route.paramMap])),
|
|
|
|
map(([markets, routeParams]) => {
|
|
|
|
const pair = routeParams.get('pair');
|
|
|
|
return {
|
|
|
|
pair: pair.replace('_', '/').toUpperCase(),
|
|
|
|
market: markets[pair],
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2021-03-13 18:24:50 +07:00
|
|
|
this.trades$ = this.route.paramMap
|
|
|
|
.pipe(
|
|
|
|
map(routeParams => routeParams.get('pair')),
|
|
|
|
switchMap((marketPair) => this.bisqApiService.getMarketTrades$(marketPair)),
|
|
|
|
);
|
|
|
|
|
2021-03-05 02:02:21 +07:00
|
|
|
this.offers$ = this.route.paramMap
|
|
|
|
.pipe(
|
|
|
|
map(routeParams => routeParams.get('pair')),
|
|
|
|
switchMap((marketPair) => this.bisqApiService.getMarketOffers$(marketPair)),
|
2021-03-10 23:02:55 +07:00
|
|
|
map((offers) => offers[Object.keys(offers)[0]])
|
2021-03-05 02:02:21 +07:00
|
|
|
);
|
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
this.hlocData$ = combineLatest([
|
|
|
|
this.route.paramMap,
|
|
|
|
merge(this.radioGroupForm.get('interval').valueChanges, of(this.defaultInterval)),
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
switchMap(([routeParams, interval]) => {
|
|
|
|
const pair = routeParams.get('pair');
|
|
|
|
return this.bisqApiService.getMarketsHloc$(pair, interval);
|
|
|
|
}),
|
2021-03-10 23:02:55 +07:00
|
|
|
map((hlocData) => {
|
|
|
|
hlocData = hlocData.map((h) => {
|
2021-02-27 04:19:56 +07:00
|
|
|
h.time = h.period_start;
|
|
|
|
return h;
|
|
|
|
});
|
2021-03-10 23:02:55 +07:00
|
|
|
return {
|
|
|
|
hloc: hlocData,
|
|
|
|
volume: hlocData.map((h) => {
|
|
|
|
return {
|
|
|
|
time: h.time,
|
|
|
|
value: h.volume_right,
|
|
|
|
color: h.close > h.avg ? 'rgba(0, 150, 136, 0.8)' : 'rgba(255,82,82, 0.8)',
|
|
|
|
};
|
|
|
|
})
|
|
|
|
};
|
2021-02-27 04:19:56 +07:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-05 15:38:46 +07:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.websocketService.stopTrackingBisqMarket();
|
|
|
|
}
|
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
}
|