WIPP
This commit is contained in:
parent
df5d9cac89
commit
a375adb8b9
3 changed files with 516 additions and 496 deletions
|
|
@ -10,7 +10,6 @@ const logger = require('./logger')
|
||||||
const notifier = require('./notifier')
|
const notifier = require('./notifier')
|
||||||
const T = require('./time')
|
const T = require('./time')
|
||||||
const configManager = require('./config-manager')
|
const configManager = require('./config-manager')
|
||||||
const settingsLoader = require('./settings-loader')
|
|
||||||
const ticker = require('./ticker')
|
const ticker = require('./ticker')
|
||||||
const wallet = require('./wallet')
|
const wallet = require('./wallet')
|
||||||
const exchange = require('./exchange')
|
const exchange = require('./exchange')
|
||||||
|
|
@ -38,8 +37,8 @@ const coins = {
|
||||||
let alertFingerprint = null
|
let alertFingerprint = null
|
||||||
let lastAlertTime = null
|
let lastAlertTime = null
|
||||||
|
|
||||||
|
function plugins (settings) {
|
||||||
function buildRates (deviceId, tickers) {
|
function buildRates (deviceId, tickers) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
const cashOut = config.cashOutEnabled
|
const cashOut = config.cashOutEnabled
|
||||||
|
|
@ -63,7 +62,6 @@ function buildRates (deviceId, tickers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildBalances (deviceId, balanceRecs) {
|
function buildBalances (deviceId, balanceRecs) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
|
|
||||||
|
|
@ -97,7 +95,6 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function pollQueries (deviceTime, deviceId, deviceRec) {
|
function pollQueries (deviceTime, deviceId, deviceRec) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const fiatCode = config.fiatCurrency
|
const fiatCode = config.fiatCurrency
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
|
|
@ -219,7 +216,6 @@ function cashOut (deviceId, tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispenseAck (deviceId, tx) {
|
function dispenseAck (deviceId, tx) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cartridges = [ config.topCashOutDenomination,
|
const cartridges = [ config.topCashOutDenomination,
|
||||||
config.bottomCashOutDenomination ]
|
config.bottomCashOutDenomination ]
|
||||||
|
|
@ -228,7 +224,6 @@ function dispenseAck (deviceId, tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fiatBalance (fiatCode, cryptoCode, deviceId) {
|
function fiatBalance (fiatCode, cryptoCode, deviceId) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
const config = configManager.scoped(cryptoCode, deviceId, settings.config)
|
||||||
|
|
||||||
return Promise.all([ticker.getRates(fiatCode, cryptoCode), wallet.balance(cryptoCode)])
|
return Promise.all([ticker.getRates(fiatCode, cryptoCode), wallet.balance(cryptoCode)])
|
||||||
|
|
@ -358,8 +353,6 @@ function consolidateTrades (cryptoCode, fiatCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeTrades () {
|
function executeTrades () {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
|
|
||||||
return dbm.devices()
|
return dbm.devices()
|
||||||
.then(devices => {
|
.then(devices => {
|
||||||
const deviceIds = devices.map(device => device.device_id)
|
const deviceIds = devices.map(device => device.device_id)
|
||||||
|
|
@ -405,7 +398,6 @@ function executeTradesForMarket (settings, fiatCode, cryptoCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMessage (rec) {
|
function sendMessage (rec) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.unscoped(settings.config)
|
const config = configManager.unscoped(settings.config)
|
||||||
|
|
||||||
let promises = []
|
let promises = []
|
||||||
|
|
@ -466,7 +458,6 @@ function checkNotification () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkDeviceBalances (deviceId) {
|
function checkDeviceBalances (deviceId) {
|
||||||
const settings = settingsLoader.settings()
|
|
||||||
const config = configManager.machineScoped(deviceId, settings.config)
|
const config = configManager.machineScoped(deviceId, settings.config)
|
||||||
const cryptoCodes = config.cryptoCurrencies
|
const cryptoCodes = config.cryptoCurrencies
|
||||||
const fiatCode = config.fiatCurrency
|
const fiatCode = config.fiatCurrency
|
||||||
|
|
@ -566,7 +557,7 @@ function sweepOldHD () {
|
||||||
.catch(err => logger.error(err))
|
.catch(err => logger.error(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
return {
|
||||||
pollQueries,
|
pollQueries,
|
||||||
trade,
|
trade,
|
||||||
stateChange,
|
stateChange,
|
||||||
|
|
@ -585,3 +576,6 @@ module.exports = {
|
||||||
sweepLiveHD,
|
sweepLiveHD,
|
||||||
sweepOldHD
|
sweepOldHD
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = plugins
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,14 @@ const TRADE_INTERVAL = 10 * T.seconds
|
||||||
const PONG_INTERVAL = 10 * T.seconds
|
const PONG_INTERVAL = 10 * T.seconds
|
||||||
const PONG_CLEAR_INTERVAL = 1 * T.day
|
const PONG_CLEAR_INTERVAL = 1 * T.day
|
||||||
|
|
||||||
function start () {
|
let pi
|
||||||
let pi = plugins
|
|
||||||
|
function reload (settings) {
|
||||||
|
pi = plugins(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
function start (settings) {
|
||||||
|
reload(settings)
|
||||||
|
|
||||||
pi.executeTrades()
|
pi.executeTrades()
|
||||||
pi.pong()
|
pi.pong()
|
||||||
|
|
@ -32,4 +38,4 @@ function start () {
|
||||||
setInterval(() => pi.pongClear(), PONG_CLEAR_INTERVAL)
|
setInterval(() => pi.pongClear(), PONG_CLEAR_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {start}
|
module.exports = {start, reload}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,14 @@ function load (versionId) {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadLatest (versionId) {
|
||||||
|
return Promise.all([loadLatestConfig(), loadAccounts()])
|
||||||
|
.then(([config, accounts]) => ({
|
||||||
|
config,
|
||||||
|
accounts
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
function loadConfig (versionId) {
|
function loadConfig (versionId) {
|
||||||
const sql = `select data
|
const sql = `select data
|
||||||
from user_config
|
from user_config
|
||||||
|
|
@ -21,6 +29,17 @@ function loadConfig (versionId) {
|
||||||
.then(row => row ? row.data.config : [])
|
.then(row => row ? row.data.config : [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadLatestConfig () {
|
||||||
|
const sql = `select data
|
||||||
|
from user_config
|
||||||
|
where type=$1
|
||||||
|
order by versionId desc
|
||||||
|
limit 1`
|
||||||
|
|
||||||
|
return db.oneOrNone(sql, ['config'])
|
||||||
|
.then(row => row ? row.data.config : [])
|
||||||
|
}
|
||||||
|
|
||||||
function loadAccounts () {
|
function loadAccounts () {
|
||||||
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
|
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
|
||||||
const toPairs = r => [r.code, toFields(r.fields)]
|
const toPairs = r => [r.code, toFields(r.fields)]
|
||||||
|
|
@ -45,5 +64,6 @@ module.exports = {
|
||||||
settings,
|
settings,
|
||||||
loadConfig,
|
loadConfig,
|
||||||
load,
|
load,
|
||||||
|
loadLatest,
|
||||||
save
|
save
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue