Comparing version 0.2.1 to 0.3.0
139
bitstamp.js
@@ -26,3 +26,2 @@ var querystring = require("querystring"); | ||
Bitstamp.prototype._request = function(method, path, data, callback, args) { | ||
var options = { | ||
@@ -100,13 +99,28 @@ host: 'www.bitstamp.net', | ||
Bitstamp.prototype._get = function(action, callback, args) { | ||
Bitstamp.prototype._get = function(market, action, callback, args) { | ||
args = _.compactObject(args); | ||
var path = '/api/' + action + (querystring.stringify(args) === '' ? '/' : '/?') + querystring.stringify(args); | ||
if(market) | ||
var path = '/api/v2/' + action + '/' + market; | ||
else | ||
// some documented endpoints (eg `https://www.bitstamp.net/api/eur_usd/`) | ||
// do not go via the v2 api. | ||
var path = '/api/' + action; | ||
path += (querystring.stringify(args) === '' ? '/' : '/?') + querystring.stringify(args); | ||
this._request('get', path, undefined, callback, args) | ||
} | ||
Bitstamp.prototype._post = function(action, callback, args) { | ||
Bitstamp.prototype._post = function(market, action, callback, args, legacy_endpoint) { | ||
if(!this.key || !this.secret || !this.client_id) | ||
return callback(new Error('Must provide key, secret and client ID to make this API request.')); | ||
var path = '/api/' + action + '/'; | ||
if(legacy_endpoint) | ||
var path = '/api/' + action + '/'; | ||
else { | ||
if(market) | ||
var path = '/api/v2/' + action + '/' + market + '/'; | ||
else | ||
var path = '/api/v2/' + action + '/'; | ||
} | ||
@@ -134,3 +148,3 @@ var nonce = this._generateNonce(); | ||
Bitstamp.prototype.transactions = function(options, callback) { | ||
Bitstamp.prototype.transactions = function(market, options, callback) { | ||
if(!callback) { | ||
@@ -140,10 +154,14 @@ callback = options; | ||
} | ||
this._get('transactions', callback, options); | ||
this._get(market, 'transactions', callback, options); | ||
} | ||
Bitstamp.prototype.ticker = function(callback) { | ||
this._get('ticker', callback); | ||
Bitstamp.prototype.ticker = function(market, callback) { | ||
this._get(market, 'ticker', callback); | ||
} | ||
Bitstamp.prototype.order_book = function(group, callback) { | ||
Bitstamp.prototype.ticker_hour = function(market, callback) { | ||
this._get(market, 'ticker_hour', callback); | ||
} | ||
Bitstamp.prototype.order_book = function(market, group, callback) { | ||
if(!callback) { | ||
@@ -158,11 +176,12 @@ callback = group; | ||
options = {group: group}; | ||
this._get('order_book', callback, options); | ||
this._get(market, 'order_book', callback, options); | ||
} | ||
Bitstamp.prototype.bitinstant = function(callback) { | ||
this._get('bitinstant', callback); | ||
} | ||
// This API calls are removed from the documentation as of `Sat Jun 11 2016 10:10:07` | ||
// Bitstamp.prototype.bitinstant = function(callback) { | ||
// this._get('bitinstant', callback); | ||
// } | ||
Bitstamp.prototype.eur_usd = function(callback) { | ||
this._get('eur_usd', callback); | ||
this._get(null, 'eur_usd', callback); | ||
} | ||
@@ -175,11 +194,7 @@ | ||
Bitstamp.prototype.balance = function(callback) { | ||
this._post('balance', callback); | ||
Bitstamp.prototype.balance = function(market, callback) { | ||
this._post(market, 'balance', callback); | ||
} | ||
Bitstamp.prototype.order_status = function (id, callback) { | ||
this._post('order_status', callback, {id: id}); | ||
}; | ||
Bitstamp.prototype.user_transactions = function(options, callback) { | ||
Bitstamp.prototype.user_transactions = function(market, options, callback) { | ||
if(!callback) { | ||
@@ -189,57 +204,89 @@ callback = options; | ||
} | ||
this._post('user_transactions', callback, options); | ||
this._post(market, 'user_transactions', callback, options); | ||
} | ||
Bitstamp.prototype.open_orders = function(callback) { | ||
this._post('open_orders', callback); | ||
Bitstamp.prototype.open_orders = function(market, callback) { | ||
this._post(market, 'open_orders', callback); | ||
} | ||
Bitstamp.prototype.order_status = function (id, callback) { | ||
this._post(null, 'order_status', callback, {id: id}, true); | ||
}; | ||
Bitstamp.prototype.cancel_order = function(id, callback) { | ||
this._post('cancel_order', callback, {id: id}); | ||
this._post(null, 'cancel_order', callback, {id: id}, true); | ||
} | ||
Bitstamp.prototype.buy = function(amount, price, callback) { | ||
this._post('buy', callback, {amount: amount, price: price}); | ||
Bitstamp.prototype.cancel_all_orders = function(callback) { | ||
this._post(null, 'cancel_all_orders', callback, null, true); | ||
} | ||
Bitstamp.prototype.sell = function(amount, price, callback) { | ||
this._post('sell', callback, {amount: amount, price: price}); | ||
Bitstamp.prototype.buy = function(market, amount, price, limit_price, callback) { | ||
this._post(market, 'buy', callback, { | ||
amount: amount, | ||
price: price, | ||
limit_price: limit_price | ||
}); | ||
} | ||
Bitstamp.prototype.sell = function(market, amount, price, limit_price, callback) { | ||
this._post(market, 'sell', callback, { | ||
amount: amount, | ||
price: price, | ||
limit_price: limit_price | ||
}); | ||
} | ||
Bitstamp.prototype.withdrawal_requests = function(callback) { | ||
this._post('withdrawal_requests', callback); | ||
this._post(null, 'withdrawal_requests', callback, null, true); | ||
} | ||
Bitstamp.prototype.bitcoin_withdrawal = function(amount, address, callback) { | ||
this._post('bitcoin_withdrawal', callback, {amount: amount, address: address}); | ||
Bitstamp.prototype.bitcoin_withdrawal = function(amount, address, instant, callback) { | ||
this._post(null, 'bitcoin_withdrawal', callback, { | ||
amount: amount, | ||
address: address, | ||
instant: instant | ||
}, true); | ||
} | ||
Bitstamp.prototype.bitcoin_deposit_address = function(callback) { | ||
this._post('bitcoin_deposit_address', callback); | ||
this._post(null, 'bitcoin_deposit_address', callback, null, true); | ||
} | ||
Bitstamp.prototype.unconfirmed_btc = function(callback) { | ||
this._post('unconfirmed_btc', callback); | ||
this._post(null, 'unconfirmed_btc', callback, null, true); | ||
} | ||
// the API documentation is wrong as of `Sat Jun 11 2016 10:10:07`. | ||
// It doesn't corectly list this call. Therefor not sure if all | ||
// arguments are correct. | ||
Bitstamp.prototype.ripple_withdrawal = function(amount, address, currency, callback) { | ||
this._post('ripple_withdrawal', callback, {amount: amount, address: address, currency: currency}); | ||
this._post(null, 'ripple_withdrawal', callback, { | ||
amount: amount, | ||
address: address, | ||
currency: currency | ||
}, true); | ||
} | ||
Bitstamp.prototype.ripple_address = function(callback) { | ||
this._post('ripple_address', callback); | ||
this._post(null, 'ripple_address', callback, null, true); | ||
} | ||
// These API calls return a 404 as of `Thu Oct 31 13:54:19 CET 2013` | ||
// even though they are still in the API documentation | ||
Bitstamp.prototype.create_code = function(usd, btc, callback) { | ||
this._post('create_code', callback, {usd: usd, btc: btc}); | ||
Bitstamp.prototype.transfer_to_main = function(amount, currency, subAccount, callback) { | ||
this._post(null, 'transfer-to-main', callback, { | ||
amount: amount, | ||
currency: currency, | ||
subAccount: subAccount | ||
}, true); | ||
} | ||
Bitstamp.prototype.check_code = function(code, callback) { | ||
this._post('check_code', callback, {code: code}); | ||
Bitstamp.prototype.transfer_from_main = function(amount, currency, subAccount, callback) { | ||
this._post(null, 'transfer-from-main', callback, { | ||
amount: amount, | ||
currency: currency, | ||
subAccount: subAccount | ||
}, true); | ||
} | ||
Bitstamp.prototype.redeem_code = function(code, callback) { | ||
this._post('redeem_code', callback, {code: code}); | ||
} | ||
module.exports = Bitstamp; |
@@ -5,10 +5,11 @@ var Bitstamp = require('./bitstamp.js'); | ||
publicBitstamp.transactions({time: 'hour'}, console.log); | ||
// publicBitstamp.ticker(console.log); | ||
// publicBitstamp.order_book(false, console.log); | ||
// publicBitstamp.transactions('btceur', {time: 'hour'}, console.log); | ||
// publicBitstamp.ticker('btceur', console.log); | ||
// publicBitstamp.ticker_hour('btceur', console.log); | ||
// publicBitstamp.order_book('btcusd', false, console.log); | ||
// publicBitstamp.eur_usd(console.log); | ||
var key = 'your key'; | ||
var secret = 'your secret'; | ||
var client_id = '0'; // your Bitstamp user ID | ||
var key = 'your-key'; | ||
var secret = 'your-secret'; | ||
var client_id = 'your-bitstamp-user-id'; | ||
var privateBitstamp = new Bitstamp(key, secret, client_id); | ||
@@ -18,26 +19,17 @@ | ||
// privateBitstamp.balance(console.log); | ||
// privateBitstamp.user_transactions({limit: 10, offset: 5, sort: 'asc'}, console.log); | ||
// privateBitstamp.open_orders(console.log); | ||
// privateBitstamp.balance(null, console.log); | ||
// privateBitstamp.user_transactions('btceur', {limit: 10, offset: 5, sort: 'asc'}, console.log); | ||
// privateBitstamp.open_orders('btcusd', console.log); | ||
// privateBitstamp.order_status(id, console.log); | ||
// privateBitstamp.cancel_order(id, console.log); | ||
// privateBitstamp.buy(amount, price, console.log); | ||
// privateBitstamp.sell(amount, price, console.log); | ||
// privateBitstamp.cancel_all_orders(console.log) | ||
// privateBitstamp.buy('btcusd', amount, price, limit_price, console.log); | ||
// privateBitstamp.sell('btcusd', amount, price, limit_price, console.log); | ||
// privateBitstamp.withdrawal_requests(console.log); | ||
// privateBitstamp.bitcoin_withdrawal(amount, address, console.log); | ||
// privateBitstamp.bitcoin_deposit_address(console.log); | ||
// privateBitstamp.unconfirmed_btc(console.log()) | ||
// privateBitstamp.ripple_withdrawal(amount, address, currency) | ||
// privateBitstamp.ripple_address(console.log) | ||
// Bistamp is currently (Thu Oct 31 13:54:19 CET 2013) | ||
// returning 404's when doing these calls | ||
// privateBitstamp.create_code(usd, btc, console.log); | ||
// privateBitstamp.check_code(code, console.log); | ||
// privateBitstamp.redeem_code(code, console.log); | ||
// Bistamp is currently (Tue Aug 26 19:31:55 CEST 2014) | ||
// returning 404's when doing these calls | ||
// publicBitstamp.bitinstant(console.log); | ||
// privateBitstamp.unconfirmed_btc(console.log); | ||
// privateBitstamp.ripple_withdrawal(amount, address, currency); | ||
// privateBitstamp.ripple_address(console.log); | ||
// privateBitstamp.transfer_to_main(amount, currency, subAccount, console.log); | ||
// privateBitstamp.transfer_from_main(amount, currency, subAccount, console.log); |
{ | ||
"name": "bitstamp", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Bitstamp REST API wrapper", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,9 +10,14 @@ # Bitstamp | ||
bitstamp.transactions(function(err, trades) { | ||
bitstamp.transactions('btcusd', function(err, trades) { | ||
console.log(trades); | ||
}); | ||
## 0.3.0 - June 2016 update | ||
## 0.1.0 - Big October 2013 update | ||
API v2 is introduced, you now need to pass the market you are interested in. Note that some API calls have changed [and](https://www.bitstamp.net/api/): | ||
> Please note that API v2 endpoints rounding is different, than the one used on the old endpoints. | ||
## 0.1.0 - October 2013 update | ||
The whole private API authentication process looks different now. The result is that you have to provide different information to Bitstamp (generate an API key, provide key, secret and client ID - the last is your Bitstamp user ID). Check out the new examples in `example.js`. | ||
@@ -19,0 +24,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12225
263
38