added bitcoind support; cleaned up

This commit is contained in:
Josh Harvey 2014-05-04 20:55:04 -04:00
parent 28e16d76e9
commit be04d1d75c
3 changed files with 13 additions and 11 deletions

View file

@ -41,11 +41,14 @@ var poll = function(req, res) {
}
var rate = rateRec.rate;
if (rate === null) return res.json({err: 'No rate available'});
var fiatBalance = _trader.fiatBalance(fingerprint);
if (fiatBalance === null) return res.json({err: 'No balance available'});
res.json({
err: null,
rate: rate * _trader.config.exchanges.settings.commission,
fiat: _trader.fiatBalance(fingerprint),
fiat: fiatBalance,
locale: _trader.config.brain.locale,
txLimit: parseInt(_trader.config.exchanges.settings.compliance.maximum.limit, 10)
});

View file

@ -1,10 +1,9 @@
'use strict';
var path = require('path');
var async = require('async');
var logger = require('./logger');
var SATOSHI_FACTOR = Math.pow(10, 8);
var SATOSHI_FACTOR = 1e8;
// TODO: Define this somewhere more global
var SESSION_TIMEOUT = 60 * 60 * 1000; // an hour
@ -64,9 +63,6 @@ Trader.prototype._purchase = function (trade, cb) {
var self = this;
var tradeCurrency = this.tradeExchange.currency();
var rate = this.rate(tradeCurrency).rate;
console.dir(this.rates);
console.log(rate);
console.log(tradeCurrency);
this.tradeExchange.purchase(trade.satoshis, rate, function (err) {
if (err) return cb(err);
self.pollBalance();
@ -110,7 +106,7 @@ Trader.prototype.fiatBalance = function (deviceFingerprint) {
var commission = this.config.exchanges.settings.commission;
if (!rawRate || !balance) {
return 0;
return null;
}
// The rate is actually our commission times real rate.
@ -121,7 +117,7 @@ Trader.prototype.fiatBalance = function (deviceFingerprint) {
var lowBalanceMargin = this.config.exchanges.settings.lowBalanceMargin;
// `balance.transferBalance` is the balance of our transfer account (the one
// we use to send Bitcoins to clients).
// we use to send Bitcoins to clients) in satoshis.
var transferBalance = balance.transferBalance;
// Since `transferBalance` is in satoshis, we need to turn it into
@ -295,9 +291,11 @@ Trader.prototype.pollRate = function (callback) {
logger.debug('polling for rates...');
self.tickerExchange.ticker(function(err, resRates) {
if (err) {
logger.error(err);
return callback && callback(err);
}
logger.debug('got rates: %j', resRates);
self.rateInfo = {rates: resRates, timestamp: new Date()};
});
};