Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions src/subdomains/core/monitoring/observers/exchange.observer.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
import { Injectable } from '@nestjs/common';
import { CronExpression } from '@nestjs/schedule';
import { Blockchain } from 'src/integration/blockchain/shared/enums/blockchain.enum';
import { ExchangeTxType } from 'src/integration/exchange/entities/exchange-tx.entity';
import { ExchangeName } from 'src/integration/exchange/enums/exchange.enum';
import { AssetType } from 'src/shared/models/asset/asset.entity';
import { AssetService } from 'src/shared/models/asset/asset.service';
import { RepositoryFactory } from 'src/shared/repositories/repository.factory';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { DisabledProcess, Process } from 'src/shared/services/process.service';
import { DfxCron } from 'src/shared/utils/cron';
import { Util } from 'src/shared/utils/util';
import { MetricObserver } from 'src/subdomains/core/monitoring/metric.observer';
import { MonitoringService } from 'src/subdomains/core/monitoring/monitoring.service';
import { PriceSource } from 'src/subdomains/supporting/pricing/domain/entities/price-rule.entity';
import {
PriceCurrency,
PriceValidity,
PricingService,
} from 'src/subdomains/supporting/pricing/services/pricing.service';
import { MoreThan } from 'typeorm';

interface ExchangeData {
name: string;
volume30: number; //volume of the last 30 days
}

interface ExchangeDeviationData {
name: string;
deviation: number; // deviation of exchange pair to reference price
}

@Injectable()
export class ExchangeObserver extends MetricObserver<ExchangeData[]> {
protected readonly logger = new DfxLogger(ExchangeObserver);

constructor(
monitoringService: MonitoringService,
private readonly repos: RepositoryFactory,
private readonly pricingService: PricingService,
private readonly assetService: AssetService,
) {
super(monitoringService, 'exchange', 'volume');
}
Expand All @@ -50,56 +34,13 @@ export class ExchangeObserver extends MetricObserver<ExchangeData[]> {
const data = [];
data.push(await this.getKraken());
data.push(await this.getBinance());
data.push(await this.getXtPriceDeviation());
this.emit(data);

return data;
}

// *** HELPER METHODS *** //

private async getXtPriceDeviation(): Promise<ExchangeDeviationData[]> {
const [usdt, jusd] = await Promise.all([
this.assetService.getAssetByQuery({
name: 'USDT',
blockchain: Blockchain.ETHEREUM,
type: AssetType.TOKEN,
}),
await this.assetService.getAssetByQuery({
name: 'JUSD',
blockchain: Blockchain.CITREA,
type: AssetType.TOKEN,
}),
]);

const xtDeurUsdtPrice = await this.pricingService.getPriceFrom(PriceSource.XT, 'USDT', 'DEURO');
const xtDepsUsdtPrice = await this.pricingService.getPriceFrom(PriceSource.XT, 'USDT', 'DEPS');
const xtJusdUsdtPrice = await this.pricingService.getPriceFrom(PriceSource.XT, 'USDT', 'JUSD');

const referenceDeurUsdtPrice = await this.pricingService.getPrice(
usdt,
PriceCurrency.EUR,
PriceValidity.VALID_ONLY,
);
const referenceDepsUsdtPrice = await this.pricingService.getPriceFrom(PriceSource.DEURO, 'USDT', 'DEPS');
const referenceJusdUsdtPrice = await this.pricingService.getPrice(usdt, jusd, PriceValidity.VALID_ONLY);

return [
{
name: 'XT-dEURO-USDT',
deviation: Util.round(xtDeurUsdtPrice.price / referenceDeurUsdtPrice.price - 1, 3),
},
{
name: 'XT-DEPS-USDT',
deviation: Util.round(xtDepsUsdtPrice.price / referenceDepsUsdtPrice.price - 1, 3),
},
{
name: 'XT-JUSD-USDT',
deviation: Util.round(xtJusdUsdtPrice.price / referenceJusdUsdtPrice.price - 1, 3),
},
];
}

private async getKraken(): Promise<ExchangeData> {
const volume30 = await this.getVolume30(ExchangeName.KRAKEN);
return {
Expand Down