fixes
This commit is contained in:
parent
ee0eecbd30
commit
48a9f9d204
14 changed files with 186 additions and 130 deletions
|
|
@ -1,13 +1,20 @@
|
|||
const configManager = require('./config-manager')
|
||||
const settingsLoader = require('./settings-loader')
|
||||
|
||||
function noExchangeError (cryptoCode) {
|
||||
const err = new Error('No exchange plugin defined for: ' + cryptoCode)
|
||||
err.name = 'NoExchangeError'
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
function fetchExchange (cryptoCode) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
const settings = settingsLoader.settings
|
||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).cryptoServices.wallet
|
||||
if (!plugin) throw new Error('No exchange plugin defined for: ' + cryptoCode)
|
||||
const account = settings.accounts.plugin
|
||||
const settings = settingsLoader.settings()
|
||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).cryptoServices.exchange
|
||||
if (!plugin) throw noExchangeError(cryptoCode)
|
||||
const account = settings.accounts[plugin]
|
||||
const exchange = require('lamassu-' + plugin)
|
||||
|
||||
return {exchange, account}
|
||||
|
|
@ -24,14 +31,7 @@ function sell (cryptoAtoms, fiatCode, cryptoCode) {
|
|||
.then(r => r.exchange.sell(r.account, cryptoAtoms, fiatCode, cryptoCode))
|
||||
}
|
||||
|
||||
function active (cryptoCode) {
|
||||
return fetchExchange(cryptoCode)
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buy,
|
||||
sell,
|
||||
active
|
||||
sell
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue