Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cryptox

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cryptox - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

exchanges.md

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": "*"
}
}
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc