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.

Metadata

Release files for wickra-gym 0.1.6

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.6
File Size Uploaded
wickra_gym-0.1.6.tar.gz 75.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for wickra-gym 0.1.6
File
wickra_gym-0.1.6-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details
wickra_gym-0.1.6-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
wickra_gym-0.1.6-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
wickra_gym-0.1.6-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
wickra_gym-0.1.6-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.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
wickra_gym-0.1.6-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
wickra_gym-0.1.6-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.6.tar.gz

Download URL wickra_gym-0.1.6.tar.gz
Size 75.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c0638eadfe38de067e782639bae6bc6834d80045abc7c55ccd16310df6ddd9ca
BLAKE2b-256 checksum
How to use checksums
8de76c93c42dfa8b570852798679ccabd93c8cb8d73f3d4b5d8173ffcbe1b7a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

Download URL wickra_gym-0.1.6-cp39-abi3-win_amd64.whl
Size 597.1 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f9ba41d5ac38ef5efe308e3918ab1f2eeb9f08e8ea58b0a4bc0dd39cee35a116
BLAKE2b-256 checksum
How to use checksums
780bc7300f7dfbfed948d378b3f748f422797e26965274a30a523320e51ac4bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

Download URL wickra_gym-0.1.6-cp39-abi3-musllinux_1_2_aarch64.whl
Size 825.7 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
8abd1eadc4d1b0a8e824ee0d3f11a50730fcbcd327aa97bb36b72dd66c225e0e
BLAKE2b-256 checksum
How to use checksums
49b081a465394ee2badd36f2f9db6211fdeab293a764d1dcff2909e703444fb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

Download URL wickra_gym-0.1.6-cp39-abi3-macosx_11_0_arm64.whl
Size 593.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7c8af5ddb80ac0514747e61f89cf5866e8312162dbfccbfc93aac6fad5199b83
BLAKE2b-256 checksum
How to use checksums
3ddb21d66955b390d64e0623ec9101fd9f1072fb09dd6d9ef8806fdcade3cfe8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

Release history Release notifications | RSS feed

0.2.0

9 release files

This release

0.1.6 This release

9 release files

0.1.5

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