Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions src/payment/models/exchange/exchange.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import { Module } from '@nestjs/common';
import { SharedModule } from 'src/shared/shared.module';
import { CurrencyService } from './services/currency.service';
import { FixerService } from './services/fixer.service';
import { FtxService } from './services/ftx.service';

@Module({
imports: [SharedModule],
controllers: [ExchangeController],
providers: [KrakenService, BinanceService, BitstampService, BitpandaService, FixerService, CurrencyService],
exports: [KrakenService, BinanceService, BitstampService, BitpandaService, FixerService, CurrencyService],
providers: [
KrakenService,
BinanceService,
BitstampService,
BitpandaService,
FtxService,
FixerService,
CurrencyService,
],
exports: [KrakenService, BinanceService, BitstampService, BitpandaService, FtxService, FixerService, CurrencyService],
})
export class ExchangeModule {}
11 changes: 11 additions & 0 deletions src/payment/models/exchange/services/ftx.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { ExchangeService } from './exchange.service';
import { ftx } from 'ccxt';
import { GetConfig } from 'src/config/config';

@Injectable()
export class FtxService extends ExchangeService {
constructor() {
super(new ftx(GetConfig().exchange));
}
}
32 changes: 21 additions & 11 deletions src/payment/models/pricing/__tests__/pricing.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BitpandaService } from '../../exchange/services/bitpanda.service';
import { BitstampService } from '../../exchange/services/bitstamp.service';
import { CurrencyService } from '../../exchange/services/currency.service';
import { FixerService } from '../../exchange/services/fixer.service';
import { FtxService } from '../../exchange/services/ftx.service';
import { KrakenService } from '../../exchange/services/kraken.service';
import { PricingService } from '../services/pricing.service';

Expand All @@ -16,13 +17,15 @@ describe('Pricing Module Integration Tests', () => {
let binanceService: BinanceService;
let bitstampService: BitstampService;
let bitpandaService: BitpandaService;
let ftxService: FtxService;
let currencyService: CurrencyService;
let fixerService: FixerService;

let krakenServiceGetPriceSpy: jest.SpyInstance;
let binanceServiceGetPriceSpy: jest.SpyInstance;
let bitstampServiceGetPriceSpy: jest.SpyInstance;
let bitpandaServiceGetPriceSpy: jest.SpyInstance;
let ftxServiceGetPriceSpy: jest.SpyInstance;
let currencyServiceGetPriceSpy: jest.SpyInstance;
let fixerServiceGetPriceSpy: jest.SpyInstance;

Expand All @@ -34,6 +37,7 @@ describe('Pricing Module Integration Tests', () => {
binanceService = mock<BinanceService>({ name: 'Binance' });
bitstampService = mock<BitstampService>({ name: 'Bitstamp' });
bitpandaService = mock<BitpandaService>({ name: 'Bitpanda' });
ftxService = mock<FtxService>({ name: 'Ftx' });
currencyService = mock<CurrencyService>({ name: 'CurrencyService' });
fixerService = mock<FixerService>({ name: 'FixerService' });

Expand All @@ -43,6 +47,7 @@ describe('Pricing Module Integration Tests', () => {
binanceService,
bitstampService,
bitpandaService,
ftxService,
currencyService,
fixerService,
);
Expand All @@ -51,6 +56,7 @@ describe('Pricing Module Integration Tests', () => {
binanceServiceGetPriceSpy = jest.spyOn(binanceService, 'getPrice');
bitstampServiceGetPriceSpy = jest.spyOn(bitstampService, 'getPrice');
bitpandaServiceGetPriceSpy = jest.spyOn(bitpandaService, 'getPrice');
ftxServiceGetPriceSpy = jest.spyOn(ftxService, 'getPrice');
currencyServiceGetPriceSpy = jest.spyOn(currencyService, 'getPrice');
fixerServiceGetPriceSpy = jest.spyOn(fixerService, 'getPrice');
});
Expand All @@ -60,6 +66,7 @@ describe('Pricing Module Integration Tests', () => {
binanceServiceGetPriceSpy.mockClear();
bitstampServiceGetPriceSpy.mockClear();
bitpandaServiceGetPriceSpy.mockClear();
ftxServiceGetPriceSpy.mockClear();
currencyServiceGetPriceSpy.mockClear();
fixerServiceGetPriceSpy.mockClear();
});
Expand Down Expand Up @@ -121,8 +128,8 @@ describe('Pricing Module Integration Tests', () => {
.spyOn(binanceService, 'getPrice')
.mockImplementationOnce(async (source, target) => createCustomPrice({ source, target, price: 0.014 }));

krakenServiceGetPriceSpy = jest
.spyOn(krakenService, 'getPrice')
ftxServiceGetPriceSpy = jest
.spyOn(ftxService, 'getPrice')
.mockImplementationOnce(async (source, target) => createCustomPrice({ source, target, price: 0.014 }));

const request = { from: 'BNB', to: 'BTC' };
Expand All @@ -147,6 +154,12 @@ describe('Pricing Module Integration Tests', () => {
});

it('calculates price path for FIAT_TO_ALTCOIN', async () => {
krakenServiceGetPriceSpy = jest
.spyOn(krakenService, 'getPrice')
.mockImplementationOnce(async (source: string, target: string) =>
createCustomPrice({ source, target, price: 0.000058 }),
);

binanceServiceGetPriceSpy = jest
.spyOn(binanceService, 'getPrice')
.mockImplementationOnce(async (source: string, target: string) =>
Expand All @@ -156,11 +169,8 @@ describe('Pricing Module Integration Tests', () => {
createCustomPrice({ source, target, price: 71.3 }),
);

krakenServiceGetPriceSpy = jest
.spyOn(krakenService, 'getPrice')
.mockImplementationOnce(async (source: string, target: string) =>
createCustomPrice({ source, target, price: 0.000058 }),
)
ftxServiceGetPriceSpy = jest
.spyOn(ftxService, 'getPrice')
.mockImplementationOnce(async (source: string, target: string) =>
createCustomPrice({ source, target, price: 71.3 }),
);
Expand Down Expand Up @@ -205,8 +215,8 @@ describe('Pricing Module Integration Tests', () => {
createCustomPrice({ source, target, price: 71.3 }),
);

krakenServiceGetPriceSpy = jest
.spyOn(krakenService, 'getPrice')
ftxServiceGetPriceSpy = jest
.spyOn(ftxService, 'getPrice')
.mockImplementationOnce(async (source: string, target: string) =>
createCustomPrice({ source, target, price: 0.081 }),
)
Expand Down Expand Up @@ -249,8 +259,8 @@ describe('Pricing Module Integration Tests', () => {
.spyOn(binanceService, 'getPrice')
.mockImplementationOnce(async (source, target) => createCustomPrice({ source, target, price: 12.38 }));

krakenServiceGetPriceSpy = jest
.spyOn(krakenService, 'getPrice')
ftxServiceGetPriceSpy = jest
.spyOn(ftxService, 'getPrice')
.mockImplementationOnce(async (source, target) => createCustomPrice({ source, target, price: 12.38 }));

const request = { from: 'BTC', to: 'ETH' };
Expand Down
12 changes: 7 additions & 5 deletions src/payment/models/pricing/services/pricing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BitpandaService } from '../../exchange/services/bitpanda.service';
import { BitstampService } from '../../exchange/services/bitstamp.service';
import { CurrencyService } from '../../exchange/services/currency.service';
import { FixerService } from '../../exchange/services/fixer.service';
import { FtxService } from '../../exchange/services/ftx.service';
import { KrakenService } from '../../exchange/services/kraken.service';
import { Altcoin, USDStableCoin, Fiat } from '../enums';
import { BadPriceRequestException } from '../exceptions/bad-price-request.exception';
Expand Down Expand Up @@ -36,6 +37,7 @@ export class PricingService {
private readonly binanceService: BinanceService,
private readonly bitstampService: BitstampService,
private readonly bitpandaService: BitpandaService,
private readonly ftxService: FtxService,
private readonly currencyService: CurrencyService,
private readonly fixerService: FixerService,
) {
Expand Down Expand Up @@ -98,7 +100,7 @@ export class PricingService {
new PriceStep({
providers: {
primary: [this.binanceService],
reference: [this.krakenService, this.bitstampService, this.bitpandaService],
reference: [this.ftxService, this.krakenService, this.bitstampService, this.bitpandaService],
},
}),
]),
Expand All @@ -117,7 +119,7 @@ export class PricingService {
from: 'BTC',
providers: {
primary: [this.binanceService],
reference: [this.krakenService, this.bitstampService, this.bitpandaService],
reference: [this.ftxService, this.krakenService, this.bitstampService, this.bitpandaService],
},
}),
]),
Expand All @@ -129,14 +131,14 @@ export class PricingService {
to: 'BTC',
providers: {
primary: [this.binanceService],
reference: [this.krakenService, this.bitstampService, this.bitpandaService],
reference: [this.ftxService, this.krakenService, this.bitstampService, this.bitpandaService],
},
}),
new PriceStep({
from: 'BTC',
providers: {
primary: [this.binanceService],
reference: [this.krakenService, this.bitstampService, this.bitpandaService],
reference: [this.ftxService, this.krakenService, this.bitstampService, this.bitpandaService],
},
}),
]),
Expand All @@ -147,7 +149,7 @@ export class PricingService {
new PriceStep({
providers: {
primary: [this.binanceService],
reference: [this.krakenService, this.bitstampService, this.bitpandaService],
reference: [this.ftxService, this.krakenService, this.bitstampService, this.bitpandaService],
},
}),
]),
Expand Down