From 7831c91404555b8516c30fa3a5501c1af5dd1b6c Mon Sep 17 00:00:00 2001 From: Alexey Peshin <lexazan@gmail.com> Date: Tue, 15 Sep 2015 17:25:38 +0300 Subject: [PATCH 1/8] Updated to work with BTC-e V3 Public API --- btc-e.js | 23 ++++++++++++++++------- test-public-api.js | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 test-public-api.js diff --git a/btc-e.js b/btc-e.js index df996aa..b6904d3 100644 --- a/btc-e.js +++ b/btc-e.js @@ -5,7 +5,7 @@ var request = require('request'), var BTCE = function(apiKey, secret, options) { this.url = 'https://btc-e.com/tapi'; - this.publicApiUrl = 'https://btc-e.com/api/2/'; + this.publicApiUrl = 'https://btc-e.com/api/3/'; this.timeout = 5000; this.apiKey = apiKey; this.secret = secret; @@ -99,9 +99,17 @@ BTCE.prototype.makeRequest = function(method, params, callback) { }; BTCE.prototype.makePublicApiRequest = function(pair, method, callback) { - this._sendRequest({ - url: this.publicApiUrl + pair + '/' + method - }, callback); + + if (pair) { + this._sendRequest({ + url: this.publicApiUrl + method + '/' + pair + }, callback); + } else { + this._sendRequest({ + url: this.publicApiUrl + method + }, callback); + } + }; BTCE.prototype.getInfo = function(callback) { @@ -152,6 +160,10 @@ BTCE.prototype.cancelOrder = function(paramsOrOrderId, callback) { this.makeRequest('CancelOrder', input, callback); }; +BTCE.prototype.info = function (callback) { + this.makePublicApiRequest(false, 'info', callback); +}; + BTCE.prototype.ticker = function(pair, callback) { this.makePublicApiRequest(pair, 'ticker', callback); }; @@ -164,8 +176,5 @@ BTCE.prototype.depth = function(pair, callback) { this.makePublicApiRequest(pair, 'depth', callback); }; -BTCE.prototype.fee = function(pair, callback) { - this.makePublicApiRequest(pair, 'fee', callback); -}; module.exports = BTCE; diff --git a/test-public-api.js b/test-public-api.js new file mode 100644 index 0000000..0d0b406 --- /dev/null +++ b/test-public-api.js @@ -0,0 +1,27 @@ +var BTCE = require('./btc-e.js'), + btcePublic = new BTCE(); + + +console.log("Test Info Method"); +btcePublic.info(function(err, data) { + console.log(err, data); +}); + +/* +btcePublic.ticker("btc_usd", function(err, data) { + console.log("Test Ticker Method"); + console.log(err, data); +}); + + +btcePublic.depth("btc_usd", function(err, data) { + console.log("Test Depth Method"); + console.log(err, data); +}); + + +btcePublic.trades("btc_usd", function(err, data) { + console.log("Test Trades Method"); + console.log(err, data); +}); +*/ \ No newline at end of file From 3c4123612282b89d7ed0d66b0516ea05e5b1ead4 Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Tue, 15 Sep 2015 17:34:57 +0300 Subject: [PATCH 2/8] Update test-public-api.js Comments removed --- test-public-api.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test-public-api.js b/test-public-api.js index 0d0b406..1708823 100644 --- a/test-public-api.js +++ b/test-public-api.js @@ -7,7 +7,6 @@ btcePublic.info(function(err, data) { console.log(err, data); }); -/* btcePublic.ticker("btc_usd", function(err, data) { console.log("Test Ticker Method"); console.log(err, data); @@ -24,4 +23,3 @@ btcePublic.trades("btc_usd", function(err, data) { console.log("Test Trades Method"); console.log(err, data); }); -*/ \ No newline at end of file From bb1bc4d68e9163130fb5bdcbd29663129625967b Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Tue, 15 Sep 2015 17:39:06 +0300 Subject: [PATCH 3/8] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93be588..af5a464 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ node-btc-e ===== -An 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). +An 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).~~~ +Updated to work with BTC-e V3 Public API ## Installation From b2d17aed8277d628c3784d5e34cbe1d5b8bf01bb Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Tue, 15 Sep 2015 17:39:20 +0300 Subject: [PATCH 4/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af5a464..b9d3ff3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ node-btc-e ===== -An 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).~~~ +An 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).~~ Updated to work with BTC-e V3 Public API ## Installation From eda1ce79827f7df646ca0f44a003977229223a37 Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Tue, 15 Sep 2015 18:23:43 +0300 Subject: [PATCH 5/8] Update btc-e.js Add Limit option --- btc-e.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/btc-e.js b/btc-e.js index b6904d3..0034464 100644 --- a/btc-e.js +++ b/btc-e.js @@ -98,17 +98,19 @@ BTCE.prototype.makeRequest = function(method, params, callback) { }, callback); }; -BTCE.prototype.makePublicApiRequest = function(pair, method, callback) { +BTCE.prototype.makePublicApiRequest = function(pair, limit, method, callback) { + var url = this.publicApiUrl + method; if (pair) { - this._sendRequest({ - url: this.publicApiUrl + method + '/' + pair - }, callback); - } else { - this._sendRequest({ - url: this.publicApiUrl + method - }, callback); + url += '/' + pair; } + if (limit) { + url += "?limit=" + limit; + } + + this._sendRequest({ + url: url + }, callback); }; @@ -160,20 +162,20 @@ BTCE.prototype.cancelOrder = function(paramsOrOrderId, callback) { this.makeRequest('CancelOrder', input, callback); }; -BTCE.prototype.info = function (callback) { - this.makePublicApiRequest(false, 'info', callback); +BTCE.prototype.info = function ( callback) { + this.makePublicApiRequest(false, false, 'info', callback); }; BTCE.prototype.ticker = function(pair, callback) { - this.makePublicApiRequest(pair, 'ticker', callback); + this.makePublicApiRequest(pair, false, 'ticker', callback); }; -BTCE.prototype.trades = function(pair, callback) { - this.makePublicApiRequest(pair, 'trades', callback); +BTCE.prototype.trades = function(pair, limit, callback) { + this.makePublicApiRequest(pair, limit, 'trades', callback); }; -BTCE.prototype.depth = function(pair, callback) { - this.makePublicApiRequest(pair, 'depth', callback); +BTCE.prototype.depth = function(pair, limit, callback) { + this.makePublicApiRequest(pair, limit, 'depth', callback); }; From 7d4cda777ff3126c2a63bfe88cdfe8813552cc80 Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Tue, 15 Sep 2015 18:24:40 +0300 Subject: [PATCH 6/8] Add Limit option to tests --- test-public-api.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test-public-api.js b/test-public-api.js index 1708823..27d64ab 100644 --- a/test-public-api.js +++ b/test-public-api.js @@ -2,24 +2,25 @@ var BTCE = require('./btc-e.js'), btcePublic = new BTCE(); -console.log("Test Info Method"); btcePublic.info(function(err, data) { + console.log("Test Info Method"); console.log(err, data); }); + btcePublic.ticker("btc_usd", function(err, data) { console.log("Test Ticker Method"); console.log(err, data); }); -btcePublic.depth("btc_usd", function(err, data) { +btcePublic.depth("btc_usd", 20, function(err, data) { console.log("Test Depth Method"); console.log(err, data); }); -btcePublic.trades("btc_usd", function(err, data) { +btcePublic.trades("btc_usd", 20, function(err, data) { console.log("Test Trades Method"); console.log(err, data); }); From 9302de8dbcacf529af34ae10d7301ba4ed7e5d89 Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Thu, 17 Sep 2015 09:39:49 +0300 Subject: [PATCH 7/8] Update README.md --- README.md | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b9d3ff3..390a954 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,13 @@ node-btc-e ===== -An 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).~~ +An unofficial node.js client for the [btc-e trade api](https://btc-e.com/api/documentation) Updated to work with BTC-e V3 Public API -## Installation - -node-btc-e is available as `btc-e` on npm. - -``` -npm install btc-e -``` - ## Usage ```javascript -var BTCE = require('btc-e'), +var BTCE = require('./btc-e.js'), btceTrade = new BTCE("YourApiKey", "YourSecret"), // No need to provide keys if you're only using the public api methods. btcePublic = new BTCE(); @@ -45,7 +37,7 @@ When passed as a hash, the following options are supported: * 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. ```javascript -var BTCE = require('btc-e'), +var BTCE = require('./btc-e'), HttpsAgent = require('agentkeepalive').HttpsAgent, btceTrade = new BTCE("YourApiKey", "YourSecret", { agent: new HttpsAgent() @@ -59,7 +51,7 @@ By default the module generates a nonce based on the current timestamp in second btc-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. ```javascript -var BTCE = require('btc-e'), +var BTCE = require('./btc-e'), fs = require('fs'), currentNonce = fs.existsSync("nonce.json") ? JSON.parse(fs.readFileSync("nonce.json")) : 0, // Provide a nonce generation function as the third parameter if desired. @@ -82,9 +74,8 @@ btce.getInfo(function(err, info) { }); ``` -## Reference - -A method-by-method [reference](https://github.com/pskupinski/node-btc-e/wiki/API-Reference) is available on the wiki. +## Credits +All credits goes to [pskupinski](https://github.com/pskupinski/node-btc-e), as initial creator. ## License From cb1d03c73f6216b5f08ab2bd89c79ce697451d7a Mon Sep 17 00:00:00 2001 From: Lexazan <lexazan@gmail.com> Date: Thu, 17 Sep 2015 09:41:03 +0300 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 390a954..fa869ac 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ When passed as a hash, the following options are supported: * timeout - The timeout to use when making requests, defaults to 5 seconds * nonce - A nonce generation function ([Custom nonce generation](#custom-nonce-generation)) * tapi_url - The base url to use when making trade api requests, defaults to `https://btc-e.com/tapi` -* public_url - The base url to use when making public api requests, defaults to `https://btc-e.com/api/2/` +* public_url - The base url to use when making public api requests, defaults to `https://btc-e.com/api/3/` * 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. ```javascript