diff --git a/lib/cache.js b/lib/cache.js new file mode 100644 index 00000000..e69de29b diff --git a/lib/plugins.js b/lib/plugins.js index ada7c84c..5f5f70af 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -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() diff --git a/lib/ticker.js b/lib/ticker.js new file mode 100644 index 00000000..e69de29b diff --git a/package.json b/package.json index e742b8be..e34a6770 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "author": "Lamassu (https://lamassu.is)", "dependencies": { "ajv": "^4.9.0", - "async": "^2.1.2", "bignumber.js": "^3.0.0", "body-parser": "^1.15.1", "express": "^4.13.4", @@ -16,6 +15,7 @@ "lamassu-bitcoind": "https://github.com/lamassu/lamassu-bitcoind/tarball/alpha", "lamassu-bitgo": "https://github.com/lamassu/lamassu-bitgo/tarball/alpha", "lamassu-bitpay": "~1.0.0", + "lamassu-bitstamp": "https://github.com/lamassu/lamassu-bitstamp/tarball/alpha", "lamassu-coindesk": "^1.0.4", "lamassu-mailjet": "^1.0.0", "lamassu-mock-id-verify": "^1.0.1",