Bentrix Docs
HomePricingDashboard

On a live market

Run a trained policy on a paper workbench — or, with your permission, a real one — where the market's clock moves and nothing can be rewound.

In the laboratory the environment drives the clock. On a paper or real workbench the clock is the market's: candles close when they close, and nothing can be rewound. The environment follows it with two calls instead of env_step:

LaboratoryLive
env_step(action) — acts and moves the clockenv_act(action) at a close — acts, moves nothing
wait for the next candle to close
env_observe(at_ms) at that close — the reward and the next observation

The observation, the actions and the rewards are the same, so a policy trained in the laboratory runs here unchanged.

i

Start on paper: a paper workbench follows the live market and trades on Bentrix's venue, with no money at a broker. On a real workbench every order is a real order, subject to the account's Automations setting — under Confirm, the trade panel proposes each one and waits for your Send.

01The loop

1. Make the environment on the paper workbench. It is live by itself; max_steps ends an episode after that many closes.

Python

made = client.strategy.env_make(paper_bench, interval="H1", max_steps=24, window=8)
env_id = made["env"]

JSJavaScript

const made = await client.strategy.envMake({ bench: paper_bench, interval: "H1", max_steps: 24, window: 8 });
const env_id = made.env;

C#C#

var made = await client.Strategy.EnvMake(paper_bench, interval: "H1", maxSteps: 24, window: 8);
var env_id = made!["env"]?.GetValue<string>() ?? "";

GOGo

made := must(client.Strategy.EnvMake(ctx, mcp.StrategyEnvMakeArgs{Bench: paper_bench, Interval: mcp.Ptr[string]("H1"), MaxSteps: mcp.Ptr[int64](24), Window: mcp.Ptr[int64](8)}))
env_id := text(at(made, "env"))

Java

Object made = client.strategy.envMake(new Bentrix.StrategyApi.EnvMakeArgs(paper_bench).interval("H1").maxSteps(24L).window(8L));
String env_id = (String) at(made, "env");

C++C++

auto made = client.strategy.env_make(StrategyApi::EnvMakeArgs(paper_bench).interval("H1").max_steps(24).window(8));
auto env_id = (made["env"].is_string() ? made["env"].str() : std::string());

Julia

made = client.strategy.env_make(paper_bench; interval = "H1", max_steps = 24, window = 8)
env_id = made["env"]

RR

made <- client$strategy$env_make(paper_bench, interval = "H1", max_steps = 24, window = 8)
env_id <- made$env

RRust

let made = client.strategy().env_make(mcp::StrategyEnvMakeArgs::new(paper_bench.clone()).interval("H1").max_steps(24).window(8))?;
let env_id = made["env"].as_str().unwrap_or_default().to_string();

2. Start at the last close. at_ms is the moment the market's last hour candle closed — its open time plus one hour, in milliseconds (UTC). Nothing moves: the episode starts where the market stands.

Python

now = client.strategy.env_reset(env_id, at_ms=last_close_ms)

JSJavaScript

const now = await client.strategy.envReset({ env: env_id, at_ms: last_close_ms });

C#C#

var now = await client.Strategy.EnvReset(env_id, atMs: last_close_ms);

GOGo

now := must(client.Strategy.EnvReset(ctx, mcp.StrategyEnvResetArgs{Env: env_id, AtMs: mcp.Ptr[int64](last_close_ms)}))

Java

Object now = client.strategy.envReset(new Bentrix.StrategyApi.EnvResetArgs(env_id).atMs(last_close_ms));

C++C++

auto now = client.strategy.env_reset(StrategyApi::EnvResetArgs(env_id).at_ms(last_close_ms));

Julia

now = client.strategy.env_reset(env_id; at_ms = last_close_ms)

RR

now <- client$strategy$env_reset(env_id, at_ms = last_close_ms)

RRust

let now = client.strategy().env_reset(mcp::StrategyEnvResetArgs::new(env_id.clone()).at_ms(last_close_ms.clone()))?;

3. At each close: act, wait, observe. Your policy reads now's observation and chooses; env_act sends the order; at the next close env_observe answers the reward and the next observation, exactly as env_step would.

Python

sent = client.strategy.env_act(env_id, 1)
print("outcome:", sent["outcome"])
# ... wait until the next hour candle has closed ...
now = client.strategy.env_observe(env_id, next_close_ms)
print("reward:", now["reward"])
print("equity:", now["info"]["equity"])

JSJavaScript

const sent = await client.strategy.envAct({ env: env_id, action: 1 });
console.log("outcome:", sent.outcome);
// ... wait until the next hour candle has closed ...
const now = await client.strategy.envObserve({ env: env_id, at_ms: next_close_ms });
console.log("reward:", now.reward);
console.log("equity:", now.info.equity);

C#C#

var sent = await client.Strategy.EnvAct(env_id, 1);
Console.WriteLine($"outcome: {sent!["outcome"]!}");
// ... wait until the next hour candle has closed ...
var now = await client.Strategy.EnvObserve(env_id, next_close_ms);
Console.WriteLine($"reward: {now!["reward"]!}");
Console.WriteLine($"equity: {now!["info"]!["equity"]!}");

GOGo

sent := must(client.Strategy.EnvAct(ctx, mcp.StrategyEnvActArgs{Env: env_id, Action: 1}))
fmt.Println("outcome:", at(sent, "outcome"))
// ... wait until the next hour candle has closed ...
now := must(client.Strategy.EnvObserve(ctx, mcp.StrategyEnvObserveArgs{Env: env_id, AtMs: next_close_ms}))
fmt.Println("reward:", at(now, "reward"))
fmt.Println("equity:", at(now, "info", "equity"))

Java

Object sent = client.strategy.envAct(new Bentrix.StrategyApi.EnvActArgs(env_id, 1));
System.out.println("outcome:" + " " + at(sent, "outcome"));
// ... wait until the next hour candle has closed ...
Object now = client.strategy.envObserve(new Bentrix.StrategyApi.EnvObserveArgs(env_id, next_close_ms));
System.out.println("reward:" + " " + at(now, "reward"));
System.out.println("equity:" + " " + at(now, "info", "equity"));

C++C++

auto sent = client.strategy.env_act(StrategyApi::EnvActArgs(env_id, 1));
std::cout << "outcome:" << " " << sent["outcome"].dump() << std::endl;
// ... wait until the next hour candle has closed ...
auto now = client.strategy.env_observe(StrategyApi::EnvObserveArgs(env_id, next_close_ms));
std::cout << "reward:" << " " << now["reward"].dump() << std::endl;
std::cout << "equity:" << " " << now["info"]["equity"].dump() << std::endl;

Julia

sent = client.strategy.env_act(env_id, 1)
println("outcome:", " ", sent["outcome"])
# ... wait until the next hour candle has closed ...
now = client.strategy.env_observe(env_id, next_close_ms)
println("reward:", " ", now["reward"])
println("equity:", " ", now["info"]["equity"])

RR

sent <- client$strategy$env_act(env_id, 1)
cat("outcome:", format(sent$outcome), "\n")
# ... wait until the next hour candle has closed ...
now <- client$strategy$env_observe(env_id, next_close_ms)
cat("reward:", format(now$reward), "\n")
cat("equity:", format(now$info$equity), "\n")

RRust

let sent = client.strategy().env_act(mcp::StrategyEnvActArgs::new(env_id.clone(), 1))?;
println!("outcome: {}", sent["outcome"]);
// ... wait until the next hour candle has closed ...
let now = client.strategy().env_observe(mcp::StrategyEnvObserveArgs::new(env_id.clone(), next_close_ms.clone()))?;
println!("reward: {}", now["reward"]);
println!("equity: {}", now["info"]["equity"]);

To wait for a close, follow the market's bars as they arrive — the SDK's follow the market guide does exactly that — and call env_observe when a new candle has closed.

02In Python, the waiting is done for you

bentrix.live.LiveEnv is TradingEnv on a live workbench: its reset() waits for a close and starts there, and each step(action) acts, waits for the next close and observes — the same Gymnasium contract as in the laboratory. bentrix.live.serve runs a policy on it:

import bentrix
from bentrix.live import LiveEnv, Model, Remote, serve

b = bentrix.connect(name="my-live-policy")
env = LiveEnv(paper_bench, "EURUSD", interval="H1", window=8, max_steps=24, door=Remote(b))
result = serve(Model(my_policy, timeout_s=0.25, fallback=0), env)
print(result["steps"], "closes;", result["fallbacks"], "fallbacks")

Model answers the policy's action within timeout_s, or fallback (flat) if the policy is late, so a slow model never misses a close by blocking it. result["journal"] records every decision — the moment, the observation's fingerprint, the action and the outcome — and bentrix.live.parity compares that journal with a laboratory workbench over the same days, to show the live run saw exactly what a laboratory step would have.

03What is different from the laboratory

LaboratoryLive
The clockthe environment moves itthe market moves it
env_resetrewinds and undoes dealsstarts at at_ms; nothing is undone
An episode endsits steps, the recording's end, or ruinmax_steps, a close with no new candle (moved: false), or ruin
infoledger_hashoutcome and live: true — a market does not repeat, so there is no hash to compare
A refused orderthe venue's sentencethe venue's or the broker's sentence

04outcome

env_act answers how the order went:

OutcomeMeans
sentthe order went to the venue
awaiting_personon a real account under Confirm, the order waits in the trade panel for your Send
refusedit was refused; refused carries the sentence

A change of side closes first and opens only once the close was sent. While a close waits for your Send, the opening waits too — it is never queued behind a close you have not approved.

05Before going live

  • Check that the live observations match what the laboratory gave at the same moments — bentrix.live.parity does it.
  • Keep lots small, and keep a real account's Automations on Confirm until you trust the policy.
  • Never let a policy you have not tested on unseen episodes trade a real account.

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