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

Common API wrapper for multiple crypto currency exchanges

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-45%
Maintainers
1
Weekly downloads
 
Created
Source

cryptox

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. Differences between the different API's are abstracted away.

Contents

Install

npm install cryptox

Example

var Cryptox = require("cryptox");
var account = new Cryptox("btce", {key: "your_key", secret: "your_secret"});
	
account.getOpenOrders({pair: "LTCUSD"}, function (err, openOrders) {
    if (!err)
	    console.log(openOrders);
});

Example result:

{
    "timestamp": "2015-02-03T00:03:27+00:00",
    "error": "",
    "data": [
        {
            "order_id": "563489985",
            "pair": "LTCUSD",
            "type": "buy",
            "amount": 1,
            "rate": 0.1,
            "status": 0,
            "created_at": "2015-02-01T19:23:15+00:00"
        },
        {
            "order_id": "563612426",
            "pair": "LTCUSD",
            "type": "buy",
            "amount": 2,
            "rate": 0.5,
            "status": 0,
            "created_at": "2015-02-01T20:59:53+00:00"
        }        
    ]
}

Supported Exchanges and Implemented methods

if you are interested in extending cryptox for different exchange or a method not yet implemented, check out the document exchanges.md

                               |Bitfinex|Bitstamp      |BitX|BTC-e|CEX.io|OXR<sup>1</sup>| 

--- | :-: | :-: |:-: | :-: | :-: | :-: | getrate | | FI | FI | FI | | FI | getTicker | | FI | FI | FI | | — | getOrderBook | | FI | FI | FI | | — | getTrades | | | | | | — | getFee | | | | FI | | — | getTransactions| | | | | | — | getBalance | | | | | | — | getOpenOrders | | | | FI | | — | postSellOrder | | | | | | — | postBuyOrder | | | | | | — | cancelOrder | | | | | | — |

FI = Fully Implemented
FR = Fully Implemented, but restrictions apply (refer to notes below)
PI = Partially Implemented (refer to notes below)
= Not Supported

1 OXR (Open Exchange Rates) is not a crypto exchange, however it provides exchange rates for world fiat currencies

Changelog

cryptox module uses semver (http://semver.org/) for versioning: MAJOR.MINOR.PATCH.

  1. MAJOR version increments when non-backwards compatible API changes are introduced
  2. MINOR version increments when functionality in a backwards-compatible manner are introduced
  3. PATCH version increments when backwards-compatible bug fixes are made

IMPORTANT NOTE: Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

See detailed Changelog

Documentation

Constructor

Creates an instance of Cryptox object type.

Cryptox(exchangeSlug [, options])

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
var account = new Cryptox("btce", {key: "yourKey", secret: "yourSecret"});
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 nameexchangeSlugAuthentication
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).

Methods

Examples
getTicker(options, callback);
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:

    {
        "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

MethodRequires authentication
getRate1
getTicker
getOrderBook
getTrades
getFeex2
getTransactionsx
getBalancex
getOpenOrdersx
postSellOrderx
placeBuyOrderx
cancelOrderx

1 Open Exchange Rates (OXR) requires authentication
2 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.

getRate(options, callback);
Example
exchange.getRate({pair: "EURUSD"}, function (err, rate) {
    if (!err)
        console.log(rate);
});

Example result:

{
    "timestamp": "2015-02-04T20:01:09+00:00",
    "error": "",
    "data": [
        {
            "pair": "USDEUR",
            "rate": 1.149807,
        }
     ]
}
Arguments
  • options
ParameterTypeRequired forDescription
pairstringAlltrading pair
Response
ParameterTypeDescription
pairStringtrading pair
rateNumberrate

getTicker

Returns the latest ticker indicators.

getTicker(options, callback);
Example
exchange.getTicker({pair: "BTCUSD"}, function (err, ticker) {
    if (!err)
        console.log(ticker);
});

Example result:

{
    "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
ParameterTypeRequired forDescription
pairstringBTC-etrading pair
Response
ParameterTypeDescription
pairStringtrading pair
lastNumberlast price
bidNumberhighest buy order
askNumberlowest sell order
volumeNumberlast 24 hours volume

Optional response parameters

Parameter / AvailabilityTypeDescription
high1Numberlast 24 hours price high
low1Numberlast 24 hours price low
vwap1Numberlast 24 hours volume weighted average price

1 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.

cryptox.getOrderBook(options, callback);
Example
exchange.getOrderBook({pair: "BTCUSD"}, function (err, orderBook) {
    if (!err)
        console.log(orderBook);
});

Example result:

{
    "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
ParameterTypeRequiredDescription
pairstringAll exchangestrading pair
Response
ParameterTypeRequiredDescription
timestampStringYesserver time, ISO 8601 string
errorBooleanYeserror message or "" if no error
pairStringYestrading pair
asksArrayYeslist of asks in the order book
bidsArrayYeslist of bids in the order book

getTrades

Returns a list of the most recent trades.

getFee

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
account.getFee({pair: "BTCUSD"}, function (err, fee) {
    if (!err)
	    console.log(fee);
});

Example result:

{ 
	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

getTransactions

getBalance

getOpenOrders

getOpenOrders(options, callback);

Returns the open orders

Example
account.getOpenOrders({pair: "LTCUSD"}, function (err, openOrders) {
    if (!err)
	    console.log(openOrders);
});

Example result:

{
    "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
ParameterTypeRequiredDescription
pairstringNotrading pair

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.

Keywords

FAQs

Package last updated on 04 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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