3

I need to implement WebSocket synchronization in our Rail project. MetaApi project's use Socket.Io as default support. Only found 2 projects (websocket-client-simple) and outdated with native socket.io. We try to implement this with Faye-Websocket and socketcluster-client-ruby but without success.

Code Example

import ioClient from 'socket.io-client';

const socket = ioClient('https://mt-client-api-v1.agiliumtrade.agiliumtrade.ai', {
    path: '/ws',
    reconnection: false,
    query: {
        'auth-token': 'token'
    }
});

const request = {
  accountId: '865d3a4d-3803-486d-bdf3-a85679d9fad2',
  type: 'subscribe',
  requestId: '57bfbc9f-108d-4131-a300-5f7d9e69c11b'
};

socket.on('connect', () => {
  socket.emit('request', request);
});

socket.on('synchronization', data => {
  console.log(data);
  if (data.type === 'authenticated') {
    console.log('authenticated event received, you can send synchronize now');
  }
});

socket.on('processingError', err => {
  console.error(err);
});
Breno Perucchi
  • 873
  • 7
  • 16

1 Answers1

0

Socket.io protocol is a bit more complicated than a simple websocket connection, with the latter being only one of the used transports, see description in official repository. Websockets are used only after initial http handshake, so you need a somewhat full client.

I'd start with trying to consume events with a js client stub from browser, just to be sure the api is working as you expect and determine used and compatible socket.io versions (current is v4, stale ruby clients are mostly for v1). And you can peek into protocol in browser developer tools.

Once you have a successful session example and have read protocol spec above - it will be easier to craft a minimal client.

Vasfed
  • 18,013
  • 10
  • 47
  • 53