Skip to content

Instantly share code, notes, and snippets.

@nyg nyg/kraken-ledger.js
Created May 30, 2014

Embed
What would you like to do?
Get all entries of your Kraken.com ledger.
/* Querying your ledger through Kraken's API only return 50 results... */
var KrakenClient = require('kraken-api'); // https://github.com/nothingisdead/npm-kraken-api
var kraken = new KrakenClient('api_key', 'api_secret');
var ledger = [];
var offset = 0;
function getLedgerEntries (error, data) {
if (error) {
console.log(error);
}
else {
var ledgerEntries = data.result.ledger;
for (var ledgerEntryId in ledgerEntries) {
ledgerEntries[ledgerEntryId].ledgerid = ledgerEntryId;
ledger.push(ledgerEntries[ledgerEntryId]);
}
var ledgerEntryCount = Object.getOwnPropertyNames(ledgerEntries).length;
if (ledgerEntryCount < 50) {
console.log(ledger);
}
else {
// Kraken API rate limit
setTimeout(loop, 5500);
}
}
}
function loop () {
kraken.api('Ledgers', { ofs: offset }, getLedgerEntries);
offset += 50;
}
loop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.