This commit is contained in:
Josh Harvey 2016-11-26 18:56:33 +02:00
parent cee4486cbd
commit 7e5515a873
4 changed files with 5 additions and 43 deletions

0
lib/cache.js Normal file
View file

View file

@ -3,7 +3,6 @@
const fs = require('fs') const fs = require('fs')
const uuid = require('uuid') const uuid = require('uuid')
const R = require('ramda') const R = require('ramda')
const async = require('async')
const HKDF = require('node-hkdf-sync') const HKDF = require('node-hkdf-sync')
const BigNumber = require('bignumber.js') const BigNumber = require('bignumber.js')
@ -170,7 +169,7 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
exports.configure = function configure (config) { exports.configure = function configure (config) {
cachedConfig = config cachedConfig = config
const cryptoCodes = getCryptoCodes() const cryptoCodes = getAllCryptoCodes()
return configManager.loadAccounts() return configManager.loadAccounts()
.then(accounts => { .then(accounts => {
@ -187,7 +186,7 @@ exports.configure = function configure (config) {
{currency: deviceCurrency}, {currency: deviceCurrency},
function onTickerChange (newTicker) { function onTickerChange (newTicker) {
tickerPlugins[cryptoCode] = newTicker tickerPlugins[cryptoCode] = newTicker
pollRate(cryptoCode) cache.clearRate()
} }
) )
@ -475,10 +474,8 @@ function monitorUnnotified () {
exports.startPolling = function startPolling () { exports.startPolling = function startPolling () {
executeTrades() executeTrades()
const cryptoCodes = getCryptoCodes() const cryptoCodes = getAllCryptoCodes()
cryptoCodes.forEach(cryptoCode => { cryptoCodes.forEach(cryptoCode => {
setInterval(async.apply(pollBalance, cryptoCode), POLLING_RATE)
setInterval(async.apply(pollRate, cryptoCode), POLLING_RATE)
startTrader(cryptoCode) 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 * Getters | Helpers
*/ */
@ -589,12 +555,8 @@ exports.getDeviceRate = function getDeviceRate (cryptoCode) {
function purchase (trade, cb) { function purchase (trade, cb) {
const cryptoCode = trade.cryptoCode const cryptoCode = trade.cryptoCode
const traderPlugin = traderPlugins[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) if (err) return cb(err)
pollBalance(cryptoCode) pollBalance(cryptoCode)
if (typeof cb === 'function') cb() if (typeof cb === 'function') cb()

0
lib/ticker.js Normal file
View file

View file

@ -7,7 +7,6 @@
"author": "Lamassu (https://lamassu.is)", "author": "Lamassu (https://lamassu.is)",
"dependencies": { "dependencies": {
"ajv": "^4.9.0", "ajv": "^4.9.0",
"async": "^2.1.2",
"bignumber.js": "^3.0.0", "bignumber.js": "^3.0.0",
"body-parser": "^1.15.1", "body-parser": "^1.15.1",
"express": "^4.13.4", "express": "^4.13.4",
@ -16,6 +15,7 @@
"lamassu-bitcoind": "https://github.com/lamassu/lamassu-bitcoind/tarball/alpha", "lamassu-bitcoind": "https://github.com/lamassu/lamassu-bitcoind/tarball/alpha",
"lamassu-bitgo": "https://github.com/lamassu/lamassu-bitgo/tarball/alpha", "lamassu-bitgo": "https://github.com/lamassu/lamassu-bitgo/tarball/alpha",
"lamassu-bitpay": "~1.0.0", "lamassu-bitpay": "~1.0.0",
"lamassu-bitstamp": "https://github.com/lamassu/lamassu-bitstamp/tarball/alpha",
"lamassu-coindesk": "^1.0.4", "lamassu-coindesk": "^1.0.4",
"lamassu-mailjet": "^1.0.0", "lamassu-mailjet": "^1.0.0",
"lamassu-mock-id-verify": "^1.0.1", "lamassu-mock-id-verify": "^1.0.1",