WIP
This commit is contained in:
parent
cee4486cbd
commit
7e5515a873
4 changed files with 5 additions and 43 deletions
0
lib/cache.js
Normal file
0
lib/cache.js
Normal file
|
|
@ -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()
|
||||
|
|
|
|||
0
lib/ticker.js
Normal file
0
lib/ticker.js
Normal file
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue