kraken-api
Advanced tools
Comparing version 0.0.9 to 0.1.0
@@ -128,12 +128,15 @@ var request = require('request'); | ||
var req = request.post(options, function(error, response, body) { | ||
if(error) { | ||
throw new Error('Error in server response: ' + JSON.stringify(error)); | ||
} | ||
else if(typeof callback === 'function') { | ||
if(typeof callback === 'function') { | ||
if (error) { | ||
callback.call(self, new Error('Error in server response: ' + JSON.stringify(error))); | ||
} | ||
var data; | ||
try { | ||
callback.call(self, JSON.parse(body)); | ||
data = JSON.parse(body); | ||
} catch(e) { | ||
return callback.call(self, new Error('Could not understand response from server: ' + body)); | ||
} | ||
catch(e) { | ||
throw new Error('Could not understand response from server.'); | ||
} | ||
callback.call(self, null, data); | ||
} | ||
@@ -140,0 +143,0 @@ }); |
{ | ||
"name": "kraken-api", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "kraken.com API client library for NodeJS", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,3 +0,3 @@ | ||
npm-kraken-api | ||
============== | ||
Node Kraken | ||
=========== | ||
@@ -13,11 +13,36 @@ NodeJS Client Library for the Kraken (kraken.com) API | ||
```javascript | ||
var kraken = require('kraken-api'); | ||
var client = new kraken('api_key', 'api_secret'); | ||
var KrakenClient = require('kraken-api'); | ||
var kraken = new KrakenClient('api_key', 'api_secret'); | ||
// Display user's balance | ||
client.api('Balance', null, function(response) { | ||
console.log('Balances:', response.result); | ||
kraken.api('Balance', null, function(error, data) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log(data.result); | ||
} | ||
}); | ||
// Get Ticker Info | ||
kraken.api('Ticker', {"pair": 'XBTCXLTC'}, function(error, data) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log(data.result); | ||
} | ||
}); | ||
``` | ||
**Update:** | ||
As of version 0.1.0, the callback passed to the *api* function conforms to the Node.js standard of | ||
```javascript | ||
function(error, data) { | ||
// ... | ||
} | ||
``` | ||
Thanks to @tehsenaus and @petermrg for pointing this out. | ||
Credit: | ||
@@ -24,0 +49,0 @@ |
8448
152
54