Scripting Overview
Write custom trading strategies in Luau and deploy them on Pyx.
What is a script task?
A script task is a user-defined trading strategy written in Luau - the language created by Roblox, based on Lua 5.1. Your script runs inside Pyx's execution engine with access to real-time market data, order placement, and position tracking.
You write the logic. Pyx handles everything else - wallet management, order routing, fill tracking, and risk enforcement.
function on_price(ctx)
if ctx.spread < 0.03 and pyx.active_orders() == 0 then
pyx.buy(TOKEN, CONDITION, ctx.ask, 0.10)
end
endHow it works
When you create a script task, Pyx:
- Compiles your Luau script in a sandboxed VM with no filesystem or network access
- Injects the
pyxAPI module - your only interface to the trading engine - Calls your callbacks on market events (
on_price,on_book), timer ticks (on_tick), and execution events (on_fill,on_placed,on_cancelled) - Executes orders you enqueue through
pyx.buy()andpyx.sell(), validating them against your configured risk limits before they hit the exchange
Your script state (local variables, tables) persists across all callback invocations for the lifetime of the task. If you store a price history table, it is still there on the next tick.
Modify scripts without recreating tasks
Script tasks can be updated from the task details page using Modify script.
The new script is compiled/validated before apply. Depending on task runtime state, edits may be applied immediately or saved without live reload.
See full operational behavior: Script Editing.
Editor assistance
The script editor includes built-in assistance so you can iterate faster:
- Luau syntax highlighting
- Inline lint diagnostics for common script/runtime mistakes
- Autocomplete for the
pyxAPI surface and common Luau patterns
Use API Reference while writing to understand available methods and callback data shapes.
Why Luau?
Luau is a fast, typed superset of Lua 5.1. It is familiar if you have used Lua, and approachable if you have not. Key advantages:
- Simple syntax - no boilerplate, no classes, just functions and tables
- Optional type annotations - add
string,number,{number}types for clarity without changing runtime behavior - Battle-tested sandboxing - designed for running untrusted code safely at scale (billions of executions in Roblox)
- Fast - bytecode-compiled, sub-microsecond function calls
What you cannot do
Scripts run in a restricted sandbox. You cannot:
- Access the filesystem, network, or OS
- Import external modules (
require,dofile,loadfileare removed) - Load bytecode (
string.dump,loadare removed) - Modify standard library tables (they are frozen)
- Run indefinitely - callback timeouts are enforced (
on_price/on_spot_price/on_book: 25ms,on_tick: 150ms, execution and split/merge callbacks: 50ms)
These restrictions exist to protect you and other users. All risk enforcement happens in Rust, outside the Luau VM. Your script cannot bypass spend limits, position limits, or order rate limits regardless of what it does.