WIPP
This commit is contained in:
parent
7e5515a873
commit
b16d11045c
10 changed files with 368 additions and 550 deletions
36
lib/exchange.js
Normal file
36
lib/exchange.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const settingsLoader = require('./settings-loader')
|
||||
const configManager = require('./config-manager')
|
||||
|
||||
function fetchExchange (cryptoCode) {
|
||||
return settingsLoader.settings()
|
||||
.then(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 exchange = require('lamassu-' + plugin)
|
||||
|
||||
return {exchange, account}
|
||||
})
|
||||
}
|
||||
|
||||
function buy (cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return fetchExchange(cryptoCode)
|
||||
.then(r => r.exchange.buy(r.account, cryptoAtoms, fiatCode, cryptoCode))
|
||||
}
|
||||
|
||||
function sell (cryptoAtoms, fiatCode, cryptoCode) {
|
||||
return fetchExchange(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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue