UNPKG

3.77 kBMarkdownView Raw
1node-btc-e
2=====
3
4An unofficial node.js client for the [btc-e trade api](https://btc-e.com/api/documentation) including v2 public api methods(depth, fee, ticker, and trades).
5
6## Installation
7
8node-btc-e is available as `btc-e` on npm.
9
10```
11npm install btc-e
12```
13
14## Usage
15
16```javascript
17var BTCE = require('btc-e'),
18 btceTrade = new BTCE("YourApiKey", "YourSecret"),
19 // No need to provide keys if you're only using the public api methods.
20 btcePublic = new BTCE();
21
22// Public API method call.
23// Note: Could use "btceTrade" here as well.
24btcePublic.ticker("ltc_btc", function(err, data) {
25 console.log(err, data);
26});
27
28// Trade API method call.
29btceTrade.getInfo(function(err, info) {
30 console.log(err, info);
31});
32```
33
34## Options
35
36The constructor supports an optional third parameter for passing in various options to override defaults, which can either be a hash of the overrides or a nonce generation function if that is the only override required.
37
38When passed as a hash, the following options are supported:
39* agent - The HTTPS agent to use when making requests
40* timeout - The timeout to use when making requests, defaults to 5 seconds
41* nonce - A nonce generation function ([Custom nonce generation](#custom-nonce-generation))
42* tapi_url - The base url to use when making trade api requests, defaults to `https://btc-e.com/tapi`
43* public_url - The base url to use when making public api requests, defaults to `https://btc-e.com/api/2/`
44* strict_ssl - `true` by default, but can be set to `false` if desired, such as if btc-e has problems with their SSL certificate again.
45
46```javascript
47var BTCE = require('btc-e'),
48 HttpsAgent = require('agentkeepalive').HttpsAgent,
49 btceTrade = new BTCE("YourApiKey", "YourSecret", {
50 agent: new HttpsAgent()
51 });
52```
53
54## Custom nonce generation
55
56By default the module generates a nonce based on the current timestamp in seconds(can't use anything smaller than seconds since btc-e is capped at 4294967294 for nonces) as a means of providing a consistently increasing number, but for traders who want to possibly get in more than one trade api request per second per api key there is a way to do so by providing a nonce generation function as the `nonce` option in an options hash provided as the third parameter to the constructor. Please don't abuse the service btc-e is providing though.
57
58btc-e expects every nonce given to be greater than the previous one for each api key you have, this presents a big problem when trying to do multiple async calls with the same api key since there is no guarantee that the first api call will be processed before the second one and so on. Chaining calls synchronously(take a look at promises with [q.js](https://github.com/kriskowal/q) for help with that) or using multiple clients, each with their own API key are the only way around that problem.
59
60```javascript
61var BTCE = require('btc-e'),
62 fs = require('fs'),
63 currentNonce = fs.existsSync("nonce.json") ? JSON.parse(fs.readFileSync("nonce.json")) : 0,
64 // Provide a nonce generation function as the third parameter if desired.
65 // The function must provide a number that is larger than the one before and must not
66 // be larger than the 32-bit unsigned integer max value of 4294967294.
67 btce = new BTCE("YourApiKey", "YourSecret", {
68 nonce: function() {
69 currentNonce++;
70 fs.writeFile("nonce.json", currentNonce);
71 return currentNonce;
72 }
73 });
74
75btce.getInfo(function(err, info) {
76 console.log(err, info);
77});
78```
79
80## Reference
81
82A method-by-method [reference](https://github.com/pskupinski/node-btc-e/wiki/API-Reference) is available on the wiki.
83
84## License
85
86This module is [ISC licensed](https://github.com/pskupinski/node-btc-e/blob/master/LICENSE.txt).