Skip to content

Commit 9a6e70f

Browse files
author
Karl Ranna
authored
feat: Kraken follow-up fixes v2 (#97)
* feat: add BTC/DAI allowed trading pair * feat: make CEX, BASEASSET and QUOTEASSET config options case insensitive * feat: log CEX config value on startup
1 parent a23eaff commit 9a6e70f

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

src/__snapshots__/config.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`checkConfigOptions LIVE_CEX disabled does not allow LTC/LTC trading pair 1`] = `"Invalid trading pair LTC/LTC. Supported trading pairs are: ETH/BTC, BTC/USDT, LTC/BTC, LTC/USDT"`;
3+
exports[`checkConfigOptions LIVE_CEX disabled does not allow LTC/LTC trading pair 1`] = `"Invalid trading pair LTC/LTC. Supported trading pairs are: ETH/BTC, BTC/USDT, BTC/DAI, LTC/BTC, LTC/USDT"`;
44

55
exports[`checkConfigOptions LIVE_CEX disabled requires TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE 1`] = `"Incomplete configuration. Please add the following options to .env or as environment variables: TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE"`;
66

src/arby.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ const logConfig = (config: Config, logger: Logger) => {
5252
TEST_CENTRALIZED_EXCHANGE_QUOTEASSET_BALANCE,
5353
TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE,
5454
LIVE_CEX,
55+
CEX,
5556
} = config;
5657
logger.info(`Running with config:
5758
LIVE_CEX: ${LIVE_CEX}
59+
CEX: ${CEX}
5860
LOG_LEVEL: ${LOG_LEVEL}
5961
DATA_DIR: ${DATA_DIR}
6062
OPENDEX_CERT_PATH: ${OPENDEX_CERT_PATH}

src/centralized/ccxt/exchange.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('getExchange', () => {
1212
it('initializes Binance with API key and secret', () => {
1313
const config = {
1414
...testConfig(),
15-
...{ CEX: 'Binance' },
15+
...{ CEX: 'BINANCE' },
1616
};
1717
getExchange(config);
1818
expect(ccxt.binance).toHaveBeenCalledTimes(1);
@@ -27,7 +27,7 @@ describe('getExchange', () => {
2727
it('initializes Kraken with API key and secret', () => {
2828
const config = {
2929
...testConfig(),
30-
...{ CEX: 'Kraken' },
30+
...{ CEX: 'KRAKEN' },
3131
};
3232
getExchange(config);
3333
expect(ccxt.kraken).toHaveBeenCalledTimes(1);

src/centralized/ccxt/exchange.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { Config } from '../../config';
33

44
const getExchange = (config: Config): Exchange => {
55
switch (config.CEX) {
6-
case 'Binance':
6+
case 'BINANCE':
77
return new ccxt.binance({
88
apiKey: config.CEX_API_KEY,
99
secret: config.CEX_API_SECRET,
1010
});
11-
case 'Kraken':
11+
case 'KRAKEN':
1212
return new ccxt.kraken({
1313
apiKey: config.CEX_API_KEY,
1414
secret: config.CEX_API_SECRET,

src/config.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ describe('checkConfigOptions', () => {
44
describe('LIVE_CEX disabled', () => {
55
const validLiveCEXdisabledConf = {
66
LOG_LEVEL: 'trace',
7-
CEX: 'Binance',
7+
CEX: 'binance',
88
DATA_DIR: '/some/data/path',
99
OPENDEX_CERT_PATH: '/some/cert/path',
1010
OPENDEX_RPC_HOST: 'localhost',
1111
OPENDEX_RPC_PORT: '1234',
1212
MARGIN: '0.06',
13-
BASEASSET: 'BTC',
14-
QUOTEASSET: 'USDT',
13+
BASEASSET: 'btc',
14+
QUOTEASSET: 'usdt',
1515
TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE: '321',
1616
TEST_CENTRALIZED_EXCHANGE_QUOTEASSET_BALANCE: '123',
1717
LIVE_CEX: 'false',
@@ -22,18 +22,24 @@ describe('checkConfigOptions', () => {
2222
const config = checkConfigOptions(validLiveCEXdisabledConf);
2323
expect(config).toEqual({
2424
...config,
25+
CEX: 'BINANCE',
2526
LIVE_CEX: false,
27+
BASEASSET: 'BTC',
28+
QUOTEASSET: 'USDT',
2629
});
2730
});
2831

2932
it('allows ETH/BTC trading pair', () => {
3033
const config = checkConfigOptions({
3134
...validLiveCEXdisabledConf,
32-
...{ BASEASSET: 'ETH', QUOTEASSET: 'BTC' },
35+
...{ BASEASSET: 'eth', QUOTEASSET: 'btc' },
3336
});
3437
expect(config).toEqual({
3538
...config,
39+
CEX: 'BINANCE',
3640
LIVE_CEX: false,
41+
BASEASSET: 'ETH',
42+
QUOTEASSET: 'BTC',
3743
});
3844
});
3945

@@ -73,7 +79,7 @@ describe('checkConfigOptions', () => {
7379
describe('LIVE_CEX enabled', () => {
7480
const validLiveCEXenabledConf = {
7581
LOG_LEVEL: 'trace',
76-
CEX: 'Binance',
82+
CEX: 'kraken',
7783
CEX_API_KEY: '123',
7884
CEX_API_SECRET: 'abc',
7985
DATA_DIR: '/some/data/path',
@@ -91,6 +97,7 @@ describe('checkConfigOptions', () => {
9197
const config = checkConfigOptions(validLiveCEXenabledConf);
9298
expect(config).toEqual({
9399
...config,
100+
CEX: 'KRAKEN',
94101
LIVE_CEX: true,
95102
});
96103
});
@@ -102,6 +109,7 @@ describe('checkConfigOptions', () => {
102109
});
103110
expect(config).toEqual({
104111
...config,
112+
CEX: 'KRAKEN',
105113
LIVE_CEX: true,
106114
});
107115
});

src/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const getMissingOptions = (config: DotenvParseOutput): string => {
8787
const ALLOWED_TRADING_PAIRS: string[] = [
8888
'ETH/BTC',
8989
'BTC/USDT',
90+
'BTC/DAI',
9091
'LTC/BTC',
9192
'LTC/USDT',
9293
];
@@ -102,7 +103,7 @@ const checkConfigOptions = (dotEnvConfig: DotenvParseOutput): Config => {
102103
`Incomplete configuration. Please add the following options to .env or as environment variables: ${missingOptions}`
103104
);
104105
}
105-
const tradingPair = `${config.BASEASSET}/${config.QUOTEASSET}`;
106+
const tradingPair = `${config.BASEASSET}/${config.QUOTEASSET}`.toUpperCase();
106107
if (!ALLOWED_TRADING_PAIRS.includes(tradingPair)) {
107108
throw new Error(
108109
`Invalid trading pair ${tradingPair}. Supported trading pairs are: ${ALLOWED_TRADING_PAIRS.join(
@@ -114,6 +115,9 @@ const checkConfigOptions = (dotEnvConfig: DotenvParseOutput): Config => {
114115
...config,
115116
LOG_LEVEL: setLogLevel(config.LOG_LEVEL),
116117
LIVE_CEX: config.LIVE_CEX === 'true' ? true : false,
118+
CEX: config.CEX.toUpperCase(),
119+
BASEASSET: config.BASEASSET.toUpperCase(),
120+
QUOTEASSET: config.QUOTEASSET.toUpperCase(),
117121
};
118122
return verifiedConfig as Config;
119123
};

0 commit comments

Comments
 (0)