TradingGym is an open-source Python environment on GitHub for training reinforcement learning trading agents and backtesting trading strategies. With roughly 1,900 stars, it gives quant developers a Gym-style playground where algorithms can practice buying and selling against historical market data before risking real money.
The library wraps market data in an environment interface familiar to anyone who has used OpenAI Gym-style APIs: an agent observes market states, chooses actions such as buy, sell or hold, and receives rewards based on portfolio performance. The same environment doubles as a backtesting engine, so simple rule-based strategies can be evaluated through exactly the same loop as learned agents. TradingGym handles the bookkeeping of positions, cash and executed trades, and can render trading activity for inspection. It accepts your own price data, which makes it usable across stocks, crypto and other time-series markets. The codebase is compact and readable, making it a popular teaching and prototyping tool for algorithmic trading with machine learning.
Because the environment follows familiar reinforcement learning conventions, agents built with common RL libraries can be plugged in with little glue code, and experiments can swing between pure backtesting and full agent training without changing the surrounding pipeline.
TradingGym is free and open source under the MIT license. It can be installed from GitHub and used in commercial or research projects without fees; you only supply your own market data and compute for training agents.
TradingGym is for quant developers, ML researchers and students who want to prototype reinforcement learning for trading, compare agent policies against simple baselines, and learn how trading environments are constructed before moving to production-grade backtesting stacks.