# Exchange Mechanics

Our decentralised betting exchange allows players to bet and trade on betting markets in a truly peer-to-peer, non-custodial and trustless exchange fully managed by smart contracts.

This section outlines the mechanics behind Bookie betting markets through a step-by-step consideration of the betting process from order submissions to market resolution and payouts.

<figure><img src="/files/UNwKAfp0NzdwzSPKn7mI" alt=""><figcaption></figcaption></figure>

### Step 1: Smart Contract Order Books

Players on Bookie are able to place bets both ‘For’ and ‘Against’ events at the odds they like and hold as their true estimation of an event's likelihood.

A player's bet is split into orders with associated “Odds” and “Collateral” amounts required.

All orders are sent and logged in automated smart contract based order books. These order books manage the bidding process independently with the goal of matching bets between two counterparties through an auction system. This competition of supply and demand reveals the market’s estimation of an event's true odds.

Bookie eliminates counterparty risk by ensuring players must submit the collateral amount required for their bet. This collateral is associated with a players order and locked on the IC ledger until the market is resolved.

### Step 2: Matched Bets

Players' bets are matched automatically by our order book system should they have the corresponding odds ‘For’ and ‘Against’. Once the bets are matched they can not be cancelled by any user and the funds are locked on the Internet Computer Protocol Ledger pending market resolution and payout.

### Step 3: Market Resolution

Bookie resolves markets by calling a secure Sports Data API through https outcalls directly from the Internet Computer blockchain smart contracts.The IC’s https outcalls allow direct communication with a secure API without using an oracle, thereby ensuring the results of Bookie prediction markets are reliable and tamperproof.

Learn more about the Internet Computer’s https outcalls [here.](https://internetcomputer.org/https-outcalls)​

<figure><img src="/files/WReBkZw1wfaxJkiYDirx" alt=""><figcaption></figcaption></figure>

### Step 4: Final Result <a href="#step-4-final-result" id="step-4-final-result"></a>

After the event is finished and upon receiving the final result from the Sports Data API, our smart contracts calculates users' winnings accordingly.&#x20;

Players bets can have three states at the end of a fixture upon which their payouts depend: matched, unmatched and partially matched.

* Matched bets: Winner takes all.&#x20;
* Unmatched bets: Bet amount refunded to player.&#x20;
* Partially matched bets: The matched portion is paid out with winnings whilst the unmatched portion is refunded to the player.

<figure><img src="/files/jcRQyAtoUmQY0JYaf2vI" alt=""><figcaption></figcaption></figure>

### Step 5: Payouts <a href="#step-5-payouts" id="step-5-payouts"></a>

Payouts are processed automatically and sent directly to players' wallets. This ensures the entire process from placement to payout remains non-custodial and Bookie never has access to player funds.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bookie-2.gitbook.io/bookie/how-does-bookie-work/exchange-mechanics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
