Comparing version 0.1.0 to 0.1.1
90
index.js
@@ -1,81 +0,25 @@ | ||
/** | ||
* Created by dutu on 2015-01-03. | ||
*/ | ||
var lang = "en"; | ||
var errMsg = require("./lib/errors_" +lang); | ||
var BITSTAMP = require('bitstamp'); | ||
var util = require('lib/util.js'); //custom functions | ||
function Cryptox (exchangeSlug, options) { | ||
var self = this; | ||
var Exchange = require('./lib/' + exchangeSlug); | ||
self.properties = Exchange.prototype.properties; | ||
var exchange; | ||
// TODO: Check exchangeSlug? | ||
exchange = new Exchange(options); | ||
function Cryptox (exchange, apiKey, secret, user_id) { | ||
var self = this; | ||
self.me = "Bitstamp"; | ||
self.config = { | ||
fee: 0.005 | ||
}; | ||
exchange = "bitstamp"; | ||
var bitstampPublic = new BITSTAMP(); | ||
var bitstampPrivate; | ||
if (typeof apiKey === "string" && typeof secret === "string" && typeof user_id === "string" ) { | ||
bitstampPrivate = new BITSTAMP(apiKey, secrrt. user_id); | ||
} else { | ||
bitstampPrivate = null; | ||
self.getTicker = function (options, callback){ | ||
exchange.getTicker(options, function (err, ticker){ | ||
callback(err, ticker); | ||
}); | ||
} | ||
self.getTicker = function(pair, callback) { | ||
var pair = 'BTC_USD'; | ||
bitstampPublic.ticker(function(err, bitstampTicker) { | ||
// https://btc-e.com/apiv1/2/btc_usd/ticker | ||
var newTicker = { | ||
exchange: exchange, | ||
pair: pair, | ||
result: err && err.message || "success" | ||
} | ||
if (!err) { | ||
newTicker["ticker"] = { | ||
timestamp: util.timestamp2string(bitstampTicker.timestamp), | ||
timestring: util.timestamp2string(bitstampTicker.timestamp), | ||
last: parseFloat(bitstampTicker.last), | ||
bid: parseFloat(bitstampTicker.bid), | ||
ask: parseFloat(bitstampTicker.ask), | ||
volume: parseFloat(bitstampTicker.volume) | ||
} | ||
} | ||
callback(newTicker); | ||
}) | ||
}; | ||
self.getOrderBook = function(pair, callback) { | ||
var pair = 'BTC_USD'; | ||
bitstampPublic.order_book(function (err, bitstampOrderBook) { | ||
// https://btc-e.com/apiv1/2/btc_usd/depth | ||
var newOrderBook = { | ||
exchange: exchange, | ||
pair: pair, | ||
result: err && err.message || "success" | ||
} | ||
if (!err) { | ||
newOrderBook["orderbook"] = { | ||
timestamp: util.timestamp2string(bitstampOrderBook.timestamp), | ||
timestring: util.timestamp2string(bitstampOrderBook.timestamp), | ||
asks: [], | ||
bids: [] | ||
} | ||
} | ||
bitstampOrderBook.asks.forEach(function (element, index, asks) { | ||
var price = parseFloat(asks[index][0]); | ||
var volume = parseFloat(asks[index][1]); | ||
var order = new Array(price, volume); | ||
newOrderBook.asks.push(order); | ||
}); | ||
bitstampOrderBook.bids.forEach(function (element, index, asks) { | ||
var price = parseFloat(asks[index][0]); | ||
var volume = parseFloat(asks[index][1]); | ||
var order = new Array(price, volume); | ||
newOrderBook.bids.push(order); | ||
}); | ||
callback(newOrderBook); | ||
self.getFee = function (options, callback){ | ||
exchange.getFee(options, function (err, fee){ | ||
callback(err, fee); | ||
}); | ||
} | ||
} | ||
module.exports = Cryptox; | ||
module.exports = Cryptox; |
{ | ||
"name": "cryptox", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Common API wrapper for multiple crypto currency exchanges", | ||
@@ -34,6 +34,9 @@ "main": "index.js", | ||
"bitstamp": ">=0.1.9", | ||
"moment": "~2.8.4", | ||
"bignumber.js": "~2.0.0", | ||
"lodash": "~2.4.1" | ||
"btc-e": "*", | ||
"moment": ">=2.9.0", | ||
"bignumber.js": ">=2.0.0", | ||
"lodash": "~2.4.1", | ||
"async": ">=0.9.0", | ||
"strscan": "*" | ||
} | ||
} |
221
README.md
cryptox | ||
======= | ||
API wrapper for REST API for multiple crypto currency exchanges | ||
cryptox is a node.js wrapper for REST API for multiple crypto currency exchanges. | ||
cryptox manages API communication with different exchanges and provides common methods for all exchanges. All differences between the different API's are abstracted away. | ||
## Install ## | ||
npm install cryptox | ||
## Example ## | ||
```js | ||
var Cryptox = require('cryptox'); | ||
var account = new Cryptox('bitstamp', {key: 'your_key', secret: 'your_secret', userId: 'your_userId'}); | ||
account.getBalance({}, function(err, balance){ | ||
console.log(balance); | ||
}); | ||
``` | ||
## Supported Exchanges and Implemented methods ## | ||
| | Bitstamp | BitX | BTC-e | CEX.io | | ||
| --- | :-: | :-: | :-: | :-: | | ||
|[getTicker](#getticker) | | | √ | | | ||
|[getOrderBook](#getorderbook) | | | | | | ||
|[getTrades](#gettrades) | | | | | | ||
|[getFee](#getfee) | | | √ | | | ||
|[getTransactions](#gettransactions)| | | | | | ||
|[getBalance](#getbalance) | | | | | | ||
|[getOpenOrders](#getopenorders) | | | | | | ||
|[postSellOrder](#postsellorder) | | | | | | ||
|[postBuyOrder](#postbuyorder) | | | | | | ||
[cancelOrder](#cancelorder) | | | | | | ||
*if you are interested in extending cryptox for different exchange or a method not yet implemented, check out the document [exchanges.md](exchanges.md)* | ||
## Constructor | ||
```js | ||
Cryptox(exchangeSlug [, options]) | ||
``` | ||
#### Parameters | ||
* `exchangeSlug` is required and should have one of the following values in table below. | ||
|Exchange name | `exchangeSlug` | Authentication | | ||
| --- | --- | --- | | ||
| Bitstamp | `'bitstamp'` | `key`, `secret`, `userId` | | ||
| BitX | `'bitx'` | `key`, `secret` | | ||
| BTC-e | `'btce'` | `key`, `secret` | | ||
| CEX.io | `'cexio'` | `key`, `secret`, `userId` | | ||
`key`, `secret` and `userId` are optional and should be used when calling methods / API calls that require authentication. Missing or incorrect key causes an error to be returned when calling a method that requires authentication (see [Authentication](#authentication)). | ||
#### Example | ||
```js | ||
var account = new Cryptox('bitstamp', your_key, your_secret, your_userId); | ||
``` | ||
## Methods | ||
### Callbacks | ||
The arguments passed to the callback function for each method are: | ||
1. `err` is an error object or `null` if no error occurred. | ||
2. `data` is an object containing the data returned by the API | ||
### Authentication | ||
Following methods require authentication | ||
|Method | Requires authentication | | ||
| --- | :-: | | ||
|getTicker | | | ||
|getOrderBook | | | ||
|getTrades | | | ||
|getFee | x | | ||
|getTransactions| x | | ||
|getBalance | x | | ||
|getOpenOrders | x | | ||
|postSellOrder | x | | ||
|placeBuyOrder | x | | ||
|cancelOrder | x | | ||
When calling a method that requires authentication, the object should have been constructed with parameters `key`, `secret` and (optional) `userId`. | ||
### getTicker | ||
Returns the latest ticker indicators | ||
```js | ||
cryptox.getTicker(options, callback); | ||
``` | ||
#### Parameters | ||
* `options` parameter is not used at the moment and can have any value | ||
* `callback` The arguments passed to callback function are | ||
* an `error` object or `null` if no error occured | ||
* an object containing the data returned by the API | ||
```js | ||
{ | ||
timestamp: <number>, | ||
data: { | ||
pair: <string>, // the pair (market) for which the data is applicable | ||
last: <float>, | ||
bid: <float>, | ||
ask: <float>, | ||
volume: <float> | ||
} | ||
} | ||
``` | ||
#### Example | ||
```js | ||
account.getTicker({pair: 'BTCUSD'}, function (err, ticker) { | ||
if (!err) | ||
console.log(ticker); | ||
}); | ||
``` | ||
Result: | ||
```js | ||
{ | ||
"timestamp": 1420935203, | ||
"data": { | ||
"pair": "BTCUSD", | ||
"last": 272.064, | ||
"bid": 272.064, | ||
"ask": 273.395, | ||
"volume": 7087.93047 | ||
} | ||
} | ||
``` | ||
### getOrderBook | ||
Returns a list of bids and asks in the order book. Ask orders are sorted by price ascending. Bid orders are sorted by price descending. Note that multiple orders at the same price are not necessarily conflated. | ||
### getTrades | ||
Returns a list of the most recent trades. | ||
### getFee | ||
```js | ||
cryptox.getFee(options, callback); | ||
``` | ||
Returns a fee, which is a float that represents the amount the exchange takes out of the orders. If an exchange has a fee of 0.2% this would be `0.002`. | ||
#### Parameters | ||
* `options` parameter is not used at the moment and can have any value | ||
* `callback` The arguments passed to callback function are | ||
* an `error` object or `null` if no error occured | ||
* an object containing the data returned by the API | ||
```js | ||
{ | ||
timestamp: <string>, | ||
data: { | ||
pair: <string>, // the pair (market) for which the fee is applicable | ||
fee: <float> // that represents the amount the exchange takes out of the orders | ||
} | ||
} | ||
``` | ||
#### Example | ||
```js | ||
var fee = account.getFee({pair: 'BTCUSD'}, function (err, fee) { | ||
if (!err) | ||
console.log(fee); | ||
}); | ||
``` | ||
Result: | ||
```js | ||
{ | ||
timestamp: '1420766742', | ||
data: { | ||
pair: 'BTCUSD', | ||
fee: 0.002 | ||
} | ||
} | ||
``` | ||
### getTransactions | ||
### getBalance | ||
### getOpenOrders | ||
### postSellOrder | ||
### postBuyOrder | ||
### cancelOrder | ||
# License # | ||
The MIT License (MIT) | ||
Copyright (c) 2015 Adrian Clinciu adrian.clinciu@outlook.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Sorry, the diff of this file is not supported yet
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
35588
17
482
223
7
3
3
1
+ Addedasync@>=0.9.0
+ Addedbtc-e@*
+ Addedstrscan@*
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.23.2.6(transitive)
+ Addedaws-sign2@0.5.0(transitive)
+ Addedbignumber.js@9.1.2(transitive)
+ Addedbl@0.9.5(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedbtc-e@1.0.5(transitive)
+ Addedcaseless@0.8.0(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.1.1(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmime-types@1.0.2(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.5.0(transitive)
+ Addedqs@2.3.3(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedrequest@2.49.0(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrscan@1.0.1(transitive)
+ Addedtldts@6.1.70(transitive)
+ Addedtldts-core@6.1.70(transitive)
+ Addedtough-cookie@5.0.0(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
- Removedbignumber.js@2.0.8(transitive)
- Removedmoment@2.8.4(transitive)
Updatedbignumber.js@>=2.0.0
Updatedmoment@>=2.9.0