Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Anchor
    AblyChannel
    AblyChannel
    Ably Channel - Channels are the medium through which messages are distributed. Clients attach to channels to subscribe to messages, and every message published to a unique channel is broadcast by Ably to all subscribers. This messaging pattern is commonly called the https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern. You can read more about Ably Channels here.

  • Access Token - Ably’s authentication token required to establish a connection with Ably. You can learn more about this /wiki/spaces/FEED/pages/3248259146 here.

  • Client Library - Ably’s public open-source SDKs provided to clients to simplify the software development work required by users of Ably. More information is available here.

...

Inc drawio
zoom1
simplefalse
inComment0
custContentId3247997270
pageId3172204626custContentId3247997270
lboxtrue
diagramDisplayNamematch-state-platform.drawio
contentVer2
baseUrlhttps://geniussports.atlassian.net/wiki
diagramName1622725815413-match-state-platform.drawio
pCenter0
aspectZezcWV2CNMKGn_PsqsVd 1
width621
linksauto
tbstyletop
isUpload1
height166

...

Before you can start using the code below you will need to get the following secrets from Genius Sports Support Team:

  • Client ID

  • Client Secret

  • API Key

To access uat environment, add .uat to the URLs documented in the section below:
https://uat.auth.api.geniussports.com/oauth2/token
https://platform.uat.matchstate.api.geniussports.com/api/v1

1. Obtaining an Access Token for the Match State Platform API

...

Code Block
languagec#
var url = "https://auth.api.geniussports.com/oauth2/token";
var body = new Dictionary<string, string> {
	{"grant_type", "client_credentials"},
	{"client_id", "CLIENT_ID"},
	{"client_secret", "CLIENT_SECRET"}
};

var httpClient = new HttpClient();
var response = await httpClient.PostAsync(url, new FormUrlEncodedContent(body));
var responseBody = await response.Content.ReadAsStringAsync();

var tokenEnvelope = JsonConvert.DeserializeObject<JObject>(responseBody);
var accessToken = tokenEnvelope["access_token"].ToString();
Info

Please refer to Authenticating against Genius Sports APIs for more information about authenticating against our API’s in both the User Acceptance Testing and Production environments.

2. Consuming the Fixture Schedule

...

Code Block
languagec#
var sourceId = "GeniusPremium";
var sportId = 17; // American Football
var from = DateTime.UtcNow.ToString("s");
var to = DateTime.UtcNow.AddDays(2).ToString("s");
var baseUrl = "https://platform.matchstate.api.geniussports.com/api/v1";
var url = $"{baseUrl}/sources/{sourceId}/sports/{sportId}/schedule?from={from}&to={to}";

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", "{ACCESS_TOKEN}");
httpClient.DefaultRequestHeaders.Add("x-api-key", "{API_KEY}");

var response = await httpClient.GetAsync(url);
var responseBody = await response.Content.ReadAsStringAsync();

var schedule = JsonConvert.DeserializeObject<JArray>(responseBody);
var fixtureId = schedule[0]["fixtureId"].ToString();

2.5. Obtaining competitor information:

You can retrieve competitor information, as well as other information such as competitions, venues, etc, from our FixtureAPI. Please note that the client credentials for the Fixture API are different from those of the Ably APIs.
Fixture API

3. Obtaining an Ably Access Token and a Channel Name

...

Important: The FIXTURE_ID should be scheduled in a period of 7 between 5 days in the past and 2 days in the future, by the Match State Platform Schedule API in order for the Access Control API to return a channel & token.

...

Any OS that supports the client-side libraries. In our case, these are all major OPs - Windows, Linux, Macintosh. The Ably Realtime client library is available in the most popular languages and platforms including JavaScript, iOS, Android, Java, .NET, Node.js, Ruby, and more.

Are there any limitations around the number of open Ably connections?

Ably Realtime instance represents a single connection to Ably. Currently an Ably token which is issued by Genius APIs, only allows subscribing to a single channel and thus consuming data for a single fixture. Looking forward, this limitation would be mitigated by issuing tokens that allow access to multiple channels but until then, there is no customer specific limit for the number of connections that can be established. There is a hard limit of inbound messages per connection which is 100 messages per second.

Are there any limitations around the number of channel subscriptions per connection?

Yes. There is a hard limit of a maximum of 200 channels per connection.

When should I open the channel subscription?

We do not recommend subscribing to a channel too much before fixture start time. We suggest 3 hours before the kickoff should be a sensible interval of time to create your subscription. Creating a subscription to channel with no publisher will not result in an error. Please keep in mind that each Ably access token has expiration time and needs to be refreshed so if you create a subscription too early, you will have to refresh the token multiple times.