Skip to content

Commit

Permalink
CY-1592: Use correct positive and negative amounts. (#64)
Browse files Browse the repository at this point in the history
* CY-1592: Use correct positive and negative amounts.

* CY-1592: Make sure tests pass.

* CY-1592: Bump version
  • Loading branch information
hareland authored Dec 12, 2024
1 parent 9706022 commit 38ca077
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/ApiResponseConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ function convertFromKrakenTrade(id, trade) {
return [ error, null ];
}

const baseAmount = coinifyCurrency.toSmallestSubunit(parseFloat(trade.vol), baseCurrency);
const feeAmount = coinifyCurrency.toSmallestSubunit(parseFloat(trade.fee), quoteCurrency);
const quoteAmount = coinifyCurrency.toSmallestSubunit(parseFloat(trade.cost), quoteCurrency);
const roundBaseAmount = coinifyCurrency.toSmallestSubunit(parseFloat(trade.vol), baseCurrency);

//Ensure we use the correct side
const baseAmount = trade.type === 'buy' ? roundBaseAmount : -roundBaseAmount;
const roundedQuoteAmount = coinifyCurrency.toSmallestSubunit(parseFloat(trade.cost), quoteCurrency);
const quoteAmount = trade.type === 'buy' ? -roundedQuoteAmount : roundedQuoteAmount;


return [ null, {
externalId: id,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
"test": "LOG_LEVEL=fatal mocha --config .mocharc.json",
"test-watch": "LOG_LEVEL=info mocha --config .mocharc.json --watch"
},
"version": "2.5.0"
"version": "2.5.1"
}
8 changes: 6 additions & 2 deletions test/unit/listTradeHistoryForPeriod.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ describe('#listTradeHistoryForPeriod', function () {
expect(trades).containSubset([
{
baseCurrency: 'ETH',
quoteCurrency: 'USD'
quoteCurrency: 'USD',
baseAmount: 10000000000,
quoteAmount: -30010
},
{
baseCurrency: 'EUR',
Expand All @@ -254,7 +256,9 @@ describe('#listTradeHistoryForPeriod', function () {
},
{
baseCurrency: 'BTC',
quoteCurrency: 'USD'
quoteCurrency: 'USD',
baseAmount: -1000000,
quoteAmount: 30010
},
{
baseCurrency: 'BTC',
Expand Down

0 comments on commit 38ca077

Please sign in to comment.