Skip to content

Connection

Connect

Users must connect to the server using a socket (i.e. websocket). It's crucial to set the path parameter to /interactive?socket.io during the connection. Tokens are only available after a successful login, so ensure you log in before attempting to connect to the server via socket.

let socket = socketIoClient(url, {
   path: '/interactive/socket.io',
   query: {
     token: token,
     userID: userID,
   }
 }); 

The URL provided is the REST API address for connecting to the interactive server (e.g., www.test.example.com). Once connected, you can listen for various events from the server, such as connect, joined, error, order, trade, position, logout, and disconnect. Below is an example of one such connect event.

 socket.on('connect', function () {
    console.info("interactive socket connected successfully!");
 }); 

Joined

If a connection to the server is successfully established, this event will be triggered to indicate that a user has connected.

 socket.on('joined', function (data) {
  console.info("interactive socket joined successfully!");
 }); 

Error

If there's an error with the server, this event will be triggered alongside the cause of the error. For instance, if you provide an incorrect token while connecting, the server will raise this event and disconnect your socket connection.

 socket.on('error', function (data) {
  console.info("interactive error:" + data);
 }); 

Disconnect

If a socket disconnection occurs with the server, this event will be raised to indicate that the disconnection has happened.

socket.on('disconnect', function () {
    console.info("interactive socket connected successfully!");
 });