WIP
This commit is contained in:
parent
cee4486cbd
commit
7e5515a873
4 changed files with 5 additions and 43 deletions
|
|
@ -3,7 +3,6 @@
|
|||
const fs = require('fs')
|
||||
const uuid = require('uuid')
|
||||
const R = require('ramda')
|
||||
const async = require('async')
|
||||
const HKDF = require('node-hkdf-sync')
|
||||
const BigNumber = require('bignumber.js')
|
||||
|
||||
|
|
@ -170,7 +169,7 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
|
|||
exports.configure = function configure (config) {
|
||||
cachedConfig = config
|
||||
|
||||
const cryptoCodes = getCryptoCodes()
|
||||
const cryptoCodes = getAllCryptoCodes()
|
||||
|
||||
return configManager.loadAccounts()
|
||||
.then(accounts => {
|
||||
|
|
@ -187,7 +186,7 @@ exports.configure = function configure (config) {
|
|||
{currency: deviceCurrency},
|
||||
function onTickerChange (newTicker) {
|
||||
tickerPlugins[cryptoCode] = newTicker
|
||||
pollRate(cryptoCode)
|
||||
cache.clearRate()
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -475,10 +474,8 @@ function monitorUnnotified () {
|
|||
exports.startPolling = function startPolling () {
|
||||
executeTrades()
|
||||
|
||||
const cryptoCodes = getCryptoCodes()
|
||||
const cryptoCodes = getAllCryptoCodes()
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
setInterval(async.apply(pollBalance, cryptoCode), POLLING_RATE)
|
||||
setInterval(async.apply(pollRate, cryptoCode), POLLING_RATE)
|
||||
startTrader(cryptoCode)
|
||||
})
|
||||
|
||||
|
|
@ -541,37 +538,6 @@ function pollBalance (cryptoCode) {
|
|||
})
|
||||
}
|
||||
|
||||
function pollRate (cryptoCode, cb) {
|
||||
const tickerPlugin = tickerPlugins[cryptoCode]
|
||||
logger.debug('[%s] polling for rates (%s)', cryptoCode, tickerPlugin.NAME)
|
||||
|
||||
let currencies = deviceCurrency
|
||||
if (typeof currencies === 'string') currencies = [currencies]
|
||||
|
||||
const tickerF = cryptoCode === 'BTC'
|
||||
? async.apply(tickerPlugin.ticker, currencies)
|
||||
: async.apply(tickerPlugin.ticker, currencies, cryptoCode)
|
||||
|
||||
tickerF((err, resRates) => {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
return cb && cb(err)
|
||||
}
|
||||
|
||||
resRates.timestamp = Date.now()
|
||||
const rates = resRates[deviceCurrency].rates
|
||||
if (rates) {
|
||||
rates.ask = rates.ask && new BigNumber(rates.ask)
|
||||
rates.bid = rates.bid && new BigNumber(rates.bid)
|
||||
}
|
||||
logger.debug('[%s] got rates: %j', cryptoCode, resRates)
|
||||
|
||||
lastRates[cryptoCode] = resRates
|
||||
|
||||
return cb && cb(null, lastRates)
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters | Helpers
|
||||
*/
|
||||
|
|
@ -589,12 +555,8 @@ exports.getDeviceRate = function getDeviceRate (cryptoCode) {
|
|||
function purchase (trade, cb) {
|
||||
const cryptoCode = trade.cryptoCode
|
||||
const traderPlugin = traderPlugins[cryptoCode]
|
||||
const opts = {
|
||||
cryptoCode,
|
||||
fiat: deviceCurrency
|
||||
}
|
||||
|
||||
traderPlugin.purchase(trade.cryptoAtoms, opts, err => {
|
||||
traderPlugin.purchase(trade.cryptoAtoms, deviceCurrency, cryptoCode, err => {
|
||||
if (err) return cb(err)
|
||||
pollBalance(cryptoCode)
|
||||
if (typeof cb === 'function') cb()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue