Connecting to the Stream Endpoints

The Stream API provides a stream of live match data as JSON over a WebSocket connection. Please see the below for how to connect to the stream endpoint.

The process for connecting to the stream endpoints and receiving data is always the same:

● Connect to the SSL websocket address ● Send JSON packet containing API token

Format to send API token:

{"authToken": "authentication token"}

● Receive response indicating that the connection is authorised (or else a response indicating why the connection cannot be made) ● Receive heartbeat packets every 10 seconds to verify that the connection is live ● Receive data packets

Once you have sent the API token, any further data that you send over the connection will be ignored.

Security protocol: Please note that we currently we do not support SSL. We only support the use of TLS Version 1.2+.

The code below shows how to make the connection using Java. It uses the following dependencies but you can use any libraries you wish:

Java

org.glassfish.tyrus / tyrus-client / 1.11
javax.websocket / javax.websocket-api / 1.1

Then use the following code:

Java

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger;
import org.glassfish.tyrus.client.ClientManager;
import javax.websocket.*;
@ClientEndpoint
public class WSClient {
    private static final String HOST = "???";
    private static final String EVENT_ID = "???";
    private static final String WS_ENDPOINT =
"wss://"+HOST+"/events/"+EVENT_ID+"/stream";
    private static final String TOKEN = "???";
    private Logger logger = Logger.getLogger(this.getClass().getName());
    private static CountDownLatch latch;
    @OnOpen
    public void onOpen(Session session) {
        logger.info("Connected ... " + session.getId());
        try {
            session.getBasicRemote().sendText("{\"authToken\": \"" + TOKEN + "\"}");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
}
    @OnMessage
    public void onMessage(String message, Session session) {
        logger.info(message);
    }
    @OnClose
    public void onClose(Session session, CloseReason closeReason) {
        logger.info(String.format("Session %s close because of %s", session.getId(),
                closeReason));
        latch.countDown();
    }
    public static void main(String[] args) {
        latch = new CountDownLatch(1);
        ClientManager client = ClientManager.createClient();
        try {
            client.connectToServer(WSClient.class, new URI(WS_ENDPOINT));
            latch.await();
        } catch (DeploymentException | URISyntaxException | InterruptedException e) {
            throw new RuntimeException(e);
} }
}

In Java, to send a Web request via a SSL-based protocol (i.e. HTTPS or WSS) one has to add the signed certificate to the keystroke ‘ jssecacerts’ for the specific domain as alias. For that the utility Java program ‘ InstallCert.java’ is used:

Java

To compile and run:

Java

When it asks for the input, press ‘ 1 ’. After this step, the informed domain will be added as a trusted keystore, and a file called “ jssecacerts“ will be generated.

Finally,this“ jssecacerts”fileneedstobecopiedtoyour“$ JAVA_HOME/jre/lib/security” folder.

The code below shows how to make the connection using Javascript. It assumes you already have a variable named token holding your API token:

Java

We can provide code samples in other languages on request.

A Test Server for event streams is also available for testing purpose. To be able to consume events coming from the Test Server one can connect via WebSocket following the steps above and point to the endpoint containing the matchId as “2 015-999-XX999”:

Java

The test feed will play a real historical match (with the names of the players modified). The match events are sent in an interval of 5 secs with heartbeats messages every 10 secs.

"startPosition" parameter

Note that you can pass the "startPosition=*" parameter in the websocket, where "*" refers to the sequence number the connection should start from. i,e: wss://dde-streams.data.imgarena.com/tennis/events/2024-XXXX-MSXXX/stream?startPosition=100 The websocket feed will start the at sequence number 100 instead of 0.

Polling limits

IMG Arena monitor the incoming traffic from our customers and strive to ensure that traffic is controlled, in-keeping with our guidelines and not unnecessarily excessive. We would suggest a polling rate of 10 requests per second measured over a 5 minute interval. Note that this rate limit is across all of our legacy sports and endpoints. If you break this late limit, your requests will start to get throttled, for more information, please contact [email protected]envelope

Last updated

Was this helpful?