feat: add USDT as a trading market

This commit is contained in:
Sérgio Salgado 2022-09-01 17:03:28 +01:00 committed by Rafael
parent 653c78313e
commit 7f168859d8
2 changed files with 18 additions and 10 deletions

View file

@ -58,13 +58,16 @@ function calculatePrice (side, amount, orderBook) {
function _getMarkets (exchangeName, availableCryptos) { function _getMarkets (exchangeName, availableCryptos) {
try { try {
const exchange = new ccxt[exchangeName]() const exchange = new ccxt[exchangeName]()
const currencyCodes = _.map(it => it.code, currencies) const cryptosToQuoteAgainst = ['USDT']
const currencyCodes = _.concat(_.map(it => it.code, currencies), cryptosToQuoteAgainst)
return exchange.fetchMarkets() return exchange.fetchMarkets()
.then(_.filter(it => (it.type === 'spot' || it.spot))) .then(_.filter(it => (it.type === 'spot' || it.spot)))
.then(res => .then(res =>
_.reduce((acc, value) => { _.reduce((acc, value) => {
if (_.includes(value.base, availableCryptos) && _.includes(value.quote, currencyCodes)) { if (_.includes(value.base, availableCryptos) && _.includes(value.quote, currencyCodes)) {
if (value.quote === value.base) return acc
if (_.isNil(acc[value.quote])) { if (_.isNil(acc[value.quote])) {
return { ...acc, [value.quote]: [value.base] } return { ...acc, [value.quote]: [value.base] }
} }

View file

@ -27,15 +27,20 @@ const leadingZerosTest = (value, context) => {
const buildCurrencyOptions = markets => { const buildCurrencyOptions = markets => {
return R.map(it => { return R.map(it => {
const unavailableCryptos = R.difference(ALL_CRYPTOS, markets[it]) const unavailableCryptos = R.difference(ALL_CRYPTOS, markets[it])
const unavailableMarkets = R.join( const unavailableCryptosFiltered = R.difference(unavailableCryptos, [it]) // As the markets can have stablecoins to trade against other crypto, filter them out, as there can't be pairs such as USDT/USDT
', ',
R.map(ite => `${ite}/${it}`, unavailableCryptos)
)
const warningLevel = R.isEmpty(unavailableCryptos) const unavailableMarketsStr =
R.length(unavailableCryptosFiltered) > 1
? `${R.join(
', ',
R.slice(0, -1, unavailableCryptosFiltered)
)} and ${R.last(unavailableCryptosFiltered)}`
: unavailableCryptosFiltered[0]
const warningLevel = R.isEmpty(unavailableCryptosFiltered)
? WARNING_LEVELS.CLEAN ? WARNING_LEVELS.CLEAN
: !R.isEmpty(unavailableCryptos) && : !R.isEmpty(unavailableCryptosFiltered) &&
R.length(unavailableCryptos) < R.length(ALL_CRYPTOS) R.length(unavailableCryptosFiltered) < R.length(ALL_CRYPTOS)
? WARNING_LEVELS.PARTIAL ? WARNING_LEVELS.PARTIAL
: WARNING_LEVELS.IMPORTANT : WARNING_LEVELS.IMPORTANT
@ -43,8 +48,8 @@ const buildCurrencyOptions = markets => {
code: R.toUpper(it), code: R.toUpper(it),
display: R.toUpper(it), display: R.toUpper(it),
warning: warningLevel, warning: warningLevel,
warningMessage: !R.isEmpty(unavailableMarkets) warningMessage: !R.isEmpty(unavailableCryptosFiltered)
? `No market pairs available for ${unavailableMarkets}` ? `No market pairs available for ${unavailableMarketsStr}`
: `All market pairs are available` : `All market pairs are available`
} }
}, R.keys(markets)) }, R.keys(markets))