mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-10 02:11:57 +00:00
Add pair split function (incl. tests)
This commit is contained in:
parent
0b8e134c15
commit
0f6aec7df8
|
@ -1,2 +1,3 @@
|
|||
export * from './numberformat';
|
||||
export * from './pairFormat';
|
||||
export * from './timeformat';
|
||||
|
|
10
src/shared/formatters/pairFormat.ts
Normal file
10
src/shared/formatters/pairFormat.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Split a trade pair into stake and quote currency
|
||||
* @param pair pair to split, either <stake>/<quote> or <stake>/<quote>:<settle>
|
||||
* @returns {stakeCurrency, quoteCurrency}
|
||||
*/
|
||||
export function splitTradePair(pair: string): { stakeCurrency: string; quoteCurrency: string } {
|
||||
const [stakeCurrency, quoteCurrency] = pair.split('/');
|
||||
const quoteCurrencySplit = quoteCurrency.split(':');
|
||||
return { stakeCurrency, quoteCurrency: quoteCurrencySplit[0] || quoteCurrency };
|
||||
}
|
26
tests/unit/formatPair.spec.ts
Normal file
26
tests/unit/formatPair.spec.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { splitTradePair } from '@/shared/formatters';
|
||||
|
||||
describe('splitTradePair', () => {
|
||||
it('Extracts stake and quote currencies from spot pairs', () => {
|
||||
expect(splitTradePair('BTC/USDT')).toEqual({ stakeCurrency: 'BTC', quoteCurrency: 'USDT' });
|
||||
expect(splitTradePair('USDT/BTC')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'BTC' });
|
||||
expect(splitTradePair('USDT/USDT')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'USDT' });
|
||||
expect(splitTradePair('USDT/USDT')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'USDT' });
|
||||
});
|
||||
it('Extracts stake and quote currencies from spot pairs', () => {
|
||||
expect(splitTradePair('BTC/USDT:USDT')).toEqual({
|
||||
stakeCurrency: 'BTC',
|
||||
quoteCurrency: 'USDT',
|
||||
});
|
||||
expect(splitTradePair('USDT/BTC:BTC')).toEqual({ stakeCurrency: 'USDT', quoteCurrency: 'BTC' });
|
||||
expect(splitTradePair('USDT/USDT:USDT')).toEqual({
|
||||
stakeCurrency: 'USDT',
|
||||
quoteCurrency: 'USDT',
|
||||
});
|
||||
expect(splitTradePair('USDT/USDT:USDT')).toEqual({
|
||||
stakeCurrency: 'USDT',
|
||||
quoteCurrency: 'USDT',
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user