Websocket

Websocket API Specs and Mapping Specifications

This is NTerminal’s documentation for a custom Websocket API. For full API documentation, please refer to the Splunk REST API and SDK resources. Most of the events clients receive are real-time events. NTerminal will start streaming real-time events once you establish the connection and until you disconnect. NTerminal will transmit all information that is available from the sources your token is subscribed to. Filtering is also available. In some cases you will get periodic updates (spot pricing) while others will arrive as soon as the platform sees them (trade quotes).

Standardized fields and static trading venue information is also available. For source-specific information and dynamic updates on trading venues and other sources, please use our REST API.

Connecting

ParameterValue
Websocket URIwss://ws.nterminal.com/v1/stream
Custom handshake headerX-INCA-TOKEN: token

Request example

websocat wss://ws.nterminal.com/v1/stream -H 'X-INCA-TOKEN: <insert_token>'

Response examples

Trades

{
"type":"trade",
"time_exchange":"2019-04-04T15:36:37.4300000Z",
"price":85.34,
"volume":0.5,
"taker_side":"BUY",
"market_venue":"COINBASE",
"symbol":"LTC",
"base":"USD"
}

Quotes

{
"type":"quote",
"time_exchange":"2019-04-04T16:01:11.9200297Z",
"ask_price":556730.0,
"ask_size":0.12,
"bid_price":551845.0,
"bid_size":0.4,
"market_venue":"KRAKEN",
"symbol":"BTC",
"base":"JPY"
}

Event filtering

Event filtering is available by 4 fields: market_venue, symbol, base, and type (quote or trade).

All parameters are optional. Filter parameters are specified in the URI in the query part. Parameters can contain either a single element or a list.

wss://ws.nterminal.com/v1/stream?market_venue=KRAKEN&symbol=BTC,ETH

C++ Client Code Snippet

The example below shows how to connect and read one message in blocking mode. This is not a production ready code and you may consider scaling concerns for high-load applications.

#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>

int main()
{
   std::string const host = "ws.nterminal.com";
   std::string const path = "/stream";
   std::string const port = "443";
   std::string const token = "<Enter your token>";
   std::string const cert  = "<Enter your certificate>";

   boost::asio::io_context ioc;
   boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23_client};

   boost::system::error_code ec;
   ctx.add_certificate_authority(boost::asio::buffer(cert.data(), cert.size()), ec);
   if(ec)
       return 1;

   boost::asio::ip::tcp::resolver resolver{ioc};
   boost::beast::websocket::stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> ws{ioc, ctx};

   auto const results = resolver.resolve(host, port);


   boost::asio::connect(ws.next_layer().next_layer(), results.begin(), results.end());
   SSL_set_tlsext_host_name(ws.next_layer().native_handle(), host.c_str());
   ws.next_layer().handshake(boost::asio::ssl::stream_base::client);
   ws.handshake_ex(host, path,
                   [&token](boost::beast::websocket::request_type& m)
                   {
                       m.insert("X-INCA-TOKEN", token);
                   });

   boost::beast::static_buffer<256> buffer;

   auto b = buffer.prepare(256);
   ws.read_some(b);

   std::cout << boost::beast::buffers_to_string(b) << std::endl;

   ws.close(boost::beast::websocket::close_code::normal);


   return 0;
}