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.2 to 0.2.0

.jshintrc

63

index.js
"use strict";
var path = require("path");
var util = require("./lib/util"); //custom functions
function Cryptox (exchangeSlug, options) {
if (!(this instanceof Cryptox)){
return new Cryptox(exchangeSlug, options); // allow to call constructor without new
}
var self = this;

@@ -10,9 +17,21 @@ var Exchange = require("./lib/" + exchangeSlug);

self.properties = Exchange.prototype.properties;
self.options = options;
self.options = options || {};
if (!self.options.hasOwnProperty("lang"))
self.options["lang"]="en"; // set default language to "en" (english)
var exchange = new Exchange(options);
var exchange = new Exchange(self.options);
var checkMethod = function (methodName) {
if (self.properties.methods.notImplemented.indexOf(methodName) > -1)
return new Error("Method not implemented");
if (self.properties.methods.notSupported.indexOf(methodName) > -1)
return new Error("Method not supported");
return null;
};
self.getRate = function (options, callback){
var err;
if (err = checkMethod("getRate"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getRate(options, function (err, rate){

@@ -24,2 +43,6 @@ callback(err, rate);

self.getTicker = function (options, callback){
var err;
if (err = checkMethod("getTicker"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getTicker(options, function (err, ticker){

@@ -31,2 +54,6 @@ callback(err, ticker);

self.getOrderBook = function (options, callback){
var err;
if (err = checkMethod("getOrderBook"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getOrderBook(options, function (err, orderBook){

@@ -38,2 +65,6 @@ callback(err, orderBook);

self.getTrades = function (options, callback){
var err;
if (err = checkMethod("getTrades"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getTrades(options, function (err, trades){

@@ -45,2 +76,6 @@ callback(err, trades);

self.getFee = function (options, callback){
var err;
if (err = checkMethod("getFee"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getFee(options, function (err, fee){

@@ -52,2 +87,6 @@ callback(err, fee);

self.getTransactions = function (options, callback){
var err;
if (err = checkMethod("getTransactions"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getTransactions(options, function (err, transactions){

@@ -59,2 +98,6 @@ callback(err, transactions);

self.getBalance = function (options, callback){
var err;
if (err = checkMethod("getBalance"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getBalance(options, function (err, balance){

@@ -66,2 +109,6 @@ callback(err, balance);

self.getOpenOrders = function (options, callback){
var err;
if (err = checkMethod("getOpenOrders"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.getOpenOrders(options, function (err, openOrders){

@@ -73,2 +120,6 @@ callback(err, openOrders);

self.postSellOrder = function (options, callback){
var err;
if (err = checkMethod("postSellOrder"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.postSellOrder(options, function (err, orderResult){

@@ -80,2 +131,6 @@ callback(err, orderResult);

self.postBuyOrder = function (options, callback){
var err;
if (err = checkMethod("postBuyOrder"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.postBuyOrder(options, function (err, orderResult){

@@ -87,2 +142,6 @@ callback(err, orderResult);

self.cancelOrder = function (options, callback){
var err;
if (err = checkMethod("cancelOrder"))
return callback(err, {timestamp: util.timestampNow(), error: err.message, data: []});
exchange.cancelOrder(options, function (err, orderResult){

@@ -89,0 +148,0 @@ callback(err, orderResult);

210

lib/bitstamp.js

@@ -21,3 +21,3 @@ "use strict";

self.getRate = function (options, callback) {
self.getTicker(options, function(err, ticker) {
self.getTicker(options, function(err, result) {
var rate, data;

@@ -33,6 +33,6 @@ rate = {

}
rate.timestamp = ticker.timestamp;
rate.timestamp = result.timestamp;
data = {
pair: ticker.data[0].pair,
rate: ticker.data[0].last
pair: result.data[0].pair,
rate: result.data[0].last
};

@@ -48,27 +48,24 @@ rate.data.push(data);

bitstampPublic.ticker(function(err, bitstampTicker) {
if (err) {
ticker = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
} else {
ticker = {
timestamp: util.timestamp(bitstampTicker.timestamp),
error: "",
data: []
};
data = {
pair: self.properties.markets[0].pair,
last: parseFloat(bitstampTicker.last),
bid: parseFloat(bitstampTicker.bid),
ask: parseFloat(bitstampTicker.ask),
volume: parseFloat(bitstampTicker.volume),
high: parseFloat(bitstampTicker.high),
low: parseFloat(bitstampTicker.low),
vwap: parseFloat(bitstampTicker.vwap)
};
ticker.data.push(data);
}
callback(err, ticker);
ticker = {
timestamp: util.timestampNow(),
error: err && err.message || "",
data: []
};
if (err)
return callback(err, ticker);
// var jf = require("jsonfile"); jf.writeFileSync(__dirname + "/MockApiResponse.json", bitstampTicker); // only used to create MockApiResponse file for the test unit
ticker.timestamp = util.timestamp(bitstampTicker.timestamp);
data = {
pair: self.properties.instruments[0].pair,
last: parseFloat(bitstampTicker.last),
bid: parseFloat(bitstampTicker.bid),
ask: parseFloat(bitstampTicker.ask),
volume: parseFloat(bitstampTicker.volume),
high: parseFloat(bitstampTicker.high),
low: parseFloat(bitstampTicker.low),
vwap: parseFloat(bitstampTicker.vwap)
};
ticker.data.push(data);
callback(null, ticker);
})

@@ -80,35 +77,33 @@ }

bitstampPublic.order_book(function (err, bitstampOrderBook) {
https://www.bitstamp.net/api/order_book/
// https://www.bitstamp.net/api/order_book/
var price, volume, order;
orderBook = {
timestamp: util.timestampNow(),
error: err && err.message || "",
data: []
};
if (err) {
orderBook = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
} else {
orderBook = {
timestamp: util.timestamp(bitstampOrderBook.timestamp),
error: "",
data: []
return callback(err, orderBook);
};
orderBook.timestamp = util.timestamp(bitstampOrderBook.timestamp);
data = {
pair: self.properties.instruments[0].pair,
asks: [],
bids: []
};
orderBook.data.push(data);
bitstampOrderBook.asks.forEach(function (element, index, asks) {
order = {
price: parseFloat(asks[index][0]),
volume: parseFloat(asks[index][1])
};
data = {
pair: self.properties.markets[0].pair,
asks: [],
bids: []
orderBook.data[0].asks.push(order);
});
bitstampOrderBook.bids.forEach(function (element, index, bids) {
order = {
price: parseFloat(bids[index][0]),
volume: parseFloat(bids[index][1])
};
orderBook.data.push(data);
bitstampOrderBook.asks.forEach(function (element, index, asks) {
price = parseFloat(asks[index][0]);
volume = parseFloat(asks[index][1]);
order = new Array(price, volume);
orderBook.data[0].asks.push(order);
});
bitstampOrderBook.bids.forEach(function (element, index, asks) {
price = parseFloat(asks[index][0]);
volume = parseFloat(asks[index][1]);
order = new Array(price, volume);
orderBook.data[0].bids.push(order);
});
}
orderBook.data[0].bids.push(order);
});
callback(err, orderBook);

@@ -120,3 +115,3 @@ });

var trades;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
trades = {

@@ -126,3 +121,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, trades);

@@ -132,10 +127,23 @@ }

self.getFee = function (options, callback) {
var fee;
var err = new Error("Method not implemented")
fee = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, fee);
bitstampPrivate.balance(function (err, bitstampBalance) {
var fee, data;
if (!err && bitstampBalance.error)
err = new Error(bitstampBalance.error);
fee = {
timestamp: util.timestampNow(),
error: err && err.message || "",
data: []
};
if (err) {
return callback(err, fee);
}
// var jf = require("jsonfile"); jf.writeFileSync(__dirname + "/MockApiResponse.json", bitstampBalance); // only used to create MockApiResponse file for the test unit
data = {
pair: "",
maker_fee: parseFloat(bitstampBalance.fee) / 100, // note that Bitstamp native API call returns 0.2 for 0.2%
taker_fee: parseFloat(bitstampBalance.fee) / 100
};
fee.data.push(data);
callback(err, fee);
});
}

@@ -145,3 +153,3 @@

var transactions;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
transactions = {

@@ -151,3 +159,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, transactions);

@@ -157,10 +165,32 @@ }

self.getBalance = function (options, callback) {
var balance;
var err = new Error("Method not implemented")
balance = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, balance);
bitstampPrivate.balance(function (err, bitstampBalance) {
var balance, data, amount;
balance = {
timestamp: util.timestampNow(),
error: err && err.message || "",
data: []
};
if (err) {
return callback(err, balance);
}
// var jf = require("jsonfile"); jf.writeFileSync(__dirname + "/MockApiResponse.json", bitstampBalance); // only used to create MockApiResponse file for the test unit
data = {
total: [],
available: []
};
amount = parseFloat(bitstampBalance.btc_balance);
if (amount)
data.total.push({currency: "XBT", amount: amount});
amount = parseFloat(bitstampBalance.usd_balance);
if (bitstampBalance.usd_balance)
data.total.push({currency: "USD", amount: amount});
amount = parseFloat(bitstampBalance.btc_available);
if (amount)
data.available.push({currency: "XBT", amount: amount});
amount = parseFloat(bitstampBalance.usd_available);
if (amount)
data.available.push({currency: "USD", amount: amount});
balance.data.push(data);
callback(null, balance);
});
}

@@ -170,3 +200,3 @@

var openOrders;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
openOrders = {

@@ -176,3 +206,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, openOrders);

@@ -183,3 +213,3 @@ }

var orderResult;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
orderResult = {

@@ -189,3 +219,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, orderResult);

@@ -196,3 +226,3 @@ }

var orderResult;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
orderResult = {

@@ -202,3 +232,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, orderResult);

@@ -209,3 +239,3 @@ }

var orderResult;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
orderResult = {

@@ -215,3 +245,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, orderResult);

@@ -224,5 +254,9 @@ }

slug: "bitstamp", // slug name of the exchange. Needs to be the same as the .js filename
markets: [ // all allowed currency/asset combinatinos (pairs) that form a market
methods: {
notImplemented: ["getTrades", "getTransactions", "getOpenOrders", "postSellOrder", "postBuyOrder", "cancelOrder"],
notSupported: [],
},
instruments: [ // all allowed currency/asset combinatinos (pairs) that form a market
{
pair: "USDBTC"
pair: "XBTUSD"
}

@@ -229,0 +263,0 @@ ],

@@ -5,2 +5,3 @@ "use strict";

var BITX = require("bitx");
var _ = require("lodash");

@@ -46,9 +47,5 @@ var util = require("./util"); //custom functions

// TODO: return all tickers when pair parameter is not specidfied
var ticker, data;
var bitxPair, bitxPublic;
if (typeof options.pair === "string")
bitxPair = options.pair.replace("BTC", "XBT");
else
bitxPair = "";
bitxPublic = new BITX({pair: bitxPair});
var ticker, data, bitxPair, bitxPublic;
bitxPublic = new BITX({pair: options.pair});
bitxPublic.getTicker(function(err, bitxTicker) {

@@ -70,3 +67,3 @@ // https://api.mybitx.com/api/1/tickers

data = {
pair: bitxPair.replace("XBT", "BTC"),
pair: options.pair,
last: parseFloat(bitxTicker.last_trade),

@@ -84,42 +81,37 @@ bid: parseFloat(bitxTicker.bid),

self.getOrderBook = function (options, callback) {
var orderBook, data;
var bitxPair;
if (typeof options.pair === "string")
bitxPair = options.pair.replace("BTC", "XBT");
else
bitxPair = "";
bitxPublic.getOrderBook(function (err, bitxOrderBook) {
var orderBook, data, pair;
pair = typeof options.pair === "string" && {pair: options.pair} || {pair: "nopair"};
bitxPublic.getOrderBook(pair, function (err, bitxOrderBook) {
https://api.mybitx.com/api/1/orderbook?pair=XBTZAR
var price, volume, order;
orderBook = {
timestamp: util.timestampNow(),
error: err && err.message || "",
data: []
}
if (err) {
orderBook = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
} else {
orderBook = {
timestamp: util.timestamp(bitxOrderBook.timestamp),
error: "",
data: []
return callback(err, orderBook);
}
// var jf = require("jsonfile"); jf.writeFileSync(__dirname + "/MockApiResponse.json", bitxOrderBook); // only used to create MockApiResponse file for the test unit
orderBook.timestamp = util.timestamp(bitxOrderBook.timestamp);
data = {
pair: options.pair,
asks: [],
bids: []
};
orderBook.data.push(data);
bitxOrderBook.asks.forEach (function (element, index, asks) {
order = {
price: parseFloat(asks[index].price),
volume: parseFloat(asks[index].volume)
};
data = {
pair: "",
asks: [],
bids: []
orderBook.data[0].asks.push(order);
});
bitxOrderBook.bids.forEach (function (element, index, bids) {
order = {
price: parseFloat(bids[index].price),
volume: parseFloat(bids[index].volume)
};
orderBook.data.push(data);
bitxOrderBook.asks.forEach (function (element, index, asks) {
var price = parseFloat(asks[index].price);
var volume = parseFloat(asks[index].volume);
var order = new Array(price, volume);
orderBook.data[0].asks.push(order);
});
bitxOrderBook.bids.forEach (function (element, index, bids) {
var price = parseFloat(bids[index].price);
var volume = parseFloat(bids[index].volume);
var order = new Array(price, volume);
orderBook.data[0].bids.push(order);
});
}
orderBook.data[0].bids.push(order);
});
callback(err, orderBook);

@@ -129,89 +121,59 @@ });

self.getTrades = function (options, callback) {
var trades;
var err = new Error("Method not implemented");
trades = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, trades);
}
self.getFee = function (options, callback) {
var fee;
var err = new Error("Method not implemented");
var fee, data;
fee = {
timestamp: util.timestampNow(),
error: err.message,
error: "",
data: []
}
callback(err, fee);
};
data = {
pair: "",
maker_fee: self.properties.maker_fee, // fee is hardcodded and fixed
taker_fee: self.properties.taker_fee
};
fee.data.push(data);
callback(null, fee);
}
self.getTransactions = function (options, callback) {
var transactions;
var err = new Error("Method not implemented");
transactions = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, transactions);
}
self.getBalance = function (options, callback) {
var balance;
var err = new Error("Method not implemented");
balance = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, balance);
}
// TODO: Confirm if "balance" include "available"
bitxPrivate.getBalance(function (err, xBalance) {
var balance, data, amount;
balance = {
timestamp: util.timestampNow(),
error: "",
data: []
};
if (err) {
balance.error = err.message;
return callback(err, balance);
}
self.getOpenOrders = function (options, callback) {
var openOrders;
var err = new Error("Method not implemented");
openOrders = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, openOrders);
}
xBalance.balance.forEach(function (element, index, bal) {
var accountIndex, newAccount, balanceElement;
balanceElement = {
account_id: element.account_id,
total: {currency: element.asset, amount: parseFloat(element.balance)},
available: {currency: element.asset, amount: parseFloat(element.balance) - parseFloat(element.reserved)}
};
accountIndex = _.findIndex(balance.data, {account_id: balanceElement.account_id});
self.postSellOrder = function (options, callback) {
var orderResult;
var err = new Error("Method not implemented");
orderResult = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, orderResult);
if (accountIndex > -1) {
util.updateBalanceArray(balance.data[accountIndex].total, balanceElement.total);
util.updateBalanceArray(balance.data[accountIndex].available, balanceElement.available);
} else {
newAccount = {
account_id: balanceElement.account_id,
total: [],
available: []
};
newAccount.total.push(balanceElement.total);
newAccount.available.push(balanceElement.available);
balance.data.push(newAccount);
}
});
callback(err, balance);
});
}
self.postBuyOrder = function (options, callback) {
var orderResult;
var err = new Error("Method not implemented");
orderResult = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, orderResult);
}
self.cancelOrder = function (options, callback) {
var orderResult;
var err = new Error("Method not implemented");
orderResult = {
timestamp: util.timestampNow(),
error: err.message,
data: []
}
callback(err, orderResult);
}
}

@@ -222,12 +184,16 @@

slug: "bitx", // slug name of the exchange. Needs to be the same as the .js filename
markets: [ // all allowed currency/asset combinatinos (pairs) that form a market
methods: {
notImplemented: ["getTrades", "getTransactions", "getOpenOrders", "postSellOrder", "postBuyOrder", "cancelOrder"],
notSupported: [],
},
instruments: [ // all allowed currency/asset combinatinos (pairs) that form a market
// check on https://api.mybitx.com/api/1/tickers
{
pair: "BTCKES"
pair: "XBTKES"
},
{
pair: "BTCZAR"
pair: "XBTZAR"
},
{
pair: "BTCMYR"
pair: "XBTMYR"
}

@@ -248,4 +214,6 @@ ],

tradeError: "", //if not able to trade at this exchange, please set it to an URL explaining the problem
maker_fee: 0, // fee is hardcoded and fixed
taker_fee: 0.01, // fee is hardcoded and fixed
}
module.exports = Bitx;

@@ -63,3 +63,3 @@ "use strict";

data: []
}
};
} else {

@@ -85,3 +85,3 @@ ticker = {

self.getOrderBook = function (options, callback) {
var orderBook, data;
var orderBook, data, order;
var btcePair = pairMap(options.pair);

@@ -95,3 +95,3 @@ btcePublic.depth(btcePair, function (err, btceDepth) {

data: []
}
};
} else {

@@ -105,7 +105,20 @@ orderBook = {

pair: pairMap(btcePair),
asks: btceDepth.asks,
bids: btceDepth.bids
asks: [],
bids: []
};
orderBook.data.push(data);
btceDepth.asks.forEach(function (element, index, asks) {
order = {
price: element[0],
volume: element[1]
};
orderBook.data[0].asks.push(order);
});
btceDepth.bids.forEach(function (element, index, bids) {
order = {
price: element[0],
volume: element[1]
};
orderBook.data[0].bids.push(order);
});
}

@@ -118,3 +131,3 @@ callback(err, orderBook);

var trades;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
trades = {

@@ -124,3 +137,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, trades);

@@ -130,21 +143,28 @@ }

self.getFee = function (options, callback) {
var fee, err, data, fixedFee
fixedFee = self.properties.fee; // fee is hardcodded and fixed
err = null;
fee = {
timestamp: util.timestampNow(),
error: "",
data: []
}
data = {
pair: options.pair,
fee: fixedFee
};
fee.data.push(data);
callback(err, fee);
}
var fee, data;
var btcePair = pairMap(options.pair);
btcePublic.fee(btcePair, function (err, btceFee) {
// https://btc-e.com/api/2/btc_usd/fee
fee = {
timestamp: util.timestampNow(),
error: "",
data: []
};
if (err) {
fee.error = err.message;
return callback(err, fee);
}
data = {
pair: pairMap(btcePair),
maker_fee: btceFee.trade / 100,
taker_fee: btceFee.trade / 100
};
fee.data.push(data);
callback(null, fee);
});
};
self.getTransactions = function (options, callback) {
var transactions;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
transactions = {

@@ -154,3 +174,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, transactions);

@@ -161,8 +181,9 @@ }

var balance;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
balance = {
account_id: "",
timestamp: util.timestampNow(),
error: err.message,
data: []
}
};
callback(err, balance);

@@ -178,8 +199,2 @@ }

};
if (!btcePrivate) {
var err = new Error("API key not specified");
openOrders.error = err.message;
callback(err, openOrders);
return;
}
if (options && options.hasOwnProperty("pair")) {

@@ -191,2 +206,3 @@ pair = pairMap(options["pair"])

if (!err) {
// var jf = require("jsonfile"); jf.writeFileSync(__dirname + "/MockApiResponse.json", result); // only used to create MockApiResponse file for the test unit
var activeOrders = result["return"];

@@ -200,3 +216,3 @@ for (var record in activeOrders) {

rate: activeOrders[record].rate, // 444.064
status: activeOrders[record].status, // 0
status: activeOrders[record].status.toString(), // 0
created_at: util.timestamp(activeOrders[record].timestamp_created) // 1396619879

@@ -217,3 +233,3 @@ };

var orderResult;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
orderResult = {

@@ -223,3 +239,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, orderResult);

@@ -230,3 +246,3 @@ }

var orderResult;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
orderResult = {

@@ -236,3 +252,3 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, orderResult);

@@ -243,3 +259,3 @@ }

var orderResult;
var err = new Error("Method not implemented")
var err = new Error("Method not implemented");
orderResult = {

@@ -249,7 +265,7 @@ timestamp: util.timestampNow(),

data: []
}
};
callback(err, orderResult);
}
var pairMap = function (pairString) { // converts pairString to different format
var pairMap = function (pair) { // converts pairString to different format
// (to map string format used by cryptox pair to/from format used by btc-e npm module

@@ -260,14 +276,16 @@ // Example "BTCUSD" to "btc_usd" or "btc_usd" to "BTCUSD"

var currency1, currency2;
if (typeof pairString !== "string")
if (typeof pair !== "string")
return "";
if(pairString.length == 6) {
currency1 = pairString.slice(0,3).toLowerCase();
currency2 = pairString.slice(3).toLowerCase();
if(pair.length == 6) {
currency1 = pair.slice(0,3).replace("XBT", "BTC").toLowerCase();
currency2 = pair.slice(3).replace("XBT", "BTC").toLowerCase();
return currency1 + "_" + currency2;
}
//Example "btc_usd" to "BTCUSD"
var currency = pairString.split("_");
var currency = pair.split("_");
if(currency.length != 2)
return pairString;
return currency[0].toUpperCase() + currency[1].toUpperCase();
return pair;
return currency[0].toUpperCase().replace("BTC", "XBT") + currency[1].toUpperCase().replace("BTC", "XBT");
};

@@ -279,56 +297,73 @@ }

slug: "btce", // slug name of the exchange. Needs to be the same as the .js filename
markets: [ // all allowed currency/asset combinatinos (pairs) that form a market
methods: {
notImplemented: ["getTrades", "getTransactions",
"getBalance", "postSellOrder", "postBuyOrder", "cancelOrder"],
notSupported: [],
},
instruments: [ // all allowed currency/asset combinatinos (pairs) that form a market
{
pair: "USDBTC"
pair: "XBTUSD"
},
{
pair: "RURBTC"
pair: "XBTRUR"
},
{
pair: "EURBTC"
pair: "XBTEUR"
},
{
pair: "LTCBTC"
pair: "XBTCNH"
},
{
pair: "XBTGPB"
},
{
pair: "LTCXBT"
},
{
pair: "LTCUSD"
},
{
pair: "RURLTC"
pair: "LTCRUR"
},
{
pair: "EURLTC"
pair: "LCTEUR"
},
{
pair: "BTCNMC"
pair: "LCTCNH"
},
{
pair: "USDNMC"
pair: "LCTGPB"
},
{
pair: "BTCNVC"
pair: "NMCXBT"
},
{
pair: "USDNVC"
pair: "NMCUSD"
},
{
pair: "RURUSD"
pair: "NVCXBT"
},
{
pair: "USDEUR"
pair: "NVCUSD"
},
{
pair: "BTCTRC"
pair: "USDRUR"
},
{
pair: "BTCPPC"
pair: "EURUSD"
},
{
pair: "USDPPC"
pair: "EURRUR"
},
{
pair: "BTCFTC"
pair: "USDCHN"
},
{
pair: "BTCXPM"
pair: "GBPUSD"
},
{
pair: "PPCXBT"
},
{
pair: "PPCUSD"
}

@@ -349,5 +384,6 @@ ],

tradeError: "", //if not able to trade at this exchange, please set it to an URL explaining the problem
fee: 0.002 // fee is hardcoded and fixed to 0.2%
maker_fee: 0.002, // fee is hardcoded and fixed to 0.2%
taker_fee: 0.002, // fee is hardcoded and fixed to 0.2%
}
module.exports = Btce;

@@ -10,8 +10,12 @@ "use strict";

"invalid api key": "Invalid API key", // BTC-e API
"BitX error 401: Unauthorized\n": "Invalid API key", // BitX API
"Must provide API key and secret to use the trade API.": "API key not specified", //BTC-e API
"invalid parameter: pair" : "Invalid currency pair", // BTC-e API
"Invalid currency pair.": "Invalid currency pair", // BitX API
"Invalid currency pair": "Invalid currency pair", // cryptox/oxr.js
"Invalid currency pair": "Invalid currency pair", // cryptox/lib/oxr.js, cryptox/lib/bitfinex.js
"Unknown symbol": "Invalid currency pair", // bitfinex npm module
"Empty pair list": "Empty pair list", // BTC-e API
"Invalid currency code.": "Invalid currency code", // BitX API
}
}
exports.errors = locales;

@@ -147,3 +147,8 @@ "use strict";

slug: "newExchangeTemplate", // slug name of the exchange. Needs to be the same as the .js filename
markets: [ // all allowed currency/asset combinatinos (pairs) that form a market
methods: {
notImplemented: ["getRate", "getTicker", "getOrderBook", "getTrades", "getFee", "getTransactions",
"getBalance", "getOpenOrders", "postSellOrder", "postBuyOrder", "cancelOrder"],
notSupported: [],
},
instruments: [ // all allowed currency/asset combinatinos (pairs) that form a market
{

@@ -150,0 +155,0 @@ pair: "USDBTC"

@@ -166,3 +166,8 @@ "use strict";

slug: "oxr", // slug name of the exchange. Needs to be the same as the .js filename
markets: [ // all allowed currency/asset combinatinos (pairs) that form a market
methods: {
notImplemented: ["getRate"],
notSupported: [, "getTicker", "getOrderBook", "getTrades", "getFee", "getTransactions",
"getBalance", "getOpenOrders", "postSellOrder", "postBuyOrder", "cancelOrder"],
},
instruments: [ // all allowed currency/asset combinatinos (pairs) that form a market
],

@@ -169,0 +174,0 @@ publicAPI: {

@@ -11,16 +11,16 @@

// the function takes two arguments
// balance, array of item amounts/prices {"unit": unit, "amount": amount}
// balance, both array of item amounts/prices {"currency": currency, "amount": amount}
// new items, array of item amounts/prices
//function returns a new balance array, with item.amount added to corresponding items.
var newBalance = [];
var unitIndex, unit, amount, i;
var unitIndex, currency, amount, i;
for (i = 0; i < balance.length; i++)
if (balance[i].amount != 0)
newBalance.push({unit: balance[i].unit, amount: balance[i].amount});
newBalance.push({currency: balance[i].currency, amount: balance[i].amount});
for (i = 0; i < newItems.length; i++) {
unit = newItems[i].unit;
currency = newItems[i].currency;
amount = newItems[i].amount;
if (unit && amount) {
unitIndex = _.findIndex(newBalance, {"unit": unit}); // check if unit in newItems is present in the balance
if (currency && amount) {
unitIndex = _.findIndex(newBalance, {"currency": currency}); // check if currecny in newItems is present in the balance
if (unitIndex == -1)

@@ -27,0 +27,0 @@ //if not found, add it

{
"name": "cryptox",
"version": "0.1.2",
"version": "0.2.0",
"description": "Common API wrapper for multiple crypto currency exchanges",

@@ -10,3 +10,3 @@ "main": "index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},

@@ -20,2 +20,3 @@ "repository": {

"api",
"bitfinex",
"bitstamp",

@@ -26,5 +27,7 @@ "bitx",

"crypto",
"exchange"
"exchange",
"open exchange rates",
"api"
],
"author": "adrian.clinciu@outlook.com",
"author": "Adrian Clinciu <adrian.clinciu@outlook.com>",
"license": "MIT",

@@ -36,12 +39,21 @@ "bugs": {

"dependencies": {
"bitstamp": ">=0.1.9",
"bitstamp": "0.1.9",
"btc-e": "*",
"moment": ">=2.9.0",
"bignumber.js": ">=2.0.0",
"lodash": "~2.4.1",
"lodash": "*",
"async": ">=0.9.0",
"strscan": "*",
"bitx": ">=1.4.1",
"open-exchange-rates" : ">=0.3.0"
"bitx": ">=1.4.3",
"open-exchange-rates" : ">=0.3.0",
"bitfinex": ">=0.3.3"
},
"devDependencies": {
"chai": ">= 1.6.1 < 2",
"mocha": ">=2.1.0",
"sinon": ">=1.12.2",
"nock": ">=0.59.1",
"jsonfile": ">=2.0.0",
"chai-json-schema": ">=1.1.0"
}
}
cryptox
=======
[![Build Status](https://travis-ci.org/dutu/cryptox.svg)](https://travis-ci.org/dutu/cryptox/) ![Dependencies Status](https://david-dm.org/dutu/cryptox.svg)
**cryptox** is a node.js wrapper for REST API for multiple crypto currency exchanges.

@@ -11,18 +13,7 @@

* [Install](#install)
* [Example](#example)
* [Supported Exchanges and Implemented Methods](#supportedexchangesandimplementedmethods)
* [Changelog](#changelog)
* [Use](#use)
* [Supported Exchanges and Implemented Methods](#supported-exchanges-and-implemented-methods)
* [ChangeLog](#changelog)
* [Documentation](#documentation)
* [Constructor](#constructor)
* [Methods](#methods)
* [getTicker](#getticker)
* [getOrderBook](#getorderbook)
* [getTrades](#gettrades)
* [getFee](#getfee)
* [getTransactions](#gettransactions)
* [getBalance](#getbalance)
* [getOpenOrders](#getopenorders)
* [postSellOrder](#postsellorder)
* [postBuyOrder](#postbuyorder)
* [cancelOrder](#cancelorder)
* [FAQ](#faq)
* [License](#license)

@@ -38,3 +29,3 @@

# Example #
# Use #

@@ -84,15 +75,15 @@ ```js

|Bitfinex|Bitstamp |BitX|BTC-e|CEX.io|OXR<sup>1</sup>|
--- | :-: | :-: |:-: | :-: | :-: | :-: |
[getrate](#getrate) | | FI | FI | FI | | FI |
[getTicker](#getticker) | | FI | FI | FI | | — |
[getOrderBook](#getorderbook) | | FI | FI | FI | | — |
[getTrades](#gettrades) | | | | | | — |
[getFee](#getfee) | | | | FI | | — |
[getTransactions](#gettransactions)| | | | | | — |
[getBalance](#getbalance) | | | | | | — |
[getOpenOrders](#getopenorders) | | | | FI | | — |
[postSellOrder](#postsellorder) | | | | | | — |
[postBuyOrder](#postbuyorder) | | | | | | — |
[cancelOrder](#cancelorder) | | | | | | — |
| |Bitfinex|Bitstamp |BitX|BTC-e|CEX.io|OXR <sup>[1]</sup>|
| --- | :-: | :-: |:-: | :-: | :-: | :-: |
|[getRate](#getrate) | FI | FI | FI | FI | | FI |
|[getTicker](#getticker) | FI | FI | FI | FI | | — |
|[getOrderBook](#getorderbook) | FI | FI | FI | FI | | — |
|[getTrades](#gettrades) | | | | | | — |
|[getFee](#getfee) | | FI | FI | FI | | — |
|[getTransactions](#gettransactions)| | | | | | — |
|[getBalance](#getbalance) | FI | FI | FI | | | — |
|[getOpenOrders](#getopenorders) | | | | FI | | — |
|[postSellOrder](#postsellorder) | | | | | | — |
|[postBuyOrder](#postbuyorder) | | | | | | — |
|[cancelOrder](#cancelorder) | | | | | | — |

@@ -103,11 +94,11 @@

> **PI** = Partially Implemented (refer to notes below)
> **—** = Not Supported
> **—** = Not Supported
><sup>1</sup> OXR ([Open Exchange Rates](https://openexchangerates.org/)) is not a crypto exchange, however it provides exchange rates for world fiat currencies
><sup>[1]</sup> OXR ([Open Exchange Rates](https://openexchangerates.org/)) is not a crypto exchange, however it provides exchange rates for world fiat currencies
# Changelog
# ChangeLog
> **cryptox** module uses semver (http://semver.org/) for versioning: MAJOR.MINOR.PATCH.
> cryptox module adheres to [Semantic Versioning] (http://semver.org/) for versioning: MAJOR.MINOR.PATCH.
> 1. MAJOR version increments when non-backwards compatible API changes are introduced

@@ -120,3 +111,3 @@ > 2. MINOR version increments when functionality in a backwards-compatible manner are introduced

See detailed [Changelog](changelog.md)
See detailed [ChangeLog](CHANGELOG.md)

@@ -126,401 +117,10 @@

## Constructor
See [API documentation](docs/api_documentation.md)
Creates an instance of `Cryptox` object type.
# FAQ
```js
Cryptox(exchangeSlug [, options])
```
See [FAQ](docs/faq.md)
Depending on the parameters used, two types of objects can be created
1. **public** (without authentication) - can be used for calling public API methods
2. **private** (with authentication) - can be used for calling public and private API methods
#### Examples
```js
var account = new Cryptox("btce", {key: "yourKey", secret: "yourSecret"});
```
```js
var exchange = new Cryptox("btce");
```
#### Arguments
* `exchangeSlug` is required and should have one values in table below
* `options` is used to pass parameters required for authentication, as indicated in table below
|Exchange name | `exchangeSlug` | Authentication |
| --- | --- | --- |
| Bitstamp | `"bitstamp"` | `key`, `secret`, `username` |
| BitX | `"bitx"` | `key`, `secret` |
| BTC-e | `"btce"` | `key`, `secret` |
| CEX.io | `"cexio"` | `key`, `secret`, `username` |
| Open Exchange Rates | `"oxr"` | `key` |
`options` should be used when calling methods that require authentication. Missing or incorrect key causes an error to be returned when calling a method that requires authentication (see [Authentication](#authentication)).
## Methods
#### Examples
```js
getTicker(options, callback);
```
```js
getTicker({pair: "BTCUSD"}, function (err, result) {
if (!err)
console.log(result);
});
```
### Arguments
* `options` is a JSON object containing parameters specific for each API call
* `callback` is executed inside the method once the API response is received from the exchange
#### Callbacks
The arguments passed to the callback function for each method are:
* `err` is an error object or `null` if no error occurred.
* `result` is JSON object containing the response.
Example result:
```js
{
"timestamp": "2015-02-03T00:01:48+00:00",
"error": "",
"data": [
{
"pair": "BTCUSD",
"last": 272.064,
"bid": 272.064,
"ask": 273.395,
"volume": 7087.93047
}
]
}
```
| Type | Description
--- | --- | ---
`timestamp` | string | ISO 8601 date & time
`error` | string | error message or `""` if no error
`data` | array | array of one or more JSON objects containig the API result
### Authentication
Following methods require authentication
|Method | Requires authentication |
| --- | :-: |
|getRate | <sup>1</sup> |
|getTicker | |
|getOrderBook | |
|getTrades | |
|getFee | x<sup>2</sup> |
|getTransactions| x |
|getBalance | x |
|getOpenOrders | x |
|postSellOrder | x |
|placeBuyOrder | x |
|cancelOrder | x |
><sup>1</sup> Open Exchange Rates (OXR) requires authentication
><sup>2</sup> BTC-e does not require authentication for `getFee` (since the fee is fixed amount)
When calling a method that requires authentication, the object should have been constructed with parameters `key`, `secret` and (optional) `userId`.
### getRate
Returns the exchange rate.
```js
getRate(options, callback);
```
#### Example
```js
exchange.getRate({pair: "EURUSD"}, function (err, rate) {
if (!err)
console.log(rate);
});
```
Example result:
```js
{
"timestamp": "2015-02-04T20:01:09+00:00",
"error": "",
"data": [
{
"pair": "USDEUR",
"rate": 1.149807,
}
]
}
```
#### Arguments
* `options`
Parameter | Type | Required for | Description |
--- | --- | :-: | --- |
`pair` | string | All | trading pair|
* `callback` see [Callbacks](#callbacks)
#### Response
Parameter | Type | Description
--- | --- | ---
`pair` | String | trading pair
`rate` | Number | rate
### getTicker
Returns the latest ticker indicators.
```js
getTicker(options, callback);
```
#### Example
```js
exchange.getTicker({pair: "BTCUSD"}, function (err, ticker) {
if (!err)
console.log(ticker);
});
```
Example result:
```js
{
"timestamp": "2015-02-03T00:01:48+00:00",
"error": "",
"data": [
{
"pair": "BTCUSD",
"last": 272.064,
"bid": 272.064,
"ask": 273.395,
"volume": 7087.93047
}
]
}
```
#### Arguments
* `options`
Parameter | Type | Required for | Description |
--- | --- | :-: | --- |
`pair` | string | BTC-e | trading pair|
* `callback` see [Callbacks](#callbacks)
#### Response
Parameter | Type | Description
--- | --- | ---
`pair` | String | trading pair
`last` | Number | last price
`bid` | Number | highest buy order
`ask` | Number | lowest sell order
`volume` | Number | last 24 hours volume
Optional response parameters
Parameter / Availability | Type | Description
--- | --- | ---
`high`<sup>1</sup> | Number | last 24 hours price high
`low`<sup>1</sup> | Number | last 24 hours price low
`vwap`<sup>1</sup> | Number | last 24 hours [volume weighted average price](http://en.wikipedia.org/wiki/Volume-weighted_average_price)
> <sup>1</sup> Bitstamp
### 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.
```js
cryptox.getOrderBook(options, callback);
```
#### Example
```js
exchange.getOrderBook({pair: "BTCUSD"}, function (err, orderBook) {
if (!err)
console.log(orderBook);
});
```
Example result:
```js
{
"timestamp": ""2015-02-03T00:01:48+00:00"",
"error": "",
"data": [
{
"pair": "BTCUSD",
"asks": [[212.962,0.014],[213,1.46820994],[213.226,3.78630967]],
"bids": [[212.885,0.014],[212.827,0.00414864],[212.74,6.685]]
}
]
}
```
#### Arguments
* `options`
Parameter | Type | Required | Description |
--- | --- | :-: | --- |
`pair` | string |All exchanges| trading pair|
* `callback` see [Callbacks](#callbacks)
#### Response
Parameter | Type |Required| Description |
--- | --- | :-: | --- |
`timestamp` | String | Yes | server time, ISO 8601 string |
`error` | Boolean | Yes | error message or `""` if no error |
`pair` | String | Yes | trading pair |
`asks` | Array | Yes | list of asks in the order book |
`bids` | Array | Yes | list of bids in the order book |
### getTrades
Returns a list of the most recent trades.
### getFee
```js
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`.
#### Example
```js
account.getFee({pair: "BTCUSD"}, function (err, fee) {
if (!err)
console.log(fee);
});
```
Example result:
```js
{
timestamp: "2015-02-01T20:59:53+00:00",
data: [
{
pair: "BTCUSD",
fee: 0.002
}
]
}
```
#### Arguments
* `options` parameter is not used at the moment and can have any value
* `callback` see [Callbacks](#callbacks)
### getTransactions
### getBalance
### getOpenOrders
```js
getOpenOrders(options, callback);
```
Returns the open orders
#### Example
```js
account.getOpenOrders({pair: "LTCUSD"}, function (err, openOrders) {
if (!err)
console.log(openOrders);
});
```
Example result:
```js
{
"timestamp": "2015-02-03T00:03:27+00:00",
"error": "",
"data": [
{
"orderId": "563489985",
"pair": "LTCUSD",
"type": "buy",
"amount": 1,
"rate": 0.1,
"status": 0,
"timestamp": "2015-02-01T19:23:15+00:00"
},
{
"orderId": "563612426",
"pair": "LTCUSD",
"type": "buy",
"amount": 2,
"rate": 0.5,
"status": 0,
"timestamp": "2015-02-01T20:59:53+00:00"
}
]
}
```
#### Arguments
* `options`
Parameter | Type | Required | Description |
--- | --- | :-: | --- |
`pair` | string | No | trading pair|
* `callback` see [Callbacks](#callbacks)
### 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.
[MIT](LICENSE)

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