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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ describe('ExchangeService', () => {
expect(service).toBeDefined();
});

it('should not be configured without credentials', () => {
expect(service.isConfigured).toBe(false);
});

it('should not be configured with only an apiKey', () => {
service = new ExchangeTestModule.TestExchangeService(
ExchangeTestModule.TestExchange,
{ apiKey: 'key' },
new QueueHandler(undefined, undefined),
);

expect(service.isConfigured).toBe(false);
});

it('should be configured with apiKey and secret', () => {
service = new ExchangeTestModule.TestExchangeService(
ExchangeTestModule.TestExchange,
{ apiKey: 'key', secret: 'secret' },
new QueueHandler(undefined, undefined),
);

expect(service.isConfigured).toBe(true);
});

it('should return BTC/EUR and buy', async () => {
Setup.Markets();

Expand Down
5 changes: 5 additions & 0 deletions src/integration/exchange/services/exchange.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export abstract class ExchangeService extends PricingProvider implements OnModul
return this.exchange.name;
}

// true only when both ccxt credentials are present; used to skip exchanges with no API keys (e.g. XT on dev)
get isConfigured(): boolean {
return !!this.config?.apiKey && !!this.config?.secret;
}

async getRawBalances(): Promise<Balances> {
return this.callApi((e) => e.fetchBalance());
}
Expand Down
5 changes: 5 additions & 0 deletions src/integration/exchange/services/scrypt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class ScryptService extends PricingProvider {

readonly name: string = 'Scrypt';

get isConfigured(): boolean {
const { apiKey, apiSecret } = GetConfig().scrypt;
return !!apiKey && !!apiSecret;
}

constructor() {
super();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export class ExchangeAdapter implements LiquidityBalanceIntegration {

private readonly ASSET_MAPPINGS = { BTC: ['XBT'] };

// exchanges already warned about missing credentials, to warn once instead of every cycle
private readonly unconfiguredWarned = new Set<string>();

constructor(
private readonly exchangeRegistry: ExchangeRegistryService,
private readonly orderRepo: LiquidityManagementOrderRepository,
Expand Down Expand Up @@ -57,8 +60,19 @@ export class ExchangeAdapter implements LiquidityBalanceIntegration {
// --- HELPER METHODS --- //

async getForExchange(exchange: string, assets: LiquidityManagementAsset[]): Promise<LiquidityBalance[]> {
const exchangeService = this.exchangeRegistry.getExchange(exchange);

// not configured (no API credentials) -> skip gracefully, warn once
if (!exchangeService.isConfigured) {
if (!this.unconfiguredWarned.has(exchange)) {
this.unconfiguredWarned.add(exchange);
this.logger.warn(`Exchange ${exchange} has no credentials configured — skipping liquidity balance`);
}

return assets.map((a) => LiquidityBalance.create(a, 0, 0));
}

try {
const exchangeService = this.exchangeRegistry.getExchange(exchange);
const { total: totalBalances, available: availableBalances } = await exchangeService.getBalances();

return assets.map((a) => {
Expand Down