From d6ec60db557e27e63e67394be5462772c6359652 Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Wed, 6 Apr 2016 17:25:43 +0100 Subject: [PATCH] WIP -- running with BTC only --- lib/plugins.js | 14 +++++++++++--- lib/routes.js | 11 +++++++++-- todo.txt | 4 ---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/plugins.js b/lib/plugins.js index c92f9ab3..6c673b98 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -119,6 +119,8 @@ function loadOrConfigPlugin (pluginHandle, pluginType, cryptoCode, currency, ? cachedConfig.exchanges.plugins.current[pluginType] : cachedConfig.exchanges.plugins.current[cryptoCode][pluginType] + currentlyUsedPlugins[cryptoCode] = currentlyUsedPlugins[cryptoCode] || {} + var pluginChanged = currentlyUsedPlugins[cryptoCode][pluginType] !== currentName if (!currentName) pluginHandle = null @@ -149,7 +151,7 @@ exports.configure = function configure (config) { cachedConfig = config deviceCurrency = config.exchanges.settings.currency - cryptoCodes = config.exchanges.settings.coins || 'BTC' + cryptoCodes = config.exchanges.settings.coins || ['BTC'] cryptoCodes.forEach(function (cryptoCode) { // TICKER [required] configure (or load) @@ -448,8 +450,8 @@ function pollBalance (cryptoCode, cb) { } function pollRate (cryptoCode, cb) { - logger.debug('[%s] polling for rates (%s)', cryptoCode, tickerPlugin.NAME) var tickerPlugin = tickerPlugins[cryptoCode] + logger.debug('[%s] polling for rates (%s)', cryptoCode, tickerPlugin.NAME) var currencies = deviceCurrency if (typeof currencies === 'string') currencies = [currencies] @@ -464,8 +466,14 @@ function pollRate (cryptoCode, cb) { return cb && cb(err) } - logger.debug('got rates: %j', resRates) resRates.timestamp = new Date() + var rates = resRates[deviceCurrency].rates + if (rates) { + rates.ask = rates.ask && new BigNumber(rates.ask) + rates.bid = rates.bid && new BigNumber(rates.bid) + } + logger.debug('got rates: %j', resRates) + lastRates[cryptoCode] = resRates return cb && cb(null, lastRates) diff --git a/lib/routes.js b/lib/routes.js index c8121280..8c46c35c 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -1,5 +1,6 @@ 'use strict' +var BigNumber = require('bignumber.js') var logger = require('./logger') var mock = false @@ -101,14 +102,20 @@ function poll (req, res) { } function trade (req, res) { - plugins.trade(session(req), req.body, function (err) { + var tx = req.body + tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms) + + plugins.trade(session(req), tx, function (err) { var statusCode = err ? 500 : 201 res.json(statusCode, {err: err}) }) } function send (req, res) { - plugins.sendCoins(session(req), req.body, function (err, status) { + var tx = req.body + tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms) + + plugins.sendCoins(session(req), tx, function (err, status) { // TODO: use status.statusCode here after confirming machine compatibility // FIX: (joshm) set txHash to status.txId instead of previous status.txHash which wasn't being set // Need to clean up txHash vs txId diff --git a/todo.txt b/todo.txt index c3230c55..ec0e1d8f 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,3 @@ -- specify crypto and fiat for trades -- make sure ticker is in full coins - getDeviceRate should return bignumber - test with l-m @@ -7,7 +5,5 @@ backwards compatibility: - new l-m must be backwards compatible with old l-s -- parse out bignumber when loading in routes -- making a trade -- convert to units - clean up db stuff satoshis/cryptoAtoms - clean up other stuff