WIPP
This commit is contained in:
parent
c80f92c227
commit
df5d9cac89
3 changed files with 65 additions and 58 deletions
|
|
@ -19,22 +19,14 @@ const email = require('./email')
|
||||||
|
|
||||||
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
||||||
const ALERT_SEND_INTERVAL = T.hour
|
const ALERT_SEND_INTERVAL = T.hour
|
||||||
const INCOMING_TX_INTERVAL = 30 * T.seconds
|
|
||||||
const LIVE_INCOMING_TX_INTERVAL = 5 * T.seconds
|
|
||||||
const STALE_INCOMING_TX_AGE = T.week
|
const STALE_INCOMING_TX_AGE = T.week
|
||||||
const STALE_LIVE_INCOMING_TX_AGE = 10 * T.minutes
|
const STALE_LIVE_INCOMING_TX_AGE = 10 * T.minutes
|
||||||
const UNNOTIFIED_INTERVAL = 10 * T.seconds
|
|
||||||
const MAX_NOTIFY_AGE = 2 * T.days
|
const MAX_NOTIFY_AGE = 2 * T.days
|
||||||
const MIN_NOTIFY_AGE = 5 * T.minutes
|
const MIN_NOTIFY_AGE = 5 * T.minutes
|
||||||
const TRANSACTION_EXPIRATION = 2 * T.days
|
const TRANSACTION_EXPIRATION = 2 * T.days
|
||||||
const SWEEP_LIVE_HD_INTERVAL = T.minute
|
|
||||||
const SWEEP_OLD_HD_INTERVAL = 2 * T.minutes
|
|
||||||
const TRADE_INTERVAL = 10 * T.seconds
|
|
||||||
const TRADE_TTL = 2 * T.minutes
|
const TRADE_TTL = 2 * T.minutes
|
||||||
const STALE_TICKER = 3 * T.minutes
|
const STALE_TICKER = 3 * T.minutes
|
||||||
const STALE_BALANCE = 3 * T.minutes
|
const STALE_BALANCE = 3 * T.minutes
|
||||||
const PONG_INTERVAL = 10 * T.seconds
|
|
||||||
const PONG_CLEAR_INTERVAL = 1 * T.day
|
|
||||||
const PONG_TTL = '1 week'
|
const PONG_TTL = '1 week'
|
||||||
const tradesQueues = {}
|
const tradesQueues = {}
|
||||||
|
|
||||||
|
|
@ -317,29 +309,6 @@ function pongClear () {
|
||||||
.catch(logger.error)
|
.catch(logger.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Polling livecycle
|
|
||||||
*/
|
|
||||||
function startPolling () {
|
|
||||||
executeTrades()
|
|
||||||
pong()
|
|
||||||
pongClear()
|
|
||||||
|
|
||||||
setInterval(executeTrades, TRADE_INTERVAL)
|
|
||||||
setInterval(monitorLiveIncoming, LIVE_INCOMING_TX_INTERVAL)
|
|
||||||
setInterval(monitorIncoming, INCOMING_TX_INTERVAL)
|
|
||||||
setInterval(monitorUnnotified, UNNOTIFIED_INTERVAL)
|
|
||||||
setInterval(sweepLiveHD, SWEEP_LIVE_HD_INTERVAL)
|
|
||||||
setInterval(sweepOldHD, SWEEP_OLD_HD_INTERVAL)
|
|
||||||
setInterval(pong, PONG_INTERVAL)
|
|
||||||
setInterval(pongClear, PONG_CLEAR_INTERVAL)
|
|
||||||
monitorLiveIncoming()
|
|
||||||
monitorIncoming()
|
|
||||||
monitorUnnotified()
|
|
||||||
sweepLiveHD()
|
|
||||||
sweepOldHD()
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Trader functions
|
* Trader functions
|
||||||
*/
|
*/
|
||||||
|
|
@ -356,9 +325,9 @@ function consolidateTrades (cryptoCode, fiatCode) {
|
||||||
const t1 = Date.now()
|
const t1 = Date.now()
|
||||||
|
|
||||||
const filtered = marketTradesQueues
|
const filtered = marketTradesQueues
|
||||||
.filter(trade => {
|
.filter(tradeEntry => {
|
||||||
console.log('DEBUG33: %j, %s, %s, %s', trade, t1, trade.timestamp, TRADE_TTL)
|
console.log('DEBUG33: %j, %s, %s, %s', tradeEntry, t1, tradeEntry.timestamp, TRADE_TTL)
|
||||||
return t1 - trade.timestamp < TRADE_TTL
|
return t1 - tradeEntry.timestamp < TRADE_TTL
|
||||||
})
|
})
|
||||||
|
|
||||||
const filteredCount = marketTradesQueues.length - filtered.length
|
const filteredCount = marketTradesQueues.length - filtered.length
|
||||||
|
|
@ -416,20 +385,20 @@ function executeTradesForMarket (settings, fiatCode, cryptoCode) {
|
||||||
const market = [fiatCode, cryptoCode].join('')
|
const market = [fiatCode, cryptoCode].join('')
|
||||||
logger.debug('[%s] checking for trades', market)
|
logger.debug('[%s] checking for trades', market)
|
||||||
|
|
||||||
const trade = consolidateTrades(cryptoCode, fiatCode)
|
const tradeEntry = consolidateTrades(cryptoCode, fiatCode)
|
||||||
if (trade === null) return logger.debug('[%s] no trades', market)
|
if (tradeEntry === null) return logger.debug('[%s] no trades', market)
|
||||||
|
|
||||||
if (trade.cryptoAtoms.eq(0)) {
|
if (tradeEntry.cryptoAtoms.eq(0)) {
|
||||||
logger.debug('[%s] rejecting 0 trade', market)
|
logger.debug('[%s] rejecting 0 trade', market)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('[%s] making a trade: %d', market, trade.cryptoAtoms.toString())
|
logger.debug('[%s] making a trade: %d', market, tradeEntry.cryptoAtoms.toString())
|
||||||
|
|
||||||
return exchange.buy(trade.cryptoAtoms, trade.fiatCode, trade.cryptoCode)
|
return exchange.buy(tradeEntry.cryptoAtoms, tradeEntry.fiatCode, tradeEntry.cryptoCode)
|
||||||
.then(() => logger.debug('[%s] Successful trade.', market))
|
.then(() => logger.debug('[%s] Successful trade.', market))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
tradesQueues[market].push(trade)
|
tradesQueues[market].push(tradeEntry)
|
||||||
if (err.name === 'NoExchangeError') return logger.debug(err.message)
|
if (err.name === 'NoExchangeError') return logger.debug(err.message)
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
})
|
})
|
||||||
|
|
@ -604,8 +573,15 @@ module.exports = {
|
||||||
sendCoins,
|
sendCoins,
|
||||||
cashOut,
|
cashOut,
|
||||||
dispenseAck,
|
dispenseAck,
|
||||||
startPolling,
|
|
||||||
startCheckingNotification,
|
startCheckingNotification,
|
||||||
getPhoneCode,
|
getPhoneCode,
|
||||||
fetchPhoneTx
|
fetchPhoneTx,
|
||||||
|
executeTrades,
|
||||||
|
pong,
|
||||||
|
pongClear,
|
||||||
|
monitorLiveIncoming,
|
||||||
|
monitorIncoming,
|
||||||
|
monitorUnnotified,
|
||||||
|
sweepLiveHD,
|
||||||
|
sweepOldHD
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
lib/poller.js
Normal file
35
lib/poller.js
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
const plugins = require('./plugins')
|
||||||
|
const T = require('./time')
|
||||||
|
|
||||||
|
const INCOMING_TX_INTERVAL = 30 * T.seconds
|
||||||
|
const LIVE_INCOMING_TX_INTERVAL = 5 * T.seconds
|
||||||
|
const UNNOTIFIED_INTERVAL = 10 * T.seconds
|
||||||
|
const SWEEP_LIVE_HD_INTERVAL = T.minute
|
||||||
|
const SWEEP_OLD_HD_INTERVAL = 2 * T.minutes
|
||||||
|
const TRADE_INTERVAL = 10 * T.seconds
|
||||||
|
const PONG_INTERVAL = 10 * T.seconds
|
||||||
|
const PONG_CLEAR_INTERVAL = 1 * T.day
|
||||||
|
|
||||||
|
function start () {
|
||||||
|
let pi = plugins
|
||||||
|
|
||||||
|
pi.executeTrades()
|
||||||
|
pi.pong()
|
||||||
|
pi.pongClear()
|
||||||
|
pi.monitorLiveIncoming()
|
||||||
|
pi.monitorIncoming()
|
||||||
|
pi.monitorUnnotified()
|
||||||
|
pi.sweepLiveHD()
|
||||||
|
pi.sweepOldHD()
|
||||||
|
|
||||||
|
setInterval(() => pi.executeTrades(), TRADE_INTERVAL)
|
||||||
|
setInterval(() => pi.monitorLiveIncoming(), LIVE_INCOMING_TX_INTERVAL)
|
||||||
|
setInterval(() => pi.monitorIncoming(), INCOMING_TX_INTERVAL)
|
||||||
|
setInterval(() => pi.monitorUnnotified(), UNNOTIFIED_INTERVAL)
|
||||||
|
setInterval(() => pi.sweepLiveHD(), SWEEP_LIVE_HD_INTERVAL)
|
||||||
|
setInterval(() => pi.sweepOldHD(), SWEEP_OLD_HD_INTERVAL)
|
||||||
|
setInterval(() => pi.pong(), PONG_INTERVAL)
|
||||||
|
setInterval(() => pi.pongClear(), PONG_CLEAR_INTERVAL)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {start}
|
||||||
|
|
@ -4,24 +4,20 @@ const db = require('./db')
|
||||||
|
|
||||||
let settingsCache
|
let settingsCache
|
||||||
|
|
||||||
function load () {
|
function load (versionId) {
|
||||||
return Promise.all([loadConfig(), loadAccounts()])
|
return Promise.all([loadConfig(versionId), loadAccounts()])
|
||||||
.then(function ([config, accounts]) {
|
.then(([config, accounts]) => ({
|
||||||
settingsCache = {
|
config,
|
||||||
config,
|
accounts
|
||||||
accounts
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
return settingsCache
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
settingsCache = undefined
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig () {
|
function loadConfig (versionId) {
|
||||||
return db.oneOrNone('select data from user_config where type=$1', 'config')
|
const sql = `select data
|
||||||
|
from user_config
|
||||||
|
where versionId=$1 and type=$2`
|
||||||
|
|
||||||
|
return db.oneOrNone(sql, [versionId, 'config'])
|
||||||
.then(row => row ? row.data.config : [])
|
.then(row => row ? row.data.config : [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue