Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #14 from blockchain/sell
Browse files Browse the repository at this point in the history
Sell
  • Loading branch information
plondon committed Dec 13, 2017
2 parents 6ee98e2 + 58c655b commit 06db471
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/quote.js
Expand Up @@ -21,10 +21,10 @@ class Quote extends Exchange.Quote {
this._rate = obj.rate;

this._baseCurrency = baseCurrency.toUpperCase();
this._baseAmount = isBTC(this._baseCurrency) ? btcAmount : usdAmount;
this._baseAmount = isBTC(this._baseCurrency) ? btcAmount : parseFloat(usdAmount).toFixed(2);

this._quoteCurrency = flipCurrency(this._baseCurrency);
this._quoteAmount = isBTC(this._quoteCurrency) ? btcAmount : usdAmount;
this._quoteAmount = isBTC(this._quoteCurrency) ? btcAmount : parseFloat(usdAmount).toFixed(2);

this._feeAmount = obj.fee_amount;
this._feeCurrency = obj.fee_currency.toUpperCase();
Expand All @@ -34,6 +34,14 @@ class Quote extends Exchange.Quote {
return this._rate;
}

get feeAmount () {
return this._feeAmount;
}

get feeCurrency () {
return this._feeCurrency;
}

static getQuote (api, delegate, amount, baseCurrency, quoteCurrency, debug) {
const processQuote = (quote) => {
let q = new Quote(quote, baseCurrency, api, delegate);
Expand Down
12 changes: 6 additions & 6 deletions src/trade.js
Expand Up @@ -45,7 +45,9 @@ class Trade extends Exchange.Trade {
if (this._inCurrency === 'BTC') {
this._inAmount = toSatoshi(obj.base_amount);
this._sendAmount = toSatoshi(obj.base_amount);
this._receiveAmount = obj.quote_amount;
this._feeAmount = obj.fee_amount;
this._feeCurrency = obj.fee_currency;
this._receiveAmount = obj.quote_amount - obj.fee_amount;
} else {
this._inAmount = toSatoshi(obj.quote_amount);
this._sendAmount = toSatoshi(obj.quote_amount);
Expand All @@ -59,14 +61,12 @@ class Trade extends Exchange.Trade {
}
this._createdAt = new Date(obj.created_at);

if (this._outCurrency === 'BTC') {
this._txHash = obj.blockchain_tx_hash || this._txHash;
this._receiveAddress = obj.address;
}

if (!this.id) {
this._id = obj.id;
}

this._receiveAddress = obj.address;
this._txHash = obj.blockchain_tx_hash || this._txHash;
}

setFromJSON (obj) {
Expand Down
4 changes: 2 additions & 2 deletions tests/quote_spec.js
Expand Up @@ -52,7 +52,7 @@ describe('SFOX Quote', function () {
obj.quote_amount = 35.05; // 35.05 * 100 = 3504.9999999999995 in javascript
obj.base_amount = 0.03505;
q = new Quote(obj, 'usd', {}, {});
expect(q.baseAmount).toEqual(35.05);
expect(q.baseAmount).toEqual('35.05');
expect(q.quoteAmount).toEqual(3505000);
});

Expand All @@ -63,7 +63,7 @@ describe('SFOX Quote', function () {
obj.base_amount = 0.00003505;
q = new Quote(obj, 'btc', {}, {});
expect(q.baseAmount).toEqual(3505);
expect(q.quoteAmount).toEqual(35.05);
expect(q.quoteAmount).toEqual('35.05');
});
});

Expand Down

0 comments on commit 06db471

Please sign in to comment.