Fantasy Match Points via WebSocket

Fantasy Match Points via WebSocket

Match information available through the Fantasy Match Points API endpoint, automatically updated and delivered to your client systems in real-time through WebSocket protocol.

Send a Subscription Request

You can subscribe to the matches individually for receiving automatic updates using the Fantasy Match Points Subscribe API. The Sample snippet below demonstrates how to send a subscription request from the Fantasy Match Points Subscribe API. Please note that subscribing twice to the same match does not mean that you will be charged twice, or you will receive the same update twice. Additionally, please be aware that the maximum allowed connections per project via WebSocket would be 20.

Fantasy Match Points Subscribe - Websocket

terminal
pip install requests
pip install requests
icon copy
Python
import requests project_key = 'YOUR_PROJ_KEY' token = 'YOUR_ACCESS_TOKEN' match_key = 'ausind_2020_odi01' url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/subscribe/".format(project_key,match_key) headers = { 'rs-token': token } payload = { 'method': "web_socket" } response = requests.post(url, headers=headers, json=payload) print(response.json())
import requests

project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/subscribe/".format(project_key,match_key)
headers = {
    'rs-token': token
}
payload = {
    'method': "web_socket"
}
response = requests.post(url, headers=headers, json=payload)

print(response.json())
icon copy

Handling the data received

The Sample snippet below demonstrates how to handle the data received through a simple WebSocket client.

Fantasy Websocket

// client.js var io = require('socket.io-client') // connect to roanuz sports server var socket = io.connect('http://socket.sports.roanuz.com/cricket', {path:'/v5/websocket', reconnect: true}) // Add a connect listener socket.on('connect', function (socket) { console.log('Connected!') }) // prepare required data to access the match data var data = {} data.token = 'YOUR_ACCESS_TOKEN' // token data.match_key = 'MATCH_KEY' // match key // emit signal to connect to the room socket.emit('connect_to_fantasy_match_points', data) // server emits 'on_match_joined' socket.on('on_fantasy_match_points_joined', function (data) { console.log('Cricket match joined!', data.key) }) // the subscribed match content are emitted with 'on_match_update' event // since it's gzipped data, parse it to unzip it socket.on('on_fantasy_match_points_update', function (res) { console.log('data received') console.log(JSON.parse(res)) }) // emits 'on_error' on, //match not subscribed socket.on('on_error', function (data) { console.log('not_subscribed', JSON.parse(data)) })
// client.js
var io = require('socket.io-client')
// connect to roanuz sports server
var socket = io.connect('http://socket.sports.roanuz.com/cricket', {path:'/v5/websocket', reconnect: true})

// Add a connect listener
socket.on('connect', function (socket) {
  console.log('Connected!')
})
// prepare required data to access the match data
var data = {}
data.token = 'YOUR_ACCESS_TOKEN' // token
data.match_key = 'MATCH_KEY' // match key
// emit signal to connect to the room
socket.emit('connect_to_fantasy_match_points', data)
// server emits 'on_match_joined'
socket.on('on_fantasy_match_points_joined', function (data) {
  console.log('Cricket match joined!', data.key)
})
// the subscribed match content are emitted with 'on_match_update' event
// since it's gzipped data, parse it to unzip it
socket.on('on_fantasy_match_points_update', function (res) {
  console.log('data received')
  console.log(JSON.parse(res))
})
// emits 'on_error' on,
//match not subscribed
socket.on('on_error', function (data) {
  console.log('not_subscribed', JSON.parse(data))
})
icon copy

Unsubscribing from a match

For any reasons, if you wish to opt-out of receiving automatic updates for a match, you can do so by placing an unsubscribe request from the Fantasy Match Points Unsubscribe API.

Fantasy Match Points Unsubscribe - Websocket

terminal
pip install requests
pip install requests
icon copy
Python
import requests project_key = 'YOUR_PROJ_KEY' token = 'YOUR_ACCESS_TOKEN' match_key = 'ausind_2020_odi01' url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/unsubscribe/".format(project_key,match_key) headers = { 'rs-token': token } payload = { 'method': "web_socket" } response = requests.post(url, headers=headers, json=payload) print(response.json())
import requests

project_key = 'YOUR_PROJ_KEY'
token = 'YOUR_ACCESS_TOKEN'
match_key = 'ausind_2020_odi01'
url = "https://api.sports.roanuz.com/v5/cricket/{}/fantasy-match-points/{}/unsubscribe/".format(project_key,match_key)
headers = {
    'rs-token': token
}
payload = {
    'method': "web_socket"
}
response = requests.post(url, headers=headers, json=payload)

print(response.json())
icon copy