don't trade if no exchange
This commit is contained in:
parent
e6a7a601c9
commit
c80f92c227
3 changed files with 20 additions and 5 deletions
|
|
@ -8,11 +8,16 @@ function noExchangeError (cryptoCode) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lookupExchange (cryptoCode) {
|
||||||
|
const settings = settingsLoader.settings()
|
||||||
|
return configManager.cryptoScoped(cryptoCode, settings.config).exchange
|
||||||
|
}
|
||||||
|
|
||||||
function fetchExchange (cryptoCode) {
|
function fetchExchange (cryptoCode) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const settings = settingsLoader.settings()
|
const settings = settingsLoader.settings()
|
||||||
const plugin = configManager.cryptoScoped(cryptoCode, settings.config).exchange
|
const plugin = lookupExchange(cryptoCode)
|
||||||
if (!plugin) throw noExchangeError(cryptoCode)
|
if (!plugin) throw noExchangeError(cryptoCode)
|
||||||
const account = settings.accounts[plugin]
|
const account = settings.accounts[plugin]
|
||||||
const exchange = require('lamassu-' + 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))
|
.then(r => r.exchange.sell(r.account, cryptoAtoms, fiatCode, cryptoCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function active (fiatCode, cryptoCode) {
|
||||||
|
return !!lookupExchange(cryptoCode)
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
buy,
|
buy,
|
||||||
sell
|
sell,
|
||||||
|
active
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,8 @@ function trade (deviceId, rawTrade) {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const market = [fiatCode, cryptoCode].join('')
|
const market = [fiatCode, cryptoCode].join('')
|
||||||
|
|
||||||
|
if (!exchange.active(cryptoCode)) return
|
||||||
|
|
||||||
logger.debug('[%s] Pushing trade: %d', market, cryptoAtoms)
|
logger.debug('[%s] Pushing trade: %d', market, cryptoAtoms)
|
||||||
if (!tradesQueues[market]) tradesQueues[market] = []
|
if (!tradesQueues[market]) tradesQueues[market] = []
|
||||||
tradesQueues[market].push({
|
tradesQueues[market].push({
|
||||||
|
|
@ -409,6 +411,8 @@ function executeTrades () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeTradesForMarket (settings, fiatCode, cryptoCode) {
|
function executeTradesForMarket (settings, fiatCode, cryptoCode) {
|
||||||
|
if (!exchange.active(cryptoCode)) return
|
||||||
|
|
||||||
const market = [fiatCode, cryptoCode].join('')
|
const market = [fiatCode, cryptoCode].join('')
|
||||||
logger.debug('[%s] checking for trades', market)
|
logger.debug('[%s] checking for trades', market)
|
||||||
|
|
||||||
|
|
@ -489,9 +493,7 @@ function checkNotification () {
|
||||||
.then(results => {
|
.then(results => {
|
||||||
if (results && results.length > 0) logger.debug('Successfully sent alerts')
|
if (results && results.length > 0) logger.debug('Successfully sent alerts')
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(logger.error)
|
||||||
logger.error(err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkDeviceBalances (deviceId) {
|
function checkDeviceBalances (deviceId) {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ function getRates (fiatCode, cryptoCode) {
|
||||||
const settings = settingsLoader.settings()
|
const settings = settingsLoader.settings()
|
||||||
const config = settings.config
|
const config = settings.config
|
||||||
const plugin = configManager.cryptoScoped(cryptoCode, config).ticker
|
const plugin = configManager.cryptoScoped(cryptoCode, config).ticker
|
||||||
|
|
||||||
|
if (!plugin) throw new Error('No ticker plugin defined')
|
||||||
|
|
||||||
const account = settings.accounts[plugin]
|
const account = settings.accounts[plugin]
|
||||||
const ticker = require('lamassu-' + plugin)
|
const ticker = require('lamassu-' + plugin)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue