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

Fix Bitstamp precision for BTC pairs and XRPUSD #2012

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions exchanges/bitstamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ Trader.prototype.getFee = function(callback) {
}

Trader.prototype.buy = function(amount, price, callback) {
var findMarket = function(pair) {
return pair.pair[0].toLowerCase() === this.currency && pair.pair[1].toLowerCase() === this.asset
}
var args = _.toArray(arguments);
var set = function(err, result) {
if(err || result.status === "error") {
Expand All @@ -98,22 +101,19 @@ Trader.prototype.buy = function(amount, price, callback) {
}.bind(this);

//Decrease amount by 1% to avoid trying to buy more than balance allows.
amount -= amount / 100;

amount *= 100000000;
amount = Math.floor(amount);
amount /= 100000000;
amount = Number(amount * 0.99).toFixed(8);

// prevent:
// 'Ensure that there are no more than 2 decimal places.'
price *= 100;
price = Math.floor(price);
price /= 100;
// Use proper precision by currency pair
var pair = _.find(Trader.getCapabilities().markets, _.bind(findMarket, this));
price = Number(Number.parseFloat(price).toFixed(pair.precision));

this.bitstamp.buy(this.market, amount, price, undefined, set);
}

Trader.prototype.sell = function(amount, price, callback) {
var findMarket = function(pair) {
return pair.pair[0].toLowerCase() === this.currency && pair.pair[1].toLowerCase() === this.asset
}
var args = _.toArray(arguments);
var set = function(err, result) {
if(err || result.status === "error") {
Expand All @@ -126,15 +126,11 @@ Trader.prototype.sell = function(amount, price, callback) {

// prevent:
// 'Ensure that there are no more than 8 decimal places.'
amount *= 100000000;
amount = Math.floor(amount);
amount /= 100000000;
amount = Number(Number.parseFloat(amount)).toFixed(8);

// prevent:
// 'Ensure that there are no more than 2 decimal places.'
price *= 100;
price = Math.ceil(price);
price /= 100;
// Use proper precision by currency pair
var pair = _.find(Trader.getCapabilities().markets, _.bind(findMarket, this));
price = Number(Number.parseFloat(price).toFixed(pair.precision));

this.bitstamp.sell(this.market, amount, price, undefined, set);
}
Expand Down Expand Up @@ -234,26 +230,26 @@ Trader.getCapabilities = function () {
maxTradesAge: 60,
maxHistoryFetch: null,
markets: [
{ pair: ['USD', 'EUR'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['USD', 'EUR'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },

{ pair: ['USD', 'BTC'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['EUR', 'BTC'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['USD', 'BTC'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['EUR', 'BTC'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },

{ pair: ['USD', 'BCH'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['EUR', 'BCH'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['BTC', 'BCH'], minimalOrder: { amount: 0.001, unit: 'currency' } },
{ pair: ['USD', 'BCH'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['EUR', 'BCH'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['BTC', 'BCH'], minimalOrder: { amount: 0.001, unit: 'currency'}, precision: 8 },

{ pair: ['USD', 'XRP'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['EUR', 'XRP'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['BTC', 'XRP'], minimalOrder: { amount: 0.001, unit: 'currency' } },
{ pair: ['USD', 'XRP'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 5 },
{ pair: ['EUR', 'XRP'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 5 },
{ pair: ['BTC', 'XRP'], minimalOrder: { amount: 0.001, unit: 'currency'}, precision: 8 },

{ pair: ['USD', 'LTC'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['EUR', 'LTC'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['BTC', 'LTC'], minimalOrder: { amount: 0.001, unit: 'currency' } },
{ pair: ['USD', 'LTC'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['EUR', 'LTC'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['BTC', 'LTC'], minimalOrder: { amount: 0.001, unit: 'currency'}, precision: 8 },

{ pair: ['USD', 'ETH'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['EUR', 'ETH'], minimalOrder: { amount: 5, unit: 'currency' } },
{ pair: ['BTC', 'ETH'], minimalOrder: { amount: 0.001, unit: 'currency' } },
{ pair: ['USD', 'ETH'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['EUR', 'ETH'], minimalOrder: { amount: 5, unit: 'currency' }, precision: 2 },
{ pair: ['BTC', 'ETH'], minimalOrder: { amount: 0.001, unit: 'currency'}, precision: 8 },
],
requires: ['key', 'secret', 'username'],
fetchTimespan: 60,
Expand Down