mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-10 10:21:55 +00:00
Improve response naming
This commit is contained in:
parent
41f464e4ca
commit
0d0fc2a4d8
|
@ -1,11 +1,15 @@
|
||||||
/**
|
/**
|
||||||
* Split a trade pair into stake and quote currency
|
* Split a trade pair into stake and quote currency
|
||||||
* @param pair pair to split, either <stake>/<quote> or <stake>/<quote>:<settle>
|
* @param pair pair to split, either <stake>/<quote> or <stake>/<quote>:<settle>
|
||||||
* @returns {stakeCurrency, quoteCurrency}
|
* @returns {baseCurrency, quoteCurrency}
|
||||||
*/
|
*/
|
||||||
export function splitTradePair(pair: string): { stakeCurrency: string; quoteCurrency: string } {
|
export function splitTradePair(pair: string): { baseCurrency: string; quoteCurrency: string } {
|
||||||
if (!pair) return { stakeCurrency: '', quoteCurrency: '' };
|
if (!pair) return { baseCurrency: '', quoteCurrency: '' };
|
||||||
const [stakeCurrency, quoteCurrency] = pair.split('/');
|
const [baseCurrency, quoteCurrency] = pair.split('/');
|
||||||
|
if (quoteCurrency !== undefined) {
|
||||||
const quoteCurrencySplit = quoteCurrency.split(':');
|
const quoteCurrencySplit = quoteCurrency.split(':');
|
||||||
return { stakeCurrency, quoteCurrency: quoteCurrencySplit[0] || quoteCurrency };
|
return { baseCurrency: baseCurrency, quoteCurrency: quoteCurrencySplit[0] || quoteCurrency };
|
||||||
|
}
|
||||||
|
// In case only one asset is passed in (e.g. USDT) we invert the values, assuming this is the quote currency.
|
||||||
|
return { baseCurrency: quoteCurrency ?? '', quoteCurrency: baseCurrency ?? '' };
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,27 +3,28 @@ import { splitTradePair } from '@/shared/formatters';
|
||||||
|
|
||||||
describe('splitTradePair', () => {
|
describe('splitTradePair', () => {
|
||||||
it('Extracts stake and quote currencies from spot pairs', () => {
|
it('Extracts stake and quote currencies from spot pairs', () => {
|
||||||
expect(splitTradePair('BTC/USDT')).toEqual({ stakeCurrency: 'BTC', quoteCurrency: 'USDT' });
|
expect(splitTradePair('BTC/USDT')).toEqual({ baseCurrency: 'BTC', quoteCurrency: 'USDT' });
|
||||||
expect(splitTradePair('USDT/BTC')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'BTC' });
|
expect(splitTradePair('USDT/BTC')).toEqual({ baseCurrency: 'USDT', quoteCurrency: 'BTC' });
|
||||||
expect(splitTradePair('USDT/USDT')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'USDT' });
|
expect(splitTradePair('USDT/USDT')).toEqual({ baseCurrency: 'USDT', quoteCurrency: 'USDT' });
|
||||||
expect(splitTradePair('USDT/USDT')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'USDT' });
|
expect(splitTradePair('USDT/USDT')).toEqual({ baseCurrency: 'USDT', quoteCurrency: 'USDT' });
|
||||||
});
|
});
|
||||||
it('Extracts stake and quote currencies from spot pairs', () => {
|
it('Extracts stake and quote currencies from spot pairs', () => {
|
||||||
expect(splitTradePair('BTC/USDT:USDT')).toEqual({
|
expect(splitTradePair('BTC/USDT:USDT')).toEqual({
|
||||||
stakeCurrency: 'BTC',
|
baseCurrency: 'BTC',
|
||||||
quoteCurrency: 'USDT',
|
quoteCurrency: 'USDT',
|
||||||
});
|
});
|
||||||
expect(splitTradePair('USDT/BTC:BTC')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'BTC' });
|
expect(splitTradePair('USDT/BTC:BTC')).toEqual({ baseCurrency: 'USDT', quoteCurrency: 'BTC' });
|
||||||
expect(splitTradePair('USDT/USDT:USDT')).toEqual({
|
expect(splitTradePair('USDT/USDT:USDT')).toEqual({
|
||||||
stakeCurrency: 'USDT',
|
baseCurrency: 'USDT',
|
||||||
quoteCurrency: 'USDT',
|
quoteCurrency: 'USDT',
|
||||||
});
|
});
|
||||||
expect(splitTradePair('USDT/USDT:USDT')).toEqual({
|
expect(splitTradePair('USDT/USDT:USDT')).toEqual({
|
||||||
stakeCurrency: 'USDT',
|
baseCurrency: 'USDT',
|
||||||
quoteCurrency: 'USDT',
|
quoteCurrency: 'USDT',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('Does not fail on empty input', () => {
|
it('Does not fail on empty input', () => {
|
||||||
expect(splitTradePair('')).toEqual({ stakeCurrency: '', quoteCurrency: '' });
|
expect(splitTradePair('')).toEqual({ baseCurrency: '', quoteCurrency: '' });
|
||||||
|
expect(splitTradePair('USDT')).toEqual({ baseCurrency: '', quoteCurrency: 'USDT' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user