# Python Examples (/scripting-v2/examples)



These examples **do not place orders**. Choose **Scripts → Examples → Use example** in Furge to create an editable copy. For the CLI, download a `.py` file below. Public data does not require a funded trading account, but running a script still requires a ready runtime.

| Example                                             | Data                                | Backtest | Live |
| --------------------------------------------------- | ----------------------------------- | -------- | ---- |
| [Watch candle closes](#watch-candle-closes)         | Hyperliquid BTC candles, 60 seconds | Yes      | Yes  |
| [Build a momentum signal](#build-a-momentum-signal) | Hyperliquid BTC candles, 60 seconds | Yes      | Yes  |
| [Watch the spread](#watch-the-spread)               | Hyperliquid BTC orderbook           | No       | Yes  |

## Watch candle closes [#watch-candle-closes]

[Download candle-monitor.py](/examples/python/candle-monitor.py)

```python
script = {"name": "candle-monitor", "version": "2", "lookback": 2}
SOURCE = "btc@candles@hyperliquidf:timeframe=60"


def on_data(ctx, history):
    candle = history.source(SOURCE, 0)
    if candle is None:
        return
    print(f"BTC close: {candle['c']} | volume: {candle['volume']}")
    return {"metrics": {"close": candle["c"], "volume": candle["volume"]}}
```

**Expected output:** One log line per candle and close/volume metrics. Zero closed trades is expected.

## Build a momentum signal [#build-a-momentum-signal]

[Download momentum-signal.py](/examples/python/momentum-signal.py)

```python
script = {"name": "momentum-signal", "version": "2", "lookback": 5}
SOURCE = "btc@candles@hyperliquidf:timeframe=60"


def on_data(ctx, history):
    candles = history.source(SOURCE)
    if len(candles) < 5:
        return
    average = sum(row["c"] for row in candles) / len(candles)
    close = candles[-1]["c"]
    signal = "above average" if close > average else "at or below average"
    print(f"BTC {signal}: close={close}, mean={average}")
    return {"metrics": {"close": close, "mean": average}}
```

**Expected output:** After five candles, the latest close and retained five-candle mean. This demonstrates a signal; it does not send orders.

## Watch the spread [#watch-the-spread]

[Download book-spread.py](/examples/python/book-spread.py)

```python
script = {"name": "book-spread", "version": "2", "lookback": 2}
SOURCE = "btc@orderbook@hyperliquidf:depth=5"


def on_data(ctx, history):
    book = history.source(SOURCE, 0)
    if not book or not book["bids"] or not book["asks"]:
        return
    bid = book["bids"][0]["price"]
    ask = book["asks"][0]["price"]
    midpoint = (bid + ask) / 2
    if midpoint <= 0:
        return
    spread_bps = (ask - bid) / midpoint * 10_000
    print(f"BTC bid={bid} ask={ask} spread={spread_bps:.2f} bps")
    return {"metrics": {"bid": bid, "ask": ask, "spread_bps": spread_bps}}
```

**Expected output:** Best bid, best ask, and spread in basis points. This source is live-only: use Deploy bot, not Backtest.

## Contract markets and execution [#contract-markets-and-execution]

Copy the market source from Furge's picker. Start with [Nest Scripts](/scripting-v2/nest) or [Elysium trades](/scripting-v2/sources/trades#elysium-markets).

When ready to add real orders, use [Execution](/scripting-v2/execution). Live execution can use real funds. Copying a signal example does not make it a safe trading strategy.

Next: [First script in Furge](/scripting-v2/furge) · [Data Sources](/scripting-v2/sources) · [Monitoring](/scripting-v2/monitoring).
