> For the complete documentation index, see [llms.txt](https://info.soccerfootball.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://info.soccerfootball.info/websocket/channels/main.md).

# MAIN

## MAIN Channel

The MAIN channel delivers key match events in real-time as they occur.

### Availability

| Plan  | Available |
| ----- | --------- |
| BASIC | No        |
| PRO   | Yes       |
| ULTRA | Yes       |
| MEGA  | Yes       |

### Events

| Event               | Description                                                           |
| ------------------- | --------------------------------------------------------------------- |
| match\_start        | Match has started                                                     |
| goal                | A goal was scored                                                     |
| cancel\_goal        | A goal was cancelled (e.g. disallowed by VAR) and the score corrected |
| halftime            | First half ended                                                      |
| second\_half\_start | Second half started                                                   |
| match\_end          | Match has ended                                                       |

***

### match\_start

Fired when a match kicks off.

#### Message

```json
{
  "type": "match_start",
  "channel": "MAIN",
  "matchId": "12345",
  "leagueId": "67890",
  "ts": 1705312800000,
  "data": {
    "teamA": {
      "id": "1001",
      "name": "Manchester United"
    },
    "teamB": {
      "id": "1002",
      "name": "Liverpool"
    },
    "championship": {
      "id": "67890",
      "name": "Premier League",
      "country": "England",
      "seasonName": "2023/2024"
    },
    "startDate": "2024-01-15T15:00:00Z"
  }
}
```

#### Data Fields

| Field                     | Type   | Description                 |
| ------------------------- | ------ | --------------------------- |
| `teamA`                   | object | Home team information       |
| `teamA.id`                | string | Team public ID              |
| `teamA.name`              | string | Team name                   |
| `teamB`                   | object | Away team information       |
| `teamB.id`                | string | Team public ID              |
| `teamB.name`              | string | Team name                   |
| `championship`            | object | Championship information    |
| `championship.id`         | string | Championship public ID      |
| `championship.name`       | string | Championship name           |
| `championship.country`    | string | Country                     |
| `championship.seasonName` | string | Season name                 |
| `startDate`               | string | Match start time (ISO 8601) |

***

### goal

Fired when a goal is scored.

#### Message

```json
{
  "type": "goal",
  "channel": "MAIN",
  "matchId": "12345",
  "leagueId": "67890",
  "ts": 1705314600000,
  "data": {
    "score": "1;0",
    "timer": "23",
    "team": "A"
  }
}
```

#### Data Fields

| Field   | Type   | Description                                |
| ------- | ------ | ------------------------------------------ |
| `score` | string | Current score in format "teamA;teamB"      |
| `timer` | string | Match minute when goal was scored          |
| `team`  | string | Team that scored: "A" (home) or "B" (away) |

#### Score Format

The score is formatted as `"X;Y"` where:

* `X` = Goals scored by Team A (home)
* `Y` = Goals scored by Team B (away)

Example: `"2;1"` means Team A is winning 2-1.

***

### cancel\_goal

Fired when a goal previously sent with a `goal` event has been cancelled (typically disallowed after a VAR review) and the score has been corrected.

The live feed does not provide a reliable real-time VAR signal, so there is no "goal under review" event. A score decrease is published only after it has been confirmed over several consecutive feed updates (usually a few minutes after the decision): this avoids false alerts caused by temporary score drops in the feed.

#### Message

```json
{
  "type": "cancel_goal",
  "channel": "MAIN",
  "matchId": "12345",
  "leagueId": "67890",
  "ts": 1705315200000,
  "data": {
    "score": "1;0",
    "timer": "31",
    "team": "A",
    "goalTimer": "27"
  }
}
```

#### Data Fields

| Field       | Type        | Description                                                                         |
| ----------- | ----------- | ----------------------------------------------------------------------------------- |
| `score`     | string      | Corrected score in format "teamA;teamB"                                             |
| `timer`     | string      | Match minute when the cancellation was confirmed                                    |
| `team`      | string      | Team whose goal was cancelled: "A" (home) or "B" (away)                             |
| `goalTimer` | string/null | Minute of the cancelled goal (e.g. "27", "90+3"), `null` if it could not be matched |

{% hint style="info" %}
After the match ends, the cancelled goal is also marked with a `cancel_goal` event (same minute and team as the goal) in the events list of the REST match endpoints.
{% endhint %}

***

### halftime

Fired when the first half ends.

#### Message

```json
{
  "type": "halftime",
  "channel": "MAIN",
  "matchId": "12345",
  "leagueId": "67890",
  "ts": 1705315500000,
  "data": {
    "score": "1;1"
  }
}
```

#### Data Fields

| Field   | Type   | Description                               |
| ------- | ------ | ----------------------------------------- |
| `score` | string | Score at halftime in format "teamA;teamB" |

***

### second\_half\_start

Fired when the second half kicks off.

#### Message

```json
{
  "type": "second_half_start",
  "channel": "MAIN",
  "matchId": "12345",
  "leagueId": "67890",
  "ts": 1705316400000,
  "data": {
    "score": "1;1"
  }
}
```

#### Data Fields

| Field   | Type   | Description                        |
| ------- | ------ | ---------------------------------- |
| `score` | string | Current score at second half start |

***

### match\_end

Fired when the match ends (full time, or after extra time/penalties if applicable).

#### Message

```json
{
  "type": "match_end",
  "channel": "MAIN",
  "matchId": "12345",
  "leagueId": "67890",
  "ts": 1705318800000,
  "data": {
    "finalScore": "2;1",
    "score1h": "1;1"
  }
}
```

#### Data Fields

| Field        | Type   | Description                              |
| ------------ | ------ | ---------------------------------------- |
| `finalScore` | string | Final score in format "teamA;teamB"      |
| `score1h`    | string | First half score in format "teamA;teamB" |

***

### Subscription Examples

#### Subscribe to all MAIN events

```json
{"action": "subscribe", "channel": "MAIN", "scope": "all"}
```

#### Subscribe to a specific match

```json
{"action": "subscribe", "channel": "MAIN", "scope": "match", "id": "b01d28ac92221034"}
```

#### Subscribe to a league

```json
{"action": "subscribe", "channel": "MAIN", "scope": "league", "id": "f2b16fa54cb525d"}
```

***

### Example: Tracking a Match

```javascript
ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);

  if (msg.channel !== 'MAIN') return;

  switch (msg.type) {
    case 'match_start':
      console.log(`Match started: ${msg.data.teamA.name} vs ${msg.data.teamB.name}`);
      break;

    case 'goal':
      const [homeGoals, awayGoals] = msg.data.score.split(';');
      const scorer = msg.data.team === 'A' ? 'Home' : 'Away';
      console.log(`GOAL! ${scorer} team scores at ${msg.data.timer}'`);
      console.log(`Score: ${homeGoals} - ${awayGoals}`);
      break;

    case 'cancel_goal':
      const team = msg.data.team === 'A' ? 'Home' : 'Away';
      console.log(`Goal cancelled (${team} team, ${msg.data.goalTimer ?? '?'}'). Score: ${msg.data.score.replace(';', ' - ')}`);
      break;

    case 'halftime':
      console.log(`Halftime: ${msg.data.score.replace(';', ' - ')}`);
      break;

    case 'second_half_start':
      console.log('Second half started');
      break;

    case 'match_end':
      console.log(`Full time: ${msg.data.finalScore.replace(';', ' - ')}`);
      console.log(`First half was: ${msg.data.score1h.replace(';', ' - ')}`);
      break;
  }
};
```
