Skip to main content

Wickra Gym — a Gymnasium-compatible, microstructure-aware backtest environment with O(1) steps for fast, deterministic RL rollouts

CI codecov PyPI License: MIT OR Apache-2.0

Wickra Gym — Python


Part of the Wickra ecosystem — for Python. pip install wickra-gym — prebuilt wheels for Linux, macOS and Windows, nothing to compile.

A deterministic, Gymnasium-compatible backtest environment. The whole candle dataset is precomputed once into a fixed feature tensor, so each step() is a constant-time array index — and the same spec, data, seed and actions produce a byte-identical trajectory across every language binding.

Install

pip install wickra-gym

Pre-built wheels ship for Linux, macOS and Windows — there is nothing to compile and no C library to track down.

Quick start

examples/python/rollout.py is the runnable example the CI smoke job executes; in full:

"""Raw rollout over the native command surface (no Gymnasium required).

    python examples/python/rollout.py

Reads the momentum_discrete spec and its candle dataset, then drives a fixed
long policy through the environment via ``RawEnv.command`` — the same JSON-in /
JSON-out boundary every language binding forwards verbatim, so this trajectory
is byte-identical to the C, Node, Go, C#, Java and R examples on the same seed.
"""

import json
from pathlib import Path

from wickra_gym import RawEnv, __version__

DATA = Path(__file__).resolve().parent.parent / "data"

def main() -> None:
    spec = (DATA / "specs" / "momentum_discrete.json").read_text()
    candles = json.loads((DATA / "candles.json").read_text())

    env = RawEnv(spec)
    env.command(json.dumps({"cmd": "load", "candles": candles}))

    reset = json.loads(env.command(json.dumps({"cmd": "reset", "seed": 42})))
    print(f"wickra-gym {__version__}")
    print("reset observation:", reset["observation"])

    equity = 0.0
    step = 0
    while True:
        result = json.loads(env.command(json.dumps({"cmd": "step", "action": 2})))
        equity += result["reward"]
        print(
            f"step {step}: reward {result['reward']:+.6f}  equity {equity:+.6f}  "
            f"terminated={result['terminated']} truncated={result['truncated']}"
        )
        if result["terminated"] or result["truncated"]:
            break
        step += 1

if __name__ == "__main__":
    main()

Use as a Gymnasium environment

import numpy as np
from wickra_gym import WickraGymEnv

spec = """{
  "dataset_ref": "demo", "symbol": "BTCUSDT",
  "observation": {"features": [
    {"kind": "price", "field": "close"},
    {"kind": "indicator", "name": "Rsi", "params": [14]}
  ]},
  "action_space": {"type": "discrete", "n": 3},
  "reward": "pnl",
  "episode": {"max_steps": 256, "warmup": 14}
}"""

candles = [
    {"ts": i, "open": 100 + i, "high": 100 + i, "low": 100 + i, "close": 100 + i}
    for i in range(300)
]

env = WickraGymEnv(spec, candles)
obs, info = env.reset(seed=0)
done = False
while not done:
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    done = terminated or truncated

The observation and action spaces are derived from the spec: unbounded observation columns use ±np.inf; a discrete action space becomes spaces.Discrete(n) and a continuous one becomes a 1-D spaces.Box.

Register it under a Gymnasium id:

from wickra_gym import register
register()  # WickraGym-v0

The raw command surface

RawEnv is the thin, dependency-free wrapper over the native command JSON surface — the same boundary every language binding forwards verbatim:

import json
from wickra_gym import RawEnv

env = RawEnv(spec)
env.command(json.dumps({"cmd": "load", "candles": candles}))
reset = json.loads(env.command(json.dumps({"cmd": "reset", "seed": 0})))
step = json.loads(env.command(json.dumps({"cmd": "step", "action": 2})))

Commands: load, reset, step, spec, version. Domain errors come back as {"ok": false, "error": ...}; a bad spec raises ValueError at construction.

Benchmark

Every binding forwards to the same data-driven Rust core, so what this one adds is the call overhead of PyO3, not a different result. The core's throughput is measured by the repository's benchmark suite and the nightly bench.yml run; the numbers, the machine and how to reproduce them are in the repository BENCHMARKS.md.

Documentation

The full guide, the spec reference and the API documentation live in the main repository and the documentation site:

Wickra Gym ships native bindings for Python, Node.js, WASM and Rust, plus a C ABI hub that any C-capable language (C, C++, C#, Go, Java, R) links against — all forwarding to the same data-driven, unsafe-forbidden Rust core.

Security

Found a security issue? Please don't open a public issue. Report it privately via the repository's Security tab ("Report a vulnerability") or email support@wickra.org with a subject line starting [wickra security]. Full policy: https://github.com/wickra-lib/wickra-gym/blob/main/SECURITY.md.

Disclaimer

wickra-gym is research and engineering tooling, not financial advice. A trained agent's backtested performance says nothing about future returns; markets carry risk and you are responsible for your own decisions. wickra-gym is free software you run yourself: no hosted service, no data collection, no warranty.

License

Licensed under either of Apache-2.0 or MIT at your option.

Release files for wickra-gym 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wickra-gym 0.1.5
File Size Uploaded
wickra_gym-0.1.5.tar.gz 75.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for wickra-gym 0.1.5
File
wickra_gym-0.1.5-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details
wickra_gym-0.1.5-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
wickra_gym-0.1.5-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
wickra_gym-0.1.5-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
wickra_gym-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
wickra_gym-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
wickra_gym-0.1.5-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
wickra_gym-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.6 MB

Release files / wickra_gym-0.1.5.tar.gz

Download URL wickra_gym-0.1.5.tar.gz
Size 75.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d5a498957e46d3aad76bcd4847c706b27837c47b8ca131b5fbc9e67768ae719a
BLAKE2b-256 checksum
How to use checksums
07f24fc5491f004c9da1a67d115540fcf64ca022e12018ffe8d68bb1102bb900
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-win_arm64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-win_arm64.whl
Size 522.8 kB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
949cf66a3361fcfa5b0b9ea8b27354f6537b3598c22c40efcce20eaf2682d9ff
BLAKE2b-256 checksum
How to use checksums
b7283808e8c383c87b9a2b552dd48467a02db9d22cfca97d4185c182d2a91e20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-win_amd64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-win_amd64.whl
Size 596.8 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7bc677cea91e0bd6bd02ec47f5f06fdd094cf1f7c12518e074cfb19da7f118c6
BLAKE2b-256 checksum
How to use checksums
14e3d313acd75decf09da4c6f5c67304d7b0c4b984e20f9559d99e85aaf2a276
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-musllinux_1_2_x86_64.whl
Size 936.7 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7b844d6f078ad9ead8b41627ec780e587899e35881ed57b30bab55776b6e1d8d
BLAKE2b-256 checksum
How to use checksums
245bd95cc89118499544adbb7db3b1966e1e2edab9b2a5ee26687f6a72fdf10f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-musllinux_1_2_aarch64.whl
Size 825.5 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
19401c1059e8302736bba8e3cbe91965ed429fbb778c873d5a006f8a8bfd9cf2
BLAKE2b-256 checksum
How to use checksums
008a72563e30ee29f415b9b2ed2447748355d7015e6f8fa79da145fabd7188e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 720.6 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
dcacff755c65d5f0bc81cd87a1dc7e14aacf6543d967a4f96aad90a682dc6462
BLAKE2b-256 checksum
How to use checksums
fdf1558acd2a59c61d300976c702bfb347db8c803a14ee8eddeba17cd23e0783
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 646.9 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
bafe8d3f4f8f135089331c9f404f7d388e44290d652b2dc64c0777aecda69a76
BLAKE2b-256 checksum
How to use checksums
126e314c3a63db1f554f65192c2a6364df59aba7b38ac523c1dd5dfe324be4d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-macosx_11_0_arm64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
Size 593.5 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ff6b3c0ea1f1763d4e90ef4a66a16e3541d11261cfd5aa32152e714ba1f8864b
BLAKE2b-256 checksum
How to use checksums
1c2e0375062e0110b0f93a157774763f954ba5a5f0f2964375536164c7d17d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / wickra_gym-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl

Download URL wickra_gym-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
Size 686.4 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ddfb05e563e506041596ada5811381b1f34313245e870631b043f7e0baedfebf
BLAKE2b-256 checksum
How to use checksums
bdec41c2102122c21130aa0805b7be6fc93033f1d8833be304005a2af30edb6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.1.5 This release

9 release files

0.1.4

9 release files

0.1.3

9 release files

0.1.2

9 release files

0.1.1

9 release files

0.1.0

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page