What happens between the action your agent sends and the reward it gets back — the order, the clock, the reward and the end of an episode.
The loop, from the agent's side
Every environment answers the same two things, in the shape reinforcement-learning libraries use:
env_reset→ the first observation and aninforecord.env_step(action)→ the next observation, the reward,terminated,truncatedandinfo.
The agent keeps calling env_step until terminated or truncated is true; then the episode is over and env_reset starts the next.
01Inside one step
A step always does three things, in this order.
1. The action is carried out. The action names a side — flat, long or short. Bentrix brings this market's position to that side through the workbench's venue:
| You hold | The action says | What is sent |
|---|---|---|
| nothing | long | a market buy of the environment's lots |
| long | long | nothing — the position is already on that side |
| long | flat | the position is closed |
| long | short | the position is closed, then a market sell is opened |
The order fills at the venue's own quote — the ask for a buy, the bid for a sell — with the market's spread and commission, exactly as an order from the trade panel would.
2. The clock moves to the next close. The workbench advances, tick by tick, to the close of the next candle of the environment's interval (an hour, with the default H1). Every tick is fed to the venue on the way, so a stop or a target set by an order action can fill in the middle of the candle.
3. Bentrix observes. At the close it reads the account and answers:
- the reward — computed from the equity just before the action and the equity at the close, by the reward you chose (the eight rewards);
- the observation — the candles closed at the clock and the account (what an observation holds);
- whether the episode ended.
02Two ways an episode ends
| Flag | Means | Typical cause |
|---|---|---|
terminated | the episode ended in ruin | the equity fell to ruin of the episode's opening equity (half, by default) |
truncated | the episode was cut off | its candles ran out, or the recording's last day was reached |
The difference matters to a learner: after terminated there is no future value to estimate; after truncated there would have been, had the episode gone on. Libraries such as Stable-Baselines3 use the two flags exactly this way.
03What info carries
| Field | What it is |
|---|---|
equity | the account's equity at the close, in the account currency |
refused | the venue's sentence when the order was refused, otherwise empty |
cursor_ms | the clock, in milliseconds since 1970 (UTC) |
ledger_hash | a fingerprint of the workbench's deals so far — equal runs give equal hashes |
reward | the reward's name, such as dsr_dd_penalty@1 |
participation | with a participation cap, what was asked, what was allowed and the impact charged |
env_reset's info adds start_ms, end_ms, opening (the equity the episode starts from) and episode_index.
Money and the real scope. A laboratory or paper workbench's account is Bentrix's own venue, so its balance and equity reach any program. A real account's money reaches only a program whose pairing includes the real scope; to any other it reads null.
04How fast a program may call
Bentrix answers one program at most 20 calls a second, with a burst of 60; a faster program is answered Rate limited: slow down and told how long to wait. Every SDK waits that out by itself: a request Bentrix refused this way ran nothing, so the SDK sends it again after the wait the answer names, up to ten times, and only then raises the refusal. A training loop can step as fast as it likes; it is simply held to the limit. For many steps at once, run_episode takes a whole list of actions in one call.
05A refused order is never changed into another
If the venue refuses an order — a size the market does not allow, a stop too close, a market closed — nothing else is sent in its place. The step still happens, the clock still moves, and info.refused carries the venue's own words. A reward can count refusals: rule_adherence@1 gives −1 for each.
06One environment, one workbench
An environment drives its workbench: each env_reset rewinds the workbench to its first moment, undoes its deals, and plays it forward to the episode's start. Use a workbench kept for training alone. Up to 64 environments can be open at once; env_close lets one go and leaves the workbench and its deals as they are.