67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
import Assets from "./Assets.js";
|
|
import TradingPair from "./TradingPair.js";
|
|
|
|
export default class TradingPairs {
|
|
|
|
static BTCUSDT = new TradingPair(Assets.BTC, Assets.USDT);
|
|
static ETHUSDT = new TradingPair(Assets.ETH, Assets.USDT);
|
|
static GALAUSDT = new TradingPair(Assets.GALA, Assets.USDT);
|
|
static ETHBTC = new TradingPair(Assets.ETH, Assets.BTC);
|
|
|
|
static TRADING_PAIRS = [
|
|
this.BTCUSDT,
|
|
this.ETHUSDT,
|
|
this.GALAUSDT,
|
|
this.ETHBTC,
|
|
];
|
|
|
|
/**
|
|
* @returns {TradingPair[]} all known trading pairs
|
|
*/
|
|
static getAll() {
|
|
return this.TRADING_PAIRS
|
|
}
|
|
|
|
/**
|
|
* @param {string} symbol
|
|
* @returns {TradingPair} tradingpair with given symbol or null if it is unknown
|
|
*/
|
|
static fromString(symbol) {
|
|
if(typeof symbol !== 'string'){
|
|
return null;
|
|
}
|
|
|
|
for (const pair of this.TRADING_PAIRS) {
|
|
if (pair.getKey().toLowerCase() === symbol.toLowerCase()) {
|
|
return pair;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns filtered list of TradingPair objects.
|
|
* All keywords must be included in the TradingPair to be included
|
|
*
|
|
* @param {...string} keywords
|
|
* @returns {TradingPair[]} matching trading pairs
|
|
*/
|
|
static getFiltered(...keywords) {
|
|
const result = [];
|
|
|
|
for (let pair of this.TRADING_PAIRS) {
|
|
let found = true;
|
|
|
|
for (let keyword of keywords) {
|
|
found &= (pair.getFirstCurrency().getSymbol().includes(keyword) || pair.getSecondCurrency().getSymbol().includes(keyword));
|
|
}
|
|
|
|
if (found) {
|
|
result.push(pair);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
} |