NAV
Shell HTTP JavaScript Node.JS PHP Ruby Python Java GO
  • Getting started
  • Authentication
  • REST APIs
  • WebSockets
  • Standards and Conventions
  • Errors and Rate Limits
  • WebSockets

    Crypto Market Data

    Crypto APIs provides WebSockets with real time data (trades, exchange rates, etc.) from top crypto exchanges (you can check the list of supported exchanges in REST APIs > Crypto Market Data > List All Exchanges)

    General

    Address

    Crypto APIs WebSockets is located on wss://ws.cryptoapis.io

    Limitations

    Init Message

    Example Init message

    
    {
        "type": "init",
        "api_key": "Your API key",
        "heartbeat": true,
        "subscribe_to_exchanges_ids": ["5b1ea9d21090c200146f7393", "5bc0893ea6f99f00093f0202"],
        "event_type": ["FUTURES", "OPTION", "SPOT"],
        "base_asset_ids": ["5b1ea92e584bf50020130612"],
        "quote_asset_ids": ["5b1ea92e584bf5002013064d"],
        "trades": true,
        "direction": ["BUY"],
        "exchange_rates": true,
        "order_book": true
    }
    
    
    
    const WebSocket = require('ws');
    
    var initMsg = {
        type: "init",
        api_key: "Your API key",
        heartbeat: true,
        subscribe_to_exchanges_ids: ["5b1ea9d21090c200146f7393", "5bc0893ea6f99f00093f0202"],
        event_type: ["FUTURES", "OPTION", "SPOT"],
        base_asset_ids: ["5b1ea92e584bf50020130612"],
        quote_asset_ids: ["5b1ea92e584bf5002013064d"],
        trades: true,
        direction: ["BUY"],
        exchange_rates: true,
        order_book: true
    };
    
    const ws = new WebSocket('wss://ws.cryptoapis.io');
    
    ws.on('open', function open() {
        ws.send(JSON.stringify(initMsg));
    });
    
    ws.on('message', function incoming(message) {
        console.log(message);
    });
    
    

    When your WebSocket connection is established, you must send an Init message which contains:

    Filter Description
    subscribe_to_exchanges_ids Array with exchanges IDs. Send empty array or do not include this filter if you want to receive data for all exchanges.
    event_type Type of symbol (possible values are: SPOT, FUTURES, OPTION or any combination of them)
    base_asset_ids Array with base asset IDs.
    quote_asset_ids Array with quote asset IDs.
    direction Initiator of the transaction - BUY, SELL or both.
    trades Optional. Boolean value for trades subscription (possible values are true or false). Default is true.
    exchange_rates Optional. Boolean value for exchange rates subscription (possible values are true or false). Default is false.
    order_book Optional. Boolean value for order book subscription (possible values are true or false). Default is false.

    All filters are optional. You will receive all data related to any filter if you skip it.

    Update filters

    Example Update message

    
    {
        "type": "update_filters",
        "direction": ["SELL"]
    }
    
    

    You must send "update_filters" as type of the message and all filters you want to update. Filters will take effect immediately after the update message is received successfully.

    Heartbeat

    You will receive heartbeat message on every 15 seconds if there aren't other messages and if you requested it in the Init message.

    Errors

    Error message JSON

    
    {
        "type": "error",
        "message": "Invalid API key"
    }
    
    

    You will receive error message if you send something wrong or if you reach any of the WebSockets limitations. The connection will be interrupted after the error message is received. You will need to re-connect.

    Messages

    Trades

    Trade message JSON

    
    { 
        "message_type": "trade",
        "exchangeId": "5bc0893ea6f99f00093f0202",
        "type": "SPOT",
        "baseAssetId": "5b1ea92e584bf50020130619",
        "quoteAssetId": "5b1ea92e584bf50020130615",
        "eventTime": 1541078887070,
        "price": 0.45387,
        "amount": 1521.4952,
        "direction": "SELL"
    }
    
    

    Message data:

    Variable Description
    message_type Message type - "trade"
    exchangeId ID of the exchange
    type Trade type - SPOT, FUTURES or OPTION
    baseAssetId Base asset ID
    quoteAssetId Quote asset ID
    eventTime Time of trade
    price Price
    amount Base asset amount
    direction Initiator of the transaction - BUY or SELL

    Exchange rates

    Exchange rate message JSON

    
    { 
        "message_type": "exchange_rate",
        "baseAsset": "5b1ea92e584bf50020130619",
        "weightedAveragePrice": 0.46381,
        "medianPrice": 0.43262,
        "weightedMedianAveragePrice": 0.45387,
        "timestamp": 1560328329
    }
    
    

    Message data:

    Variable Description
    message_type Message type - "exchange_rate"
    baseAsset Base asset ID
    weightedAveragePrice Exchange rate between base asset and USD calculated by weighted average of the last trades in every exchange for the last 24 hours by giving more weight to exchanges with higher volume
    medianPrice Exchange rate between base asset and USD calculated by median of the last trades in every exchange for the last 24 hours
    weightedMedianAveragePrice Exchange rate between base asset and USD calculated by median of the last trades in every exchange for the last 24 hours by giving more weight to exchanges with higher volume. Range of the prices is being adjusted by calculating percentage of wrong (extremely low or extremely high) prices
    timestamp Time (in UNIX Timestamp) of the market data used to calculate exchange rate

    Order book

    Order book message JSON

    
    { 
        "message_type": "order_book",
        "timestamp": "1565947559209",
        "exchange_id": "5bc0893ea6f99f00093f0202",
        "base_asset": "5b1ea92e584bf50020130621",
        "quote_asset": "5b1ea92e584bf50020130612",
        "symbol": "tEOSBTC",
        "symbol_id": "BITFINEX_SPOT_EOS_BTC",
        "depth": {
            "bids": [
                {
                    "price": 0.00035391,
                    "amount": 100
                },
                {
                    "price": 0.00035381,
                    "amount": 154.90625
                },
                {
                    "price": 0.00035377999,
                    "amount": 1108.8
                },
                {
                    "price": 0.00035356,
                    "amount": 18.743822
                },
                {
                    "price": 0.00035347999,
                    "amount": 278.70001
                },
                {
                    "price": 0.00035332001,
                    "amount": 279.5
                },
                {
                    "price": 0.00035330001,
                    "amount": 844.75977
                },
                {
                    "price": 0.00035322999,
                    "amount": 424.44922
                },
                {
                    "price": 0.00035302,
                    "amount": 8463.502
                },
                {
                    "price": 0.00035300999,
                    "amount": 240
                },
                {
                    "price": 0.00035299,
                    "amount": 1000
                },
                {
                    "price": 0.00035297999,
                    "amount": 843.65973
                },
                {
                    "price": 0.00035297,
                    "amount": 1660
                },
                {
                    "price": 0.00035295999,
                    "amount": 279.70001
                },
                {
                    "price": 0.00035292999,
                    "amount": 300
                },
                {
                    "price": 0.00035290001,
                    "amount": 60
                }
            ],
            "asks": [
                {
                    "price": 0.00035280001,
                    "amount": 1746.9125
                },
                {
                    "price": 0.00035285999,
                    "amount": 750
                },
                {
                    "price": 0.00035307999,
                    "amount": 564.5896
                },
                {
                    "price": 0.00035282999,
                    "amount": 33.59
                },
                {
                    "price": 0.00035320001,
                    "amount": 564.53064
                },
                {
                    "price": 0.00035297999,
                    "amount": 278.89999
                },
                {
                    "price": 0.00035325999,
                    "amount": 993.32196
                },
                {
                    "price": 0.00035327999,
                    "amount": 145.94701
                },
                {
                    "price": 0.00035329,
                    "amount": 145.93811
                },
                {
                    "price": 0.00035309,
                    "amount": 564.65039
                },
                {
                    "price": 0.00035337999,
                    "amount": 145.92632
                },
                {
                    "price": 0.00035339,
                    "amount": 145.68997
                },
                {
                    "price": 0.00035330001,
                    "amount": 417.10001
                },
                {
                    "price": 0.00035344,
                    "amount": 145.72464
                },
                {
                    "price": 0.00035349,
                    "amount": 145.70616
                },
                {
                    "price": 0.00035341,
                    "amount": 564.65039
                },
                {
                    "price": 0.00035352001,
                    "amount": 564.58765
                },
                {
                    "price": 0.00035352999,
                    "amount": 145.93222
                },
                {
                    "price": 0.00035354,
                    "amount": 145.94043
                },
                {
                    "price": 0.00035355001,
                    "amount": 145.74513
                },
                {
                    "price": 0.00035346,
                    "amount": 564.70898
                },
                {
                    "price": 0.00035357001,
                    "amount": 564.65039
                },
                {
                    "price": 0.00035376,
                    "amount": 711.70001
                },
                {
                    "price": 0.00035273001,
                    "amount": 350
                },
                {
                    "price": 0.00035382999,
                    "amount": 18.629471
                },
                {
                    "price": 0.00035384999,
                    "amount": 1006.2
                },
                {
                    "price": 0.00035279,
                    "amount": 5052.6113
                },
                {
                    "price": 0.00035389999,
                    "amount": 18.61434
                },
                {
                    "price": 0.00035392001,
                    "amount": 48
                },
                {
                    "price": 0.00035387001,
                    "amount": 18.635611
                },
                {
                    "price": 0.00035392999,
                    "amount": 878.79999
                },
                {
                    "price": 0.00035394001,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035394999,
                    "amount": 18.595854
                },
                {
                    "price": 0.00035396,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035406,
                    "amount": 18.566944
                },
                {
                    "price": 0.00035397001,
                    "amount": 154.90625
                },
                {
                    "price": 0.00035412001,
                    "amount": 202.60516
                },
                {
                    "price": 0.00035409001,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035449999,
                    "amount": 27.52648
                },
                {
                    "price": 0.00035409999,
                    "amount": 202.60516
                },
                {
                    "price": 0.00035451,
                    "amount": 86.485138
                },
                {
                    "price": 0.00035411,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035397999,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035399001,
                    "amount": 221.17233
                },
                {
                    "price": 0.00035399999,
                    "amount": 18.576475
                },
                {
                    "price": 0.00035401,
                    "amount": 202.60516
                },
                {
                    "price": 0.00035402001,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035456999,
                    "amount": 1700
                },
                {
                    "price": 0.00035402999,
                    "amount": 422.80368
                },
                {
                    "price": 0.00035404001,
                    "amount": 202.60516
                }
            ]
        }
    }
    
    

    Message data:

    Variable Description
    message_type Message type - "order_book"
    timestamp Time (in UNIX timestamp) of snapshot generation reported by exchange
    exchange_id Our identifier (UID) of the exchange where symbol is traded
    base_asset Our identifier (UID) of the base asset. (_id attribute from assets endpoint)
    quote_asset Our identifier (UID) of the quote asset. (_id attribute from assets endpoint)
    symbol Exchange symbol identifier
    symbol_id Our symbol identifier, see table below for format description
    depth Depth of exchange for Book Snapshot level of 50
    bids Latest 50 bid levels in order from best to worst
    asks Latest 50 ask levels in order from best to worst
    price Price of the bid/ask
    amount Available amount of base to quote asset at the given price

    Heartbeat

    Heartbeat message JSON

    
    {
        "type": "heartbeat"
    }
    
    

    The heartbeat message is received every 15 seconds if there aren't other messages and if you require it in the Init message.