2021-02-27 04:19:56 +07:00
|
|
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
|
|
|
import { Observable, combineLatest } from 'rxjs';
|
2021-04-23 03:49:55 +04:00
|
|
|
import { map, share } from 'rxjs/operators';
|
2021-03-14 23:24:06 +07:00
|
|
|
import { SeoService } from 'src/app/services/seo.service';
|
2021-03-14 02:42:14 +07:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
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';
|
2021-04-23 03:49:55 +04:00
|
|
|
import { Trade } from '../bisq.interfaces';
|
2021-02-27 04:19:56 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bisq-dashboard',
|
|
|
|
templateUrl: './bisq-dashboard.component.html',
|
|
|
|
styleUrls: ['./bisq-dashboard.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
})
|
|
|
|
export class BisqDashboardComponent implements OnInit {
|
|
|
|
tickers$: Observable<any>;
|
2021-03-16 01:17:40 +07:00
|
|
|
volumes$: Observable<any>;
|
2021-04-23 03:49:55 +04:00
|
|
|
trades$: Observable<Trade[]>;
|
2021-03-16 01:17:40 +07:00
|
|
|
|
2021-03-14 02:42:14 +07:00
|
|
|
allowCryptoCoins = ['usdc', 'l-btc', 'bsq'];
|
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 bisqApiService: BisqApiService,
|
2021-03-14 02:42:14 +07:00
|
|
|
private stateService: StateService,
|
2021-03-14 23:24:06 +07:00
|
|
|
private seoService: SeoService,
|
2021-02-27 04:19:56 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-03-14 23:24:06 +07:00
|
|
|
this.seoService.setTitle(`Markets`);
|
2021-03-05 15:38:46 +07:00
|
|
|
this.websocketService.want(['blocks']);
|
|
|
|
|
2021-03-16 01:17:40 +07:00
|
|
|
this.volumes$ = this.bisqApiService.getAllVolumesDay$()
|
|
|
|
.pipe(
|
|
|
|
map((volumes) => {
|
|
|
|
const data = volumes.map((volume) => {
|
|
|
|
return {
|
|
|
|
time: volume.period_start,
|
|
|
|
value: volume.volume,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const linesData = volumes.map((volume) => {
|
|
|
|
return {
|
|
|
|
time: volume.period_start,
|
|
|
|
value: volume.num_trades,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
data: data,
|
|
|
|
linesData: linesData,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2021-04-23 03:49:55 +04:00
|
|
|
const getMarkets = this.bisqApiService.getMarkets$().pipe(share());
|
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
this.tickers$ = combineLatest([
|
|
|
|
this.bisqApiService.getMarketsTicker$(),
|
2021-04-23 03:49:55 +04:00
|
|
|
getMarkets,
|
2021-03-10 23:02:55 +07:00
|
|
|
this.bisqApiService.getMarketVolumesByTime$('7d'),
|
2021-02-27 04:19:56 +07:00
|
|
|
])
|
|
|
|
.pipe(
|
2021-02-28 17:18:29 +07:00
|
|
|
map(([tickers, markets, volumes]) => {
|
2021-03-14 02:42:14 +07:00
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
const newTickers = [];
|
|
|
|
for (const t in tickers) {
|
2021-03-14 02:42:14 +07:00
|
|
|
|
|
|
|
if (!this.stateService.env.OFFICIAL_BISQ_MARKETS) {
|
|
|
|
const pair = t.split('_');
|
|
|
|
if (pair[1] === 'btc' && this.allowCryptoCoins.indexOf(pair[0]) === -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 03:49:55 +04:00
|
|
|
const mappedTicker: any = tickers[t];
|
|
|
|
|
|
|
|
mappedTicker.pair_url = t;
|
|
|
|
mappedTicker.pair = t.replace('_', '/').toUpperCase();
|
|
|
|
mappedTicker.market = markets[t];
|
|
|
|
mappedTicker.volume = volumes[t];
|
|
|
|
newTickers.push(mappedTicker);
|
2021-02-27 04:19:56 +07:00
|
|
|
}
|
2021-02-28 17:18:29 +07:00
|
|
|
|
2021-03-10 23:02:55 +07:00
|
|
|
newTickers.sort((a, b) => (b.volume && b.volume.num_trades || 0) - (a.volume && a.volume.num_trades || 0));
|
2021-02-28 17:18:29 +07:00
|
|
|
|
2021-02-27 04:19:56 +07:00
|
|
|
return newTickers;
|
|
|
|
})
|
|
|
|
);
|
2021-04-23 03:49:55 +04:00
|
|
|
|
|
|
|
this.trades$ = combineLatest([
|
|
|
|
this.bisqApiService.getMarketTrades$('all'),
|
|
|
|
getMarkets,
|
|
|
|
])
|
|
|
|
.pipe(
|
|
|
|
map(([trades, markets]) => {
|
|
|
|
return trades.map((trade => {
|
|
|
|
trade._market = markets[trade.market];
|
|
|
|
return trade;
|
|
|
|
}));
|
|
|
|
}));
|
2021-02-27 04:19:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
trackByFn(index: number) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|