Restructured long lines of code

This commit is contained in:
José Oliveira 2021-01-18 21:20:51 +00:00 committed by Josh Harvey
parent f572fc0a7e
commit 54a231ab60

View file

@ -11,7 +11,8 @@ function trade (side, account, cryptoAtoms, fiatCode, cryptoCode, exchangeName)
if (exchangeName === 'itbit') {
return exchange.fetchOrderBook(symbol)
.then(orderBook => {
return exchange.createOrder(symbol, 'limit', side, amount, calculatePrice(side, amount, orderBook), { walletId: account.walletId })
const price = calculatePrice(side, amount, orderBook)
return exchange.createOrder(symbol, 'limit', side, amount, price, { walletId: account.walletId })
})
}
return exchange.createOrder(symbol, 'market', side, amount)
@ -28,17 +29,32 @@ function setUpExchange (account, exchangeName) {
switch (exchangeName) {
case 'itbit':
if (!account.clientKey || !account.clientSecret || !account.userId || !account.walletId)
if (!account.clientKey || !account.clientSecret || !account.userId || !account.walletId) {
throw new Error('Must provide user ID, wallet ID, client key, and client secret')
return new ccxt[exchangeName](_.mapKeys((key) => { return key === 'clientKey' ? 'apiKey' : key === 'clientSecret' ? 'secret' : key === 'userId' ? 'uid' : key }, _.omit(['walletId'], account)))
}
return new ccxt[exchangeName](_.mapKeys((key) => {
if (key === 'clientKey') return 'apiKey'
if (key === 'clientSecret') return 'secret'
if (key === 'userId') return 'uid'
return key
}, _.omit(['walletId'], account)))
case 'kraken':
if (!account.apiKey || !account.privateKey)
if (!account.apiKey || !account.privateKey) {
throw new Error('Must provide key and private key')
return new ccxt[exchangeName](_.mapKeys((key) => { return key === 'privateKey' ? 'secret' : key }, account))
}
return new ccxt[exchangeName](_.mapKeys((key) => {
if (key === 'privateKey') return 'secret'
return key
}, account))
case 'bitstamp':
if (!account.key || !account.secret || !account.clientId)
if (!account.key || !account.secret || !account.clientId) {
throw new Error('Must provide key, secret and client ID')
return new ccxt[exchangeName](_.mapKeys((key) => { return key === 'key' ? 'apiKey' : key === 'clientId' ? 'uid' : key }, account))
}
return new ccxt[exchangeName](_.mapKeys((key) => {
if (key === 'key') return 'apiKey'
if (key === 'clientId') return 'uid'
return key
}, account))
default:
throw new Error(`Exchange ${exchangeName} not supported.`)
}