AminHP / gym-anytrading

The most simple, flexible, and comprehensive OpenAI Gym trading environment (Approved by OpenAI Gym)
MIT License
2.09k stars 459 forks source link

Add render_mode='rgb_array' #96

Open ipsec opened 9 months ago

ipsec commented 9 months ago

Hi,

Some algorithms uses rgb_array render mode.

env = gym.make(env_id, render_mode='rgb_array')

I'm getting error:

gym_anytrading/envs/trading_env.py", line 29, in __init__ assert render_mode is None or render_mode in self.metadata['render_modes']

Thanks

AminHP commented 4 months ago

Hello @ipsec , As far as I know, the render_mode parameter is just used for visualization purposes. It doesn't affect the underlying algorithms and computations.

twbrandon7 commented 3 months ago

Hi there!

The assertion failed because the rgb_array render mode is not currently supported. I'd be happy to contribute a fix for this. Here's what I propose:

  1. Add 'rgb_array' to the list of supported render modes in gym_anytrading/envs/trading_env.py#25.
  2. Create a class `PriceRendererˋ and offload the rendering-related code to it.
  3. Implement a render function for rgb_array mode: We'll need to add code within the TradingEnv.render() method to convert the Matplotlib plot to a NumPy array.

Would this approach be aligned with the project's direction? I'm happy to create a pull request with these changes once we have confirmation.

Thanks!