This commit is contained in:
Josh Harvey 2016-12-08 17:56:50 +02:00
parent df5d9cac89
commit a375adb8b9
3 changed files with 516 additions and 496 deletions

File diff suppressed because it is too large Load diff

View file

@ -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}

View file

@ -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
} }