Skip to content

Commit

Permalink
real trading now working on poloniex
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Jun 14, 2016
1 parent 5263f59 commit 4c260cb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions core/portfolioManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ Manager.prototype.sell = function(amount, price) {

Manager.prototype.noteOrder = function(err, order) {
this.order = order;
// if after 5 minutes the order is still there
// if after 1 minute the order is still there
// we cancel and calculate & make a new one
setTimeout(this.checkOrder, util.minToMs(5));
setTimeout(this.checkOrder, util.minToMs(1));
}

// check wether the order got fully filled
Expand Down
2 changes: 1 addition & 1 deletion docs/supported_exchanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [kraken](http://kraken.com/)
- [bitfinex](https://bitfinex.com/)
- [btc-e](https://btc-e.com/)
- [poloniex](https://poloniex.com/)

## Partially working (live trading might not work correctly)

Expand All @@ -14,6 +15,5 @@
- [BTCC](https://btcc.com/) (trading not implemented at the moment)
- [lakeBTC](https://lakebtc.com/)
- [meXBT](https://mexbt.com/) (see [here](https://github.com/askmike/gekko/issues/288#issuecomment-223810974))
- [poloniex](https://poloniex.com/)
- [zaif](https://zaif.jp/trade_btc_jpy)
- [bx.in.th](https://bx.in.th/)
48 changes: 32 additions & 16 deletions exchanges/poloniex.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ var Trader = function(config) {
if(_.isObject(config)) {
this.key = config.key;
this.secret = config.secret;
this.clientID = config.username;
this.currency = config.currency;
this.asset = config.asset;
}
this.name = 'Poloniex';
this.balance;
this.price;

this.pair = [this.currency, this.asset].join('_');

this.poloniex = new Poloniex(this.key, this.secret);
}

Expand Down Expand Up @@ -49,21 +50,36 @@ Trader.prototype.retry = function(method, args) {
}

Trader.prototype.getPortfolio = function(callback) {
var args = _.toArray(arguments);
var set = function(err, data) {
if(err)
return this.retry(this.getPortfolio, args);

var portfolio = [];
_.each(data, function(amount, asset) {
if(asset.indexOf('available') !== -1) {
//asset = asset.substr(0, 3).toUpperCase();
portfolio.push({name: asset, amount: parseFloat(amount)});
}
portfolio.push({name: asset, amount: parseFloat(amount)});
});

callback(err, portfolio);
}
this.poloniex.myBalances(_.bind(set, this));
}.bind(this);

this.poloniex.myBalances(set);
}

Trader.prototype.getTicker = function(callback) {
this.poloniex.getTicker(callback);
var args = _.toArray(arguments);
this.poloniex.getTicker(function(err, data) {
if(err)
return this.retry(this.getTicker, args);

var tick = data[this.pair];

callback(null, {
bid: parseFloat(tick.highestBid),
ask: parseFloat(tick.lowestAsk),
});

}.bind(this));
}

Trader.prototype.getFee = function(callback) {
Expand All @@ -82,9 +98,9 @@ Trader.prototype.buy = function(amount, price, callback) {
return log.error('unable to buy:', err, result);

callback(null, result.orderNumber);
};
}.bind(this);

this.poloniex.buy(this.currency, this.asset, price, amount, _.bind(set, this));
this.poloniex.buy(this.currency, this.asset, price, amount, set);
}

Trader.prototype.sell = function(amount, price, callback) {
Expand All @@ -93,18 +109,18 @@ Trader.prototype.sell = function(amount, price, callback) {
return log.error('unable to sell:', err, result);

callback(null, result.orderNumber);
};
}.bind(this);

this.poloniex.sell(this.currency, this.asset, price, amount, _.bind(set, this));
this.poloniex.sell(this.currency, this.asset, price, amount, set);
}

Trader.prototype.checkOrder = function(order, callback) {
var check = function(err, result) {
var stillThere = _.find(result, function(o) { return o.orderNumber === order });
callback(err, !stillThere);
};
}.bind(this);

this.poloniex.myOpenOrders(_.bind(check, this));
this.poloniex.myOpenOrders(this.currency, this.asset, check);
}

Trader.prototype.cancelOrder = function(order, callback) {
Expand All @@ -113,9 +129,9 @@ Trader.prototype.cancelOrder = function(order, callback) {
log.error('unable to cancel order', order, '(', err, result, ')');
// return this.retry(this.cancelOrder, args);
}
};
}.bind(this);

this.poloniex.cancelOrder(this.currency, this.asset, order, _.bind(cancel, this));
this.poloniex.cancelOrder(this.currency, this.asset, order, cancel);
}

Trader.prototype.getTrades = function(since, callback, descending) {
Expand Down

0 comments on commit 4c260cb

Please sign in to comment.