Introduction

Ginses provides low-latency institutional quality markets data that covers a wide range of online tradable assets for over 20000+ assets. To see the full list of asset classes, please visit https://ginses.com/#assetClass. This service is offered for Ginses clients and subscribers. Please visit our pricing section for more details. If you didn’t find what you are looking for, please don’t hesitate to contact us.

Servers location

Ginses currently has servers in several regions globally. Your requests will automatically be routed to the one nearest to your origin. You can check the latency by pinging you account’s assigned servers.

$ ping [Assigned Server - e.g., wss29.ginses.com]

Timestamp format

All timestamps are unix/epoch timestamps (seconds that have passed since since January 1, 1970 UTC). If you require different format and need help converting timestamps to a different formats, please contact us.

WebSocket Support

Introduction to WebSocket and Socket.IO

User expectations have changed a lot over the last couple of years we now live in an age where it is expected that content is instant and data is live. Web technology has improved and using WebSockets can now offer two-way (or full-duplex) data transfer between client and server.

The prime goal of WebSockets is to provide live data transfer over a persistent TCP socket connection.

To summarise how the protocol works: The client makes a request to the server and the server responds with a handshake, Once the client and the server have shaken hands so to speak they are free to send information back and forth at will.

All the data transfer takes place over a single TCP Socket and can be done on Port 80(WS) or Port 443(WSS), Most browsers now support WebSockets you can see if you browser support web sockets on this site.

Socket.IO is a WebSocket implementation wrapper that aids in the setup of WebSockets. Why make it hard when you can make it easy.

Conclusion

WebSocket vs Socket.IO, not really much to say WebSockets are the protocol and Socket.IO is the quickest most robust method to get them implemented.

Getting started

This implementation is written in NodeJS and would be a good implementation to run on the server-side to leverage the real-time data for your app users, it is also possible to write a client that renders real-time data using FE libraries, such as React.js, Angular and Vue.js. We offer technical support and custom development services starting at $75 per hour.

Node.js client-side Example

This example makes a connection to the server, receives a handshake event and transmits the subscription token, it then receives an onConnect. The onConnect function then subscribes to a symbol (asset) and then waits for the response. When the application receives the socket.on event it reads the message and then outputs it to the console.

Please visit socket.io official documentation for further details.

Download and Install NodeJS

Windows:

Download and install NodeJS from here https://nodejs.org

Linux:

$ apt-get install nodejs

Install Socket.IO

$ npm install socket.io-client

Code

Create a connection and send handshake to the server:

const io = require('socket.io-client');

const SocketOptions = {
  upgrade: false,
  transports: ['websocket'],
  reconnect: true
};

const socket = io(SOCKET_SERVER_URL, SocketOptions);

Once the connection is made to the server, the server will send a “connect” event to receive this you will need a function with the identifier “connect”.

Ginses service requires further authentication and subscription events. When the “connect” event is received the client must send the subscription token message.

socket.on('connect', function () {
    console.log('Connected!');
    socket.emit('ginsesToken', SUBSCRIPTION_TOKEN);
});

After the authentication event is sent and as long as the subscription token is correct the server will respond with a ‘handshake’ event, This confirms that the server is connected and ready for the client to request data.

Subscribe to assets (ticks)

Once the connection is initiated, the client can subscribe by sending the asset’s symbol. e.g. “EURUSD, FB, APPL, BTCUSD”

socket.emit('reSubscribe', ["BTCUSD", "EURUSD", "APPL", "FB"]);

Resubscribe to assets (amend subscribed assets list)

If the client is already subscribed, it is possible to resubscribe to change the list of assets by sending a new subscription. Ginses server will automatically unsubscribe the unwanted assets and subscribe to the new ones.

socket.emit('reSubscribe', ["GBPUSD", "XAUUSD", "FB"]);

Ginses server will respond to this request with the assets-related data is in json format (Binary format is available upon request – contact us):

socket.on('quotes', quotes => console.log(quotes));
42["quotes",[{"s":"BTCUSD","p":2,"lev":1,"t":1593431925471,"b":"9070.26","bD":-1,"a":"9140.13","aD":1,"l":"9054.12","h":"9140.52"},{"s":"EURUSD","p":5,"lev":30,"t":1593431925267,"l":"1.11683","h":"1.12544","b":"1.12810","bD":0,"a":"1.12810","aD":1}]]

Subscribe to historical data (OHLC/last tick)

Once the connection is initiated, the client can subscribe by emitting the following:

  • To receive candles/OHLC:
socket.emit('graphHistory', CANDLES_LIMIT, SYMBOL);
// Example
socket.emit('graphHistory', 5000, "SPX");
  • To receive the latest candle/s or subscribe to the live updates within the same session:
history.emit('tickCandle', INTERVAL, ACCEPTED_SLIPPAGE);
// Example (INTERVAL and ACCEPTED_SLIPPAGE are in ms)
history.emit('tickCandle', 100, 1000);

Example