Skip to content

Commit fd970f2

Browse files
author
Karl Ranna
authored
feat(config): allow different BASEASSET and QUOTEASSET for CEX and DEX (#103)
* feat(config): allow different BASEASSET and QUOTEASSET for CEX and DEX * feat: remove valid trading pair config check
1 parent 7b8fe6e commit fd970f2

31 files changed

+219
-147
lines changed

src/__snapshots__/config.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
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, BTC/DAI, LTC/BTC, LTC/USDT, USDT/DAI"`;
4-
53
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"`;
64

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

src/arby.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ const logConfig = (config: Config, logger: Logger) => {
4747
OPENDEX_RPC_HOST,
4848
OPENDEX_RPC_PORT,
4949
MARGIN,
50-
BASEASSET,
51-
QUOTEASSET,
50+
CEX_BASEASSET,
51+
CEX_QUOTEASSET,
52+
OPENDEX_BASEASSET,
53+
OPENDEX_QUOTEASSET,
5254
TEST_CENTRALIZED_EXCHANGE_QUOTEASSET_BALANCE,
5355
TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE,
5456
LIVE_CEX,
@@ -63,8 +65,10 @@ OPENDEX_CERT_PATH: ${OPENDEX_CERT_PATH}
6365
OPENDEX_RPC_HOST: ${OPENDEX_RPC_HOST}
6466
OPENDEX_RPC_PORT: ${OPENDEX_RPC_PORT}
6567
MARGIN: ${MARGIN}
66-
BASEASSET: ${BASEASSET}
67-
QUOTEASSET: ${QUOTEASSET}
68+
OPENDEX_BASEASSET: ${OPENDEX_BASEASSET}
69+
OPENDEX_QUOTEASSET: ${OPENDEX_QUOTEASSET}
70+
CEX_BASEASSET: ${CEX_BASEASSET}
71+
CEX_QUOTEASSET: ${CEX_QUOTEASSET}
6872
TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE: ${TEST_CENTRALIZED_EXCHANGE_BASEASSET_BALANCE}
6973
TEST_CENTRALIZED_EXCHANGE_QUOTEASSET_BALANCE: ${TEST_CENTRALIZED_EXCHANGE_QUOTEASSET_BALANCE}`);
7074
};

src/centralized/ccxt/cancel-order.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ describe('CCXT', () => {
1212
} as unknown) as Exchange;
1313
const orderId = '123';
1414
const config = testConfig();
15-
const { BASEASSET, QUOTEASSET } = config;
16-
const tradingPair = `${BASEASSET}/${QUOTEASSET}`;
15+
const { CEX_BASEASSET, CEX_QUOTEASSET } = config;
16+
const tradingPair = `${CEX_BASEASSET}/${CEX_QUOTEASSET}`;
1717
const orders$ = cancelOrder$(exchange, config, orderId);
1818
orders$.subscribe({
1919
next: actualResponse => {

src/centralized/ccxt/cancel-order.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const cancelOrder$ = (
99
): Observable<Order> => {
1010
return defer(() =>
1111
from(
12-
exchange.cancelOrder(orderId, `${config.BASEASSET}/${config.QUOTEASSET}`)
12+
exchange.cancelOrder(
13+
orderId,
14+
`${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`
15+
)
1316
)
1417
);
1518
};

src/centralized/ccxt/create-order.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ describe('CCXT', () => {
2121
const config: Config = {
2222
...testConfig(),
2323
...{
24-
BASEASSET: 'ETH',
25-
QUOTEASSET: 'BTC',
24+
CEX_BASEASSET: 'ETH',
25+
CEX_QUOTEASSET: 'BTC',
2626
CEX: 'Binance',
2727
},
2828
};
29-
const expectedSymbol = `${config.BASEASSET}/${config.QUOTEASSET}`;
29+
const expectedSymbol = `${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`;
3030
const sellOrder$ = createOrder$({
3131
config,
3232
exchange,
@@ -61,13 +61,13 @@ describe('CCXT', () => {
6161
const config: Config = {
6262
...testConfig(),
6363
...{
64-
BASEASSET: 'BTC',
65-
QUOTEASSET: 'USDT',
64+
CEX_BASEASSET: 'BTC',
65+
CEX_QUOTEASSET: 'USDT',
6666
CEX: 'Binance',
6767
},
6868
};
6969
orderQuantity = new BigNumber('0.12345678');
70-
const expectedSymbol = `${config.BASEASSET}/${config.QUOTEASSET}`;
70+
const expectedSymbol = `${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`;
7171
const buyOrder$ = createOrder$({
7272
config,
7373
exchange,
@@ -102,12 +102,12 @@ describe('CCXT', () => {
102102
const config: Config = {
103103
...testConfig(),
104104
...{
105-
BASEASSET: 'BTC',
106-
QUOTEASSET: 'USDT',
105+
CEX_BASEASSET: 'BTC',
106+
CEX_QUOTEASSET: 'USDT',
107107
CEX: 'Kraken',
108108
},
109109
};
110-
const expectedSymbol = `${config.BASEASSET}/${config.QUOTEASSET}`;
110+
const expectedSymbol = `${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`;
111111
const buyOrder$ = createOrder$({
112112
config,
113113
exchange,
@@ -144,12 +144,12 @@ describe('CCXT', () => {
144144
const config: Config = {
145145
...testConfig(),
146146
...{
147-
BASEASSET: 'ETH',
148-
QUOTEASSET: 'BTC',
147+
CEX_BASEASSET: 'ETH',
148+
CEX_QUOTEASSET: 'BTC',
149149
CEX: 'Kraken',
150150
},
151151
};
152-
const expectedSymbol = `${config.BASEASSET}/${config.QUOTEASSET}`;
152+
const expectedSymbol = `${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`;
153153
const sellOrder$ = createOrder$({
154154
config,
155155
exchange,

src/centralized/ccxt/create-order.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const createOrder$ = ({
2323
config.CEX === 'Kraken' ? { trading_agreement: 'agree' } : undefined;
2424
return from(
2525
exchange.createMarketOrder(
26-
`${config.BASEASSET}/${config.QUOTEASSET}`,
26+
`${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`,
2727
side,
2828
parseFloat(quantity.toFixed(4, BigNumber.ROUND_DOWN)),
2929
price,

src/centralized/ccxt/fetch-open-orders.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const fetchOpenOrders$ = (
77
config: Config
88
): Observable<Order[]> => {
99
return defer(() =>
10-
from(exchange.fetchOpenOrders(`${config.BASEASSET}/${config.QUOTEASSET}`))
10+
from(
11+
exchange.fetchOpenOrders(
12+
`${config.CEX_BASEASSET}/${config.CEX_QUOTEASSET}`
13+
)
14+
)
1115
);
1216
};
1317

src/centralized/ccxt/fetch-orders.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe('CCXT', () => {
1111
fetchOpenOrders: fetchOpenOrdersMock,
1212
} as unknown) as Exchange;
1313
const config = testConfig();
14-
const { BASEASSET, QUOTEASSET } = config;
15-
const tradingPair = `${BASEASSET}/${QUOTEASSET}`;
14+
const { CEX_BASEASSET, CEX_QUOTEASSET } = config;
15+
const tradingPair = `${CEX_BASEASSET}/${CEX_QUOTEASSET}`;
1616
const orders$ = fetchOpenOrders$(exchange, config);
1717
orders$.subscribe({
1818
next: actualOrders => {

src/centralized/convert-balances.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ describe('convertBalances', () => {
77
it('converts CCXT Balances to ExchangeAssetAllocation', () => {
88
const config = testConfig();
99
const balances = ({} as unknown) as Balances;
10-
balances[config.BASEASSET] = {
10+
balances[config.CEX_BASEASSET] = {
1111
free: 10,
1212
used: 10,
1313
total: 20,
1414
};
15-
balances[config.QUOTEASSET] = {
15+
balances[config.CEX_QUOTEASSET] = {
1616
free: 1,
1717
used: 1,
1818
total: 2,

src/centralized/convert-balances.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ const convertBalances = (
88
balances: Balances
99
): ExchangeAssetAllocation => {
1010
const baseAssetTotal =
11-
(balances[config.BASEASSET] && balances[config.BASEASSET].total) || '0';
11+
(balances[config.CEX_BASEASSET] && balances[config.CEX_BASEASSET].total) ||
12+
'0';
1213
const baseAssetBalance = new BigNumber(baseAssetTotal);
1314
const quoteAssetTotal =
14-
(balances[config.QUOTEASSET] && balances[config.QUOTEASSET].total) || '0';
15+
(balances[config.CEX_QUOTEASSET] &&
16+
balances[config.CEX_QUOTEASSET].total) ||
17+
'0';
1518
const quoteAssetBalance = new BigNumber(quoteAssetTotal);
1619
return {
1720
baseAssetBalance,

0 commit comments

Comments
 (0)