Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #348 from xhad/new-bitfinex
Browse files Browse the repository at this point in the history
fixed symbol error
  • Loading branch information
askmike authored Jun 26, 2016
2 parents f518c79 + 2af9121 commit f41165d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion exchanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var exchanges = [
{ pair: ['BTC', 'ETH'], minimalOrder: { amount: 0.01, unit: 'asset' }},
],
requires: ['key', 'secret'],
maxHistoryFetch: 10000,
maxHistoryFetch: 2000,
tid: 'tid'

},
Expand Down
22 changes: 9 additions & 13 deletions exchanges/bitfinex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var log = require('../core/log');

// Module-wide constants
var exchangeName = 'bitfinex';
// Bitfinex supports Litecoin, but this module currently only supports Bitcoin
var symbol;

var Trader = function(config) {
_.bindAll(this);
Expand All @@ -18,8 +18,9 @@ var Trader = function(config) {
this.name = 'Bitfinex';
this.balance;
this.price;
this.pair = config.asset + config.currency;
this.bitfinex = new Bitfinex(this.key, this.secret).rest;
symbol = config.asset + config.currency;
this.bitfinex = new Bitfinex(this.key, this.secret);
this.bitfinex = this.bitfinex.rest;
}

// if the exchange errors we try the same call again after
Expand Down Expand Up @@ -70,12 +71,9 @@ Trader.prototype.getTicker = function(callback) {
// so we use this.retry since this will wait first
// before we retry.
// the arguments we need to pass the the ticker method
//>> this.retry throws an error
var tryAgain = function () {
return this.bitfinex.ticker(this.pair, process);
}.bind(this);

return tryAgain();
var args = [ symbol, process ];
return this.retry(bitfinex.ticker(args));
}

// whenever we reach this point we have valid
Expand All @@ -84,7 +82,7 @@ Trader.prototype.getTicker = function(callback) {
callback(err, {bid: +data.bid, ask: +data.ask})
}.bind(this);

this.bitfinex.ticker(this.pair, process);
this.bitfinex.ticker(symbol, process);
}

// This assumes that only limit orders are being placed, so fees are the
Expand All @@ -98,8 +96,7 @@ function submit_order(bfx, type, amount, price, callback) {
// TODO: Bitstamp module included the following - is it necessary?
// amount *= 0.995; // remove fees
amount = Math.floor(amount*100000000)/100000000;

bfx.new_order(this.pair, amount + '', price + '', exchangeName,
bfx.new_order(symbol, amount + '', price + '', exchangeName,
type,
'exchange limit',
function (err, data, body) {
Expand All @@ -112,7 +109,6 @@ function submit_order(bfx, type, amount, price, callback) {

Trader.prototype.buy = function(amount, price, callback) {
submit_order(this.bitfinex, 'buy', amount, price, callback);

}

Trader.prototype.sell = function(amount, price, callback) {
Expand All @@ -136,7 +132,7 @@ Trader.prototype.getTrades = function(since, callback, descending) {
var args = _.toArray(arguments);
var self = this;

var path = this.pair;
var path = symbol;
if(since)
path += '?limit_trades=' + since;

Expand Down

0 comments on commit f41165d

Please sign in to comment.