diff --git a/index.js b/index.js index 978a38a..7615706 100644 --- a/index.js +++ b/index.js @@ -555,7 +555,18 @@ Kraken.prototype._listTransactionsRecursive = function (type, start, knownTransa try { // Construct transaction objects for each ledger entry - const transactions = _.values(response.ledger).map(convertFromKrakenTransaction); + const transactions = _.values(response.ledger).map(tx => { + try{ + return convertFromKrakenTransaction(tx); + }catch (err) { + const msg = err.cause ? err.cause.message : err.message; + if(msg.match(new RegExp('Invalid currency \'[A-Z]{2,4}\'', 'g'))){ + this.logger.info(err, msg); + return null; //convertFromKrakenTransaction can also return null so we just continue with that as "invalid" + } + throw err; + } + }); // Merge our newly converted transactions with the ones from previous calls const allTransactions = transactions.concat(knownTransactions); diff --git a/package-lock.json b/package-lock.json index 0fe0540..8bc17f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kraken-exc", - "version": "2.5.2", + "version": "2.5.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 67dc7fb..def0349 100644 --- a/package.json +++ b/package.json @@ -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.3" + "version": "2.5.4" } diff --git a/test/unit/listTransactions.test.js b/test/unit/listTransactions.test.js index 1bb5552..51d4843 100644 --- a/test/unit/listTransactions.test.js +++ b/test/unit/listTransactions.test.js @@ -329,4 +329,75 @@ describe('listTransactions', () => { }); }); }); + + it('should ignore invalid currencies', (done) => { + //Mock response... + const withdrawalRawObject = { + refid: 'ACLLUS5-JKRHGP-ZWWYSO', + time: 1480675052.7086, + type: 'withdrawal', + aclass: 'currency', + asset: 'TAO', + amount: '-24952.5900', + fee: '47.4100', + balance: '4440.5843' + }; + + const withdrawalApiResponse = + { + ledger: { 'YQ4LR7-6WL5O-Y4XDP3': withdrawalRawObject } + }; + + /* + * Mock response from the deposit Ledgers endpoint + */ + const depositRawObject = + { + refid: 'QGB2OUR-O5OQ6O-T5RZJF', + time: 1420989927.5751, + type: 'deposit', + aclass: 'currency', + asset: 'XXBT', + amount: '0.0465757500', + fee: '0.0000000000', + balance: '8.3684639100' + }; + const depositApiResponse = + { + ledger: { 'Y4HJR1-WWT7H-YH945H': depositRawObject } + }; + + /* + * Define expected response from listTransactions() + * Note that the deposit is the oldest, so it is returned first as per the API definition + */ + const expectedConvertedResponse = [ + { + externalId: 'QGB2OUR-O5OQ6O-T5RZJF', + timestamp: '2015-01-11T15:25:27.575Z', + state: 'completed', + amount: 4657575, + currency: 'BTC', + type: 'deposit', + raw: depositRawObject + }, null //this is the invalid currency + ]; + + const withdrawalReqStub = reqStub.withArgs(sinon.match.any, 'Ledgers', sinon.match({ type: 'withdrawal' })); + withdrawalReqStub.onCall(0).yields(null, withdrawalApiResponse); + withdrawalReqStub.onCall(1).yields(null, { ledger: {} }); + + const depositReqStub = reqStub.withArgs(sinon.match.any, 'Ledgers', sinon.match({ type: 'deposit' })); + depositReqStub.onCall(0).yields(null, depositApiResponse); + depositReqStub.onCall(1).yields(null, { ledger: {} }); + + kraken.listTransactions(null, function (err, result) { + if (err) { + return done(err); + } + expect(result).to.deep.equal(expectedConvertedResponse); + + done(); + }); + }); });