# Markets Leaderboard

Golf Event Centre now supports the integration of bookmaker markets within the leaderboard. Operators can transmit market data to the Event Centre using the FRS.js message bus functionality outlined below.

The UI dynamically updates markets in real time and when a customer selects an option, the Event Centre emits an event, which the operator can listen to for processing into their betslip.

<figure><img src="https://1485305088-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ9XC5ZatUENF4oTZ0UUR%2Fuploads%2Fgit-blob-d5d48781481da8b9a79db8406d3c7a22755d20a6%2Fimage%20(5).png?alt=media" alt=""><figcaption></figcaption></figure>

### Emitting

<pre><code>// See below the fields to include on object passed for each topic
<strong>ec.emit(MESSAGE_TOPIC_NAME, messageData)
</strong></code></pre>

The `emit` method is available on the return value from the `eventCentre` initialiser, it is used to send messages to the Event Centre. Only supported message topics will be passed to the Event Centre.

### **Message Types for Golf Event Centre**

### **Markets Update**

`ec.emit(markets-update, messageData)`

#### **Initial Market Load:**

* On the first load, send us all available markets along with their player options. This ensures we have a complete starting dataset.

#### **Handling Updates:**

* Future updates can either include the entire dataset (full payload) or only the updates.
* Updates are applied by matching the market ID first, then the player ID within that market. If an existing market or player option is found, it will be overwritten with the new data.

#### **Adding New Markets or Players:**

* If a market ID or player ID doesn’t already exist in our system, it will be added automatically.

#### **Suspending/Unsuspending Markets:**

* You can suspend or unsuspend an entire market or specific player option within a market at any time.

#### **UI Behavior for Multiple Markets:**

* If multiple markets are provided, a dropdown menu will be displayed, allowing users to switch between them. The first market in the list will be selected by default.
* If only one market is provided, its title will simply be displayed in the leaderboard header without a dropdown.

**Market Object:**

| Variable  | Values     | Description                                                |
| --------- | ---------- | ---------------------------------------------------------- |
| id        |            | unique identifier for a market - used to add/apply updates |
| title     |            | Name of Market that will be shown on GEC UI                |
| suspended | true/false | suspends all players options within this market            |

**Options array:**

| Variable        | Values                                         | Description                                                                                                                                                                                        |
| --------------- | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id              |                                                | unique to operator - we will emit this upon any user clicks                                                                                                                                        |
| playerId        |                                                | used to add/apply updates (this is the DDE playerId)                                                                                                                                               |
| title           |                                                | Market Title                                                                                                                                                                                       |
| odds            | <p>fractional</p><p>decimal</p><p>american</p> | you can specify the odds format to display in the I via the existing FRS.js option (oddsFormat)                                                                                                    |
| suspended       | true/false                                     | suspend individual player option                                                                                                                                                                   |
| marketDirection | <p>default<br>lengthening<br>shortening</p>    | if 'lengthening' or 'shortening' are provided as values then we will animate the odds button accordingly. If this field is omitted the GEC will take responsibility for calculating the animation. |

**Sample code:**

```
//markets-update
- To be used on initial load to send us all markets and their player options.
- Subsequent updates can include the full payload including updates or just the updates alone. Updates will overwrite based on finding a market id and then the playerId if updating a player option.
- If a market id or playerId (within a market id) does not exist, we will add.
- You have the ability to suspend/unsuspend a market or it's player options within a market here too.
- If more than one market is added, then we will display a dropdown in the UI. The first market will be selected by default. If a single market is provided, we simply show this title in the leaderboard header.

const markets_update = {
  markets: [
    {
      id: '1', //unique identifier for a market - used to add/apply updates
      title: 'Outright', //what you will see in the GEC UI
      suspended: false, //suspends all players options within this market
      options: [
        {
          id: 'abc', //unique to operator - we will emit this upon any user clicks
          playerId: '45', //used to add/apply updates (this is the DDE playerId)
          title: 'Outright',
          odds: { //you can specify the odds format to display in the I via the existing FRS.js option (oddsFormat)
            fractional: '9/1',
            decimal: '10.00',
            american: '+900'
          },
          suspended: false, //suspend individual player option
          marketDirection: 'default', //if 'lengthening' or 'shortening' are provided as values then we will animate the odds button accordingly. If this field is omitted the GEC will take responsibility for calculating the animation.
        },
      ],
    },
    {
      id: '2', //second market to show in dropdown
      title: 'Top 5',
      suspended: false,
      options: [
        {
          id: 'ghi',
          playerId: '64',
          title: 'Top 5',
          odds: {
            fractional: '11/1',
            decimal: '12.00',
            american: '+1100',
          },
          suspended: false,
          marketDirection: 'default',
        },
      ],
    },
  ],
};
```

### Market Suspend

```
ec.emit(markets-suspend, messageData)
```

This update allows you to suspend markets or specific player options within markets. You can choose to suspend entire markets (including all associated player options) or target specific player options within a market for suspension.

#### Suspending Entire Markets

* If you provide only market IDs, the system will suspend those markets along with all their player options.

#### Suspending Specific Player Options

* If you include player IDs alongside market IDs, the system will locate the specified markets and suspend only the player options that match the given player IDs.

| Value     | Description                                        |
| --------- | -------------------------------------------------- |
| marketIds | suspends entire market.                            |
| playerIds | suspends an individual player option in market id. |

**Sample code:**

```
const markets-suspend = {
  marketIds: ['1'], //suspends entire market.
  playerIds: ['45'], //suspends an individual player option in market id '1'.
};
```

### Remove Markets

`ec.emit(markets-remove, messageData)`

This update allows you to remove markets or specific player options within markets. You can choose to remove entire markets (including all associated player options) or target specific players within a market for removal.

#### Removing Entire Markets

* If you provide only market IDs, the system will remove those markets along with all their player options.

#### Removing Specific Player Options

* If you include player IDs alongside market IDs, the system will locate the specified markets and remove only the player options that match the given player IDs.

| Value     | Description                                             |
| --------- | ------------------------------------------------------- |
| marketIds | removes entire market                                   |
| playerIds | removes an individual player option from market id '1'. |

**Sample code:**

<pre><code><strong>const market-remove = {
</strong>  marketIds: ['1'], //removes entire market,
  playerIds: ['45'], //removes an individual player option from market id '1'.
};
</code></pre>

### Bet Placement Event

```
ec.emit(markets-place-bet, messageData)
```

This event notifies the operator when a user selects an odds option. The operator must listen for it and use the provided payload to handle the selection on their betslip.

#### Triggering the Event

* When a user clicks on an odds button, the Event Centre will emit this event.

#### Operator Responsibility

* The operator must listen for this event to process the selection.

```
      // for listening to event centre bets
      ec.on("markets-place-bet", (e) =>
        console.log("markets-place-bet", JSON.stringify(e))
      );
```

#### Payload Handling

* The emitted event includes a payload (detailed below) that the operator can use to add the selection to their betslip.

**Sample code:**

```
const markets-place-bet = {
  market: {
    id: '1',
    title: 'Outright',
    suspended: false,
  },
  option: {
    id: 'abc',
    playerId: '45',
    title: 'Outright',
    odds: {
      fractional: '9/1',
      decimal: '10.00',
      american: '+900'
    },
    suspended: false,
    marketDirection: 'default',
  },
};
```
