> For the complete documentation index, see [llms.txt](https://docs.origami.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.origami.tech/bots/global-variables.md). Agents can also search and read this documentation through its [MCP server](https://docs.origami.tech/~gitbook/mcp).

# Global variables

Project-wide global variables — create them in the Variables modal or widget and read them in any grid formula with globals.\<name>.

A global variable is a named value that belongs to the project. Every grid of every bot in the project can read it, so one edit changes many bots at once — a spread, a maximum size, a risk switch. The UI calls them **Variables**; this documentation says *global variables* to distinguish them from the arguments inside a grid.

![Variables window with the project selector, New Variable button and the Name / Value list](https://602593284-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDjboTEEPFNxFhKJ6msZi%2Fuploads%2FRkYYxBeEwcqHmtMFSgMP%2Fbots-global-variables-01.png?alt=media)

## Where to edit them

* Grids page of any custom bot → **Edit Variables** in the header. The modal is titled **Variables**: *Global variables apply to the entire project, updating all linked bots and grids for consistency and easier management.*
* Terminal → **Add Widget → Variables**. Same table as a widget; see [Bots and Variables](https://docs.origami.tech/terminal/bots-and-variables.md#variables).

Both show the variables of the project selected in the header.

## Create a variable

1. Click **New Variable** (the widget header has **Add**).
2. Fill **Name** and **Value**. A variable's value is itself a formula — `0.002` is valid, and so is `ticker("BTC-USDT") * 0.01` — and it is evaluated when a grid reads it.
3. Click **Apply**.

Names must be unique within the project. Both fields are required; errors from the server appear under the field.

## Use a variable in a grid

Read a global variable inside any argument with `globals.<name>`:

```python
# global variable: spread = 0.002
execute_price = ticker() * (1 - globals.spread)
```

```python
# global variable: max_size = 0.05
execute_volume = min((globals.max_size, balance('counter').available / ticker()))
```

Changing the variable changes the result on every bot's next cycle — no need to open and save each grid. See [How a grid executes](https://docs.origami.tech/grids/how-a-grid-executes.md) for when cycles run.

{% hint style="info" %}
`globals.<name>` is different from the `var(...)` helper offered by the editor's autocomplete: `var` is a per-bot runtime value, while `globals` reads the project table described here.
{% endhint %}

## Edit or delete

* Click a row to edit **Name** or **Value**, then **Apply**.
* The trash icon asks **Confirmation** — *Are you sure you want to delete the ?* — and deletes the variable. This cannot be undone.

{% hint style="warning" %}
Deleting or renaming a variable that a running grid reads makes that formula fail on the next cycle; the bot logs the error and places no orders for that grid. Update the grids first, then remove the variable.
{% endhint %}

## Variables vs preset inputs

|          | Global variable                    | Preset input                          |
| -------- | ---------------------------------- | ------------------------------------- |
| Lives in | Project                            | Preset                                |
| Changes  | Every grid reading it, immediately | Only the grids created by that import |
| Use for  | Values tuned while bots run        | Values fixed when a bot is created    |

## Related

* [Presets](https://docs.origami.tech/bots/presets.md)
* [Grid language reference](https://docs.origami.tech/reference/grid-language.md)
* [Bots and Variables in the Terminal](https://docs.origami.tech/terminal/bots-and-variables.md)
