don't trade if no exchange

This commit is contained in:
Josh Harvey 2016-12-08 00:13:59 +02:00
parent e6a7a601c9
commit c80f92c227
3 changed files with 20 additions and 5 deletions

View file

@ -8,11 +8,16 @@ function noExchangeError (cryptoCode) {
return err
}
function lookupExchange (cryptoCode) {
const settings = settingsLoader.settings()
return configManager.cryptoScoped(cryptoCode, settings.config).exchange
}
function fetchExchange (cryptoCode) {
return Promise.resolve()
.then(() => {
const settings = settingsLoader.settings()
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).exchange
const plugin = lookupExchange(cryptoCode)
if (!plugin) throw noExchangeError(cryptoCode)
const account = settings.accounts[plugin]
const exchange = require('lamassu-' + plugin)
@ -31,7 +36,12 @@ function sell (cryptoAtoms, fiatCode, cryptoCode) {
.then(r => r.exchange.sell(r.account, cryptoAtoms, fiatCode, cryptoCode))
}
function active (fiatCode, cryptoCode) {
return !!lookupExchange(cryptoCode)
}
module.exports = {
buy,
sell
sell,
active
}

View file

@ -162,6 +162,8 @@ function trade (deviceId, rawTrade) {
.then(() => {
const market = [fiatCode, cryptoCode].join('')
if (!exchange.active(cryptoCode)) return
logger.debug('[%s] Pushing trade: %d', market, cryptoAtoms)
if (!tradesQueues[market]) tradesQueues[market] = []
tradesQueues[market].push({
@ -409,6 +411,8 @@ function executeTrades () {
}
function executeTradesForMarket (settings, fiatCode, cryptoCode) {
if (!exchange.active(cryptoCode)) return
const market = [fiatCode, cryptoCode].join('')
logger.debug('[%s] checking for trades', market)
@ -489,9 +493,7 @@ function checkNotification () {
.then(results => {
if (results && results.length > 0) logger.debug('Successfully sent alerts')
})
.catch(err => {
logger.error(err)
})
.catch(logger.error)
}
function checkDeviceBalances (deviceId) {

View file

@ -9,6 +9,9 @@ function getRates (fiatCode, cryptoCode) {
const settings = settingsLoader.settings()
const config = settings.config
const plugin = configManager.cryptoScoped(cryptoCode, config).ticker
if (!plugin) throw new Error('No ticker plugin defined')
const account = settings.accounts[plugin]
const ticker = require('lamassu-' + plugin)