WIP
This commit is contained in:
parent
259b527214
commit
0a2d2f658e
6 changed files with 90 additions and 61 deletions
|
|
@ -32,8 +32,6 @@ const TRADE_INTERVAL = T.minute
|
|||
const TRADE_TTL = 5 * T.minutes
|
||||
const LOW_BALANCE_MARGIN_DEFAULT = 1.05
|
||||
|
||||
let cryptoCodes = null
|
||||
|
||||
const tickerPlugins = {}
|
||||
const traderPlugins = {}
|
||||
const walletPlugins = {}
|
||||
|
|
@ -167,13 +165,22 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
|
|||
|
||||
// Note: this whole function gets called every time there's a config update
|
||||
exports.configure = function configure (config) {
|
||||
console.log('DEBUG40')
|
||||
console.log('DEBUG4: %j', config)
|
||||
|
||||
cachedConfig = config
|
||||
|
||||
console.log('DEBUG41')
|
||||
|
||||
const accounts = configManager.loadAccounts()
|
||||
|
||||
console.log('DEBUG42')
|
||||
deviceCurrency = config.fiat.fiatCurrency
|
||||
cryptoCodes = config.crypto.cryptoCurrencies
|
||||
// cryptoCodes = config.crypto.cryptoCurrencies TODO: add to admin
|
||||
console.log('DEBUG43')
|
||||
const cryptoCodes = getCryptoCodes()
|
||||
|
||||
console.log('DEBUG30')
|
||||
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
const cryptoScopedConfig = config.cryptoScoped(cryptoCode, cachedConfig)
|
||||
|
|
@ -192,6 +199,8 @@ exports.configure = function configure (config) {
|
|||
}
|
||||
)
|
||||
|
||||
console.log('DEBUG31')
|
||||
|
||||
// Give each crypto a different derived seed so as not to allow any
|
||||
// plugin to spend another plugin's funds
|
||||
const cryptoSeed = hkdf.derive(cryptoCode, 32)
|
||||
|
|
@ -226,6 +235,8 @@ exports.configure = function configure (config) {
|
|||
)
|
||||
})
|
||||
|
||||
console.log('DEBUG32')
|
||||
|
||||
const unscopedCfg = config.unscoped(cachedConfig)
|
||||
|
||||
// ID VERIFIER [optional] configure (or load)
|
||||
|
|
@ -252,6 +263,8 @@ exports.configure = function configure (config) {
|
|||
unscopedCfg,
|
||||
accounts
|
||||
)
|
||||
|
||||
console.log('DEBUG33')
|
||||
}
|
||||
|
||||
exports.getConfig = function getConfig (machineId) {
|
||||
|
|
@ -418,7 +431,7 @@ exports.fiatBalance = function fiatBalance (cryptoCode) {
|
|||
const deviceRate = exports.getDeviceRate(cryptoCode)
|
||||
if (!deviceRate) return null
|
||||
const rawRate = deviceRate.rates.ask
|
||||
const commission = cachedConfig.commissions.cashInCommission
|
||||
const commission = new BigNumber(cachedConfig.commissions.cashInCommission).div(100)
|
||||
const lastBalanceRec = lastBalances[cryptoCode]
|
||||
if (!lastBalanceRec) return null
|
||||
const lastBalance = lastBalanceRec.balance
|
||||
|
|
@ -493,6 +506,7 @@ function monitorUnnotified () {
|
|||
exports.startPolling = function startPolling () {
|
||||
executeTrades()
|
||||
|
||||
const cryptoCodes = getCryptoCodes()
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
setInterval(async.apply(pollBalance, cryptoCode), POLLING_RATE)
|
||||
setInterval(async.apply(pollRate, cryptoCode), POLLING_RATE)
|
||||
|
|
@ -686,9 +700,11 @@ exports.verifyTx = function verifyTx (data, cb) {
|
|||
idVerifierPlugin.verifyTransaction(data, cb)
|
||||
}
|
||||
|
||||
exports.getcryptoCodes = function getcryptoCodes () {
|
||||
return cryptoCodes
|
||||
function getCryptoCodes () {
|
||||
console.log('DEBUG17 TODO: generalize')
|
||||
return ['BTC', 'ETC']
|
||||
}
|
||||
exports.getCryptoCodes = getCryptoCodes
|
||||
|
||||
function sendMessage (rec) {
|
||||
const pluginPromises = []
|
||||
|
|
@ -760,7 +776,7 @@ function checkNotification () {
|
|||
}
|
||||
|
||||
function checkBalances () {
|
||||
const cryptoCodes = exports.getcryptoCodes()
|
||||
const cryptoCodes = exports.getCryptoCodes()
|
||||
|
||||
const balances = []
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue