> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sx.bet/llms.txt
> Use this file to discover all available pages before exploring further.

# Odds & Tokens

> How odds and tokens are represented on the SX Bet API

## Odds format

The SX Bet API represents odds as an **implied probability** stored as a fixed-point integer with 20 decimal places (units of 10^20).

### The formula

```
Human-readable implied probability = percentageOdds / 10^20
```

### Examples

| `percentageOdds` value | Implied probability | American odds (approx) |
| ---------------------- | ------------------- | ---------------------- |
| `60000000000000000000` | 60.00%              | -150                   |
| `52500000000000000000` | 52.50%              | -111                   |
| `50000000000000000000` | 50.00%              | +100                   |
| `40000000000000000000` | 40.00%              | +150                   |

### Converting in code

<CodeGroup>
  ```python Python theme={null}
  ODDS_PRECISION = 10 ** 20

  def to_implied(percentage_odds: int) -> float:
      """Convert raw percentageOdds to decimal implied probability (0–1)."""
      return percentage_odds / ODDS_PRECISION

  def to_raw(implied: float) -> int:
      """Convert decimal implied probability to raw percentageOdds."""
      return int(implied * ODDS_PRECISION)

  def implied_to_american(implied: float) -> float:
      """Convert implied probability to American odds."""
      if implied >= 0.5:
          return -(implied / (1 - implied)) * 100
      else:
          return ((1 - implied) / implied) * 100

  # Examples
  raw = 52631578947368421052
  print(to_implied(raw))             # 0.5263...
  print(implied_to_american(0.5263)) # ~-111
  ```

  ```javascript JavaScript theme={null}
  const ODDS_PRECISION = BigInt(10 ** 20);

  function toImplied(percentageOdds) {
    // Use floating point for display purposes
    return Number(percentageOdds) / Number(ODDS_PRECISION);
  }

  function toRaw(implied) {
    return BigInt(Math.round(implied * Number(ODDS_PRECISION)));
  }

  function impliedToAmerican(implied) {
    if (implied >= 0.5) {
      return -(implied / (1 - implied)) * 100;
    } else {
      return ((1 - implied) / implied) * 100;
    }
  }

  // Examples
  const raw = 52631578947368421052n;
  console.log(toImplied(raw));               // 0.5263...
  console.log(impliedToAmerican(0.5263));    // ~-111
  ```
</CodeGroup>

<Warning>
  `percentageOdds` values are very large integers. Use `BigInt` in JavaScript to avoid precision loss when doing arithmetic.
</Warning>

## Taker odds

When you fill an order, you automatically receive the complementary odds:

```
taker_implied = 1 - maker_implied
```

For example, if a maker posts an order with desired odds of 52.25% implied odds on outcome 1, the taker gets 47.75% implied odds on outcome 2.

## Token amounts (USDC)

All stake and payout amounts are in **USDC with 6 decimal places**.

```
Human-readable USDC = rawAmount / 1000000
```

### Examples

| Raw value  | Human-readable |
| ---------- | -------------- |
| `1000000`  | \$1.00         |
| `10000000` | \$10.00        |
| `5500000`  | \$5.50         |

### Converting in code

<CodeGroup>
  ```python Python theme={null}
  USDC_DECIMALS = 10 ** 6

  def to_usdc(raw: int) -> float:
      return raw / USDC_DECIMALS

  def from_usdc(amount: float) -> int:
      return int(amount * USDC_DECIMALS)

  print(to_usdc(10000000))   # 10.0
  print(from_usdc(5.50))       # 5500000
  ```

  ```javascript JavaScript theme={null}
  const USDC_DECIMALS = 1000000;

  function toUsdc(raw) {
    return raw / USDC_DECIMALS;
  }

  function fromUsdc(amount) {
    return Math.round(amount * USDC_DECIMALS);
  }

  console.log(toUsdc(10000000));  // 10
  console.log(fromUsdc(5.50));      // 5500000
  ```
</CodeGroup>

## Calculating payout

For a given fill:

```
taker_payout = fill_amount / taker_implied
taker_profit = taker_payout - fill_amount
```

<CodeGroup>
  ```python Python theme={null}
  def calculate_payout(fill_amount_raw: int, maker_odds_raw: int) -> dict:
      maker_implied = maker_odds_raw / ODDS_PRECISION
      taker_implied = 1 - maker_implied
      payout_raw = fill_amount_raw / taker_implied
      profit_raw = payout_raw - fill_amount_raw
      return {
          "stake_usdc": to_usdc(fill_amount_raw),
          "payout_usdc": to_usdc(payout_raw),
          "profit_usdc": to_usdc(profit_raw),
      }

  result = calculate_payout(
      fill_amount_raw=10000000,              # $10 stake
      maker_odds_raw=52631578947368421052,   # maker at 52.63%
  )
  # stake: $10, payout: ~$21.17, profit: ~$11.17
  ```

  ```javascript JavaScript theme={null}
  function calculatePayout(fillAmountRaw, makerOddsRaw) {
    const makerImplied = Number(makerOddsRaw) / Number(ODDS_PRECISION);
    const takerImplied = 1 - makerImplied;
    const payoutRaw = fillAmountRaw / takerImplied;
    const profitRaw = payoutRaw - fillAmountRaw;
    return {
      stakeUsdc: toUsdc(fillAmountRaw),
      payoutUsdc: toUsdc(payoutRaw),
      profitUsdc: toUsdc(profitRaw),
    };
  }
  ```
</CodeGroup>

<Card title="Markets & Sports →" icon="arrow-right" href="/developers/markets-and-sports" />
