# Selection Result Endpoint

The Selection Result endpoint is for sending results for individual market selections as their related events unfold during play or at the end of an event. There will be a request made for every market selection with one or more bets placed against it with the operator. This request will not be user specific. It's the responsibility of the operator to find and result/settle the n pending bets against this specific market selection (N.B. important to note that for efficiency BetLink will not result/settle at the market level and so any market selections without a bet placed against them will not be settled).

On receipt of a selection result request, the operator should:

* look up all pending user bets for that selection and market ID
* for each bet, payout the user by resulting/settling the bets according to the stakeReturned and payoutReturned fields as follows:

`payout = (stake * stakeReturned) + (potentialPayout * payoutReturned)`

The `potentialPayout` should have been calculated alongside each bet as per the bet placement endpoint specification. Here is a brief explanation of how the fields function:

* When a selection has lost, both stakeReturned and payoutReturned will be 0.0 so nothing will be paid out to the user
* When some stake needs to be returned to the user (e.g. if the market was declared null and void) the stakeReturned parameter will show a factor of the stake to return of <= 1 and the user should be paid stake \* stakeReturned
* When the bet has won, the payoutReturned parameter will show a factor of the payout to return of <=1 (usually 1.0 but some result scenarios such as dead heats can return fractional payouts) and the user should be paid potential payout \* payoutReturned.

For more detail on market and selection definitions, see the 'Markets and Selections' section.

{% hint style="info" %}
Both single and multiple bets are to be resulted based on the receipt of results for selections concerning the bet
{% endhint %}

### Request Parameters

type: `POST`\
content-type: `application/json`

#### Idempotency

Request will contain a header `X-Idempotency-Key` in the form of a UUID string. See the 'Idempotency' section for more detail.

<table><thead><tr><th width="178">Parameter</th><th width="216">Type</th><th width="111">Required?</th><th>Example</th></tr></thead><tbody><tr><td>requestId</td><td>String/UUID</td><td>Yes</td><td>92e02ae9-a2a3-48e2-af0e-940aec4bbcfb</td></tr><tr><td>marketId</td><td>String</td><td>Yes</td><td></td></tr><tr><td>selectionId</td><td>String</td><td>Yes</td><td></td></tr><tr><td>stakeReturned</td><td>Decimal/Double</td><td>Yes</td><td>0.0</td></tr><tr><td>payoutReturned</td><td>Decimal/Double</td><td>Yes</td><td>1.0</td></tr><tr><td>timestamp</td><td>String (epoch)</td><td>Yes</td><td>1640995200000</td></tr></tbody></table>

### Response Parameters

accepts: `application/json`

<table><thead><tr><th width="179">Parameter</th><th width="215">Type</th><th width="112">Required?</th><th></th></tr></thead><tbody><tr><td>requestId</td><td>String/UUID</td><td>Yes</td><td>Matches request's requestId</td></tr><tr><td>marketId</td><td>String</td><td>Yes</td><td></td></tr><tr><td>selectionId</td><td>String</td><td>Yes</td><td></td></tr><tr><td>stakeReturned</td><td>Decimal/Double</td><td>Yes</td><td>0.0</td></tr><tr><td>payoutReturned</td><td>Decimal/Double</td><td>Yes</td><td>1.0</td></tr><tr><td>timestamp</td><td>String (epoch)</td><td>Yes</td><td>Response timestamp</td></tr><tr><td>status</td><td>String ("RESULTED")</td><td>Yes</td><td></td></tr></tbody></table>

### Error Response

accepts: `application/json`

| Parameter    | Type                                   | Required? |
| ------------ | -------------------------------------- | --------- |
| status       | String ("FAILURE")                     | Yes       |
| errorCode    | String (enum - see Errors table below) | Yes       |
| errorMessage | String                                 | No        |

#### Errors

| Error Code             | Http Status |
| ---------------------- | ----------- |
| MISSING\_PARAMETER     | 400         |
| AUTHENTICATION\_FAILED | 403         |
| GENERAL\_EXCEPTION     | 500         |
| REQUEST\_TIMED\_OUT    | 503         |
