lamassu-server/lib/exchange.js
Josh Harvey 493e669e6d WIPP
2016-11-27 16:54:08 +02:00

35 lines
1,002 B
JavaScript

const configManager = require('./config-manager')
function fetchExchange (settings, cryptoCode) {
return Promise.resolve()
.then(() => {
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 exchange = require('lamassu-' + plugin)
return {exchange, account}
})
}
function buy (settings, cryptoAtoms, fiatCode, cryptoCode) {
return fetchExchange(settings, cryptoCode)
.then(r => r.exchange.buy(r.account, cryptoAtoms, fiatCode, cryptoCode))
}
function sell (settings, cryptoAtoms, fiatCode, cryptoCode) {
return fetchExchange(settings, cryptoCode)
.then(r => r.exchange.sell(r.account, cryptoAtoms, fiatCode, cryptoCode))
}
function active (settings, cryptoCode) {
return fetchExchange(settings, cryptoCode)
.then(() => true)
.catch(() => false)
}
module.exports = {
buy,
sell,
active
}