> ## 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.

# Unit Conversions

> Converting between SX Bet's raw API values and human-readable formats.

The SX Bet API uses raw integers for odds and token amounts. Here's everything you need to convert them.

## Quick reference

| Value      | Raw format               | Convert to human-readable                 |
| ---------- | ------------------------ | ----------------------------------------- |
| Odds       | Integer, scaled by 10^20 | `raw / 10^20` → implied probability (0–1) |
| USDC       | Integer, 6 decimals      | `raw / 1,000,000` → dollar amount         |
| Timestamps | Unix seconds             | Standard Unix timestamp                   |

***

## Odds

SX Bet stores odds as **implied probability** scaled to avoid floating point: `percentageOdds = implied × 10^20`

### Raw ↔ implied probability

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

  raw_to_implied = lambda raw: raw / ODDS_PRECISION
  implied_to_raw = lambda implied: int(implied * ODDS_PRECISION)

  # 52631578947368421052 → 0.5263 (52.63%)
  ```

  ```javascript JavaScript theme={null}
  const rawToImplied = (raw) => Number(raw) / 1e20;
  const impliedToRaw = (implied) => BigInt(Math.round(implied * 1e20));
  ```
</CodeGroup>

### Maker → taker odds

On SX Bet, makers post odds at a specific implied probability. The taker automatically receives the complementary side — the two sides always sum to 1 (no house spread):

```
taker_implied = 1 - maker_implied
taker_raw = 10^20 - maker_raw
```

**Example:** Maker posts at `50125000000000000000` (\~50.125%). Taker receives `49875000000000000000` (\~49.875%).

### Implied ↔ American

```
Favorite (implied ≥ 0.5):  American = -(implied / (1 - implied)) × 100
Underdog (implied < 0.5):  American = ((1 - implied) / implied) × 100
```

<CodeGroup>
  ```python Python theme={null}
  def implied_to_american(implied: float) -> float:
      if implied >= 0.5:
          return -(implied / (1 - implied)) * 100
      return ((1 - implied) / implied) * 100

  def american_to_implied(american: float) -> float:
      if american < 0:
          return (-american) / (-american + 100)
      return 100 / (american + 100)
  ```

  ```javascript JavaScript theme={null}
  function impliedToAmerican(implied) {
    return implied >= 0.5
      ? -(implied / (1 - implied)) * 100
      : ((1 - implied) / implied) * 100;
  }

  function americanToImplied(american) {
    return american < 0
      ? (-american) / (-american + 100)
      : 100 / (american + 100);
  }
  ```
</CodeGroup>

### Implied ↔ Decimal

```
decimal = 1 / implied
implied = 1 / decimal
```

***

## Token amounts

USDC on SX Network uses 6 decimal places, so all token amounts in the API are integers representing millionths of a dollar. For example, `10000000` is 10.00 USDC, and `1500000` is 1.50 USDC.

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

  raw_to_usdc = lambda raw: raw / USDC_DECIMALS
  usdc_to_raw = lambda amount: int(round(amount * USDC_DECIMALS))

  raw_to_usdc(10_000_000)   # → 10.0
  usdc_to_raw(10.00)        # → 10000000
  ```

  ```javascript JavaScript theme={null}
  const rawToUsdc = (raw) => raw / 1_000_000;
  const usdcToRaw = (amount) => Math.round(amount * 1_000_000);

  rawToUsdc(10_000_000);  // → 10
  usdcToRaw(10.00);       // → 10000000
  ```
</CodeGroup>
