Bentrix Docs
HomePricingDashboard

Gym

Reinforcement learning on Bentrix: a trading environment over a workbench, with the venue's own fills and costs, trained from your own program in any of nine languages.

What the Gym is

The Gym turns a workbench into a reinforcement-learning environment — the shape every learning library expects. Your program, the agent, repeats one loop:

  1. it observes the market and its account,
  2. it chooses an action — flat, long or short,
  3. Bentrix carries the action out on the workbench's venue, moves the clock to the next candle's close, and answers a reward and the next observation.

An episode is one run of that loop over a stretch of history; training is many episodes, the agent changing how it chooses after each one.

01Why train here

  • The fills are the venue's. Every action is an order on the same simulated venue a person trades on: the spread, the commission, the swap, the volume step, the stops level. A policy cannot learn to exploit a fill that does not exist.
  • No look-ahead, by construction. An observation is built only from candles closed at the clock. The next candle does not exist yet when the agent chooses — not by discipline, but because the clock has not served it.
  • Every episode is repeatable. The same seed and the same actions give the same deals, and the environment answers a ledger hash that proves it. A result can be checked by running it again.
  • Any language. The environment is part of Bentrix itself, so the same eight calls work from Python, JavaScript, C#, Go, Java, C++, Julia, R and Rust. In Python it is also a ready Gymnasium environment for Stable-Baselines3, CleanRL and the rest.

02What you need

  • Bentrix open on this computer, with a laboratory workbench of its own for training. Each new episode rewinds the workbench to its start and undoes its deals — so never train on a workbench whose trades you want to keep. A laboratory to practise in makes one in a minute.
  • The SDK for your language, installed and connected: start in your language.
  • A pairing with the lab scope (the default for a program).

03The calls

CallWhat it does
env_makemakes an environment over a workbench and answers its id, its observation and its actions
env_resetstarts an episode and answers the first observation
env_steptakes one action and answers the reward, the next observation and whether the episode ended
run_episoderesets and takes a whole list of actions in one call
env_act, env_observethe same loop on a paper or real workbench, whose clock is the market's
env_closelets the environment go — the workbench and its deals stay
extract_datasetwrites labelled candles for supervised learning instead

04Where to begin

Read how one step works, then run your first episode. The guides after it beat a simple rule, train a policy, and move to Python libraries.

i

The Gym is a laboratory instrument. Nothing an agent does here is ranked or published, and a reward is a training signal, not a score of anyone.

How the environment works

What one step is, what an observation holds, the three kinds of action, the eight rewards, episodes and seeds, every setting.

Step by step, in nine languages

Each guide is a whole program in Python, JavaScript, C#, Go, Java, C++, Julia, R and Rust.

With a Python library

Gymnasium, Stable-Baselines3 and a loop of your own, on the same environment.

The engine in your own program

Bentrix's replay clock and venue inside your own Python program: your own environment, orders and legs, several timeframes, fills, snapshots and branching, many environments, a strategy, datasets, and checking the engine yourself.

Further

A live market, a labelled dataset, and how to evaluate a policy honestly.

Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed