# Candles (/scripting-v2/data-types/candles)



```python
latest = history.source("btc@candles@binancef:timeframe=60", 0)
```

| Key          | Type              | Meaning                                    |
| ------------ | ----------------- | ------------------------------------------ |
| `t`          | integer           | Bucket start in Unix milliseconds.         |
| `o`          | number            | Open price.                                |
| `h`          | number            | High price.                                |
| `l`          | number            | Low price.                                 |
| `c`          | number            | Close price.                               |
| `volume`     | number            | Total available volume.                    |
| `trades`     | integer           | Trade count.                               |
| `close_time` | integer, optional | Exclusive bucket end in Unix milliseconds. |
| `vb`, `vs`   | number, optional  | Buy and sell volume.                       |
| `tb`, `ts`   | integer, optional | Buy and sell trade counts.                 |

```python
def on_data(ctx, history):
    candles = history.source("btc@candles@binancef:timeframe=60")
    latest = history.source("btc@candles@binancef:timeframe=60", 0)
    if latest is None:
        return

    sma = ctx.study.sma(candles, {"field": "c", "window": 20})
    return {"metrics": {"close": latest["c"], "sma": sma["latest"]}}
```

Directional fields are present only when the provider supplies or derives them. See [Candles Source](/scripting-v2/sources/candles).
