This commit is contained in:
Josh Harvey 2016-11-27 18:12:49 +02:00
parent 3a99b7a6bc
commit 00d986376e
8 changed files with 149 additions and 155 deletions

View file

@ -1,8 +1,10 @@
const configManager = require('./config-manager')
const settingsLoader = require('./settings-loader')
function fetchExchange (settings, cryptoCode) {
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
@ -12,18 +14,18 @@ function fetchExchange (settings, cryptoCode) {
})
}
function buy (settings, cryptoAtoms, fiatCode, cryptoCode) {
return fetchExchange(settings, cryptoCode)
function buy (cryptoAtoms, fiatCode, cryptoCode) {
return fetchExchange(cryptoCode)
.then(r => r.exchange.buy(r.account, cryptoAtoms, fiatCode, cryptoCode))
}
function sell (settings, cryptoAtoms, fiatCode, cryptoCode) {
return fetchExchange(settings, cryptoCode)
function sell (cryptoAtoms, fiatCode, cryptoCode) {
return fetchExchange(cryptoCode)
.then(r => r.exchange.sell(r.account, cryptoAtoms, fiatCode, cryptoCode))
}
function active (settings, cryptoCode) {
return fetchExchange(settings, cryptoCode)
function active (cryptoCode) {
return fetchExchange(cryptoCode)
.then(() => true)
.catch(() => false)
}