Gym CryptoTrading Environment

license dep2 dep3 dep4

Gym Environment API based Bitcoin trading simulator with continuous observation space and discrete action space. It uses real world transactions from CoinBaseUSD exchange to sample per minute closing, lowest and highest prices along with volume of the currency traded in the particular minute interval.

Contents of this document

Installation

git clone https://github.com/samre12/gym-cryptotrading.git
cd gym-cryptotrading
pip install -e .

Usage

Importing the module into the current session using import gym_cryptotrading will register the environment with gym after which it can be used as any other gym environment.

Environments

import gym
import gym_cryptotrading
env = gym.make('RealizedPnLEnv-v0')

Setting the logging level of gym using gym.logger.set_level(level) to a value less than or equal 10 will allow to track all the logs (debug and info levels) generated by the environment.
These include human readable timestamps of Bitcoin prices used to simulate an episode.
For more information on gym.logger and setting logging levels, visit here .

Note: Custom loggers can also be provided to environments using env.env.set_logger(logger=)

Basics

Observation Space

Each entry in the observation is the ratio of increase (value greater than 1.0) or decrease (value lessar than 1.0) from the price at previos time instant.

Action Space

At each time step, the agent can either go LONG or SHORT in a unit (for more information , refer to Parameters) of Bitcoin or can stay NEUTRAL.
Action space thus becomes discrete with three possible actions:

Note: Use env.action_space.get_action(action) to lookup action names corresponding to their respective values.

Parameters

The basic environment is characterized with these parameters:

Usage

env = gym.make('RealizedPnLEnv-v0')
env.env.set_params(history_length, horizon, unit)

Note: parameters can only be set before first reset of the environment, that is, before the first call to env.reset(), else gym_cryptotrading.errors.EnvironmentAlreadyLoaded will be raised.

Some environments contain their own specific parameters due to the nature of their reward function.
These parameters can be passed using env.env.set_params(history_length, horizon, unit, **kwargs) as keyworded arguements alongside setting history length, horizon and unit.

Simulator

Dataset

Per minute Bitcoin series is obtained by modifying the procedure mentioned in this repository. Transactions in the Coinbase exchange are sampled to generate the Bitcoin price series.

Sample logs generated by the simulator while preprocessing the dataset:

INFO: Columns found in the dataset Index([u'DateTime_UTC', u'Timestamp', u'price_open', u'price_high',
       u'price_low', u'price_close', u'volume'],
      dtype='object')
INFO: Number of blocks of continuous prices found are 58880
INFO: Number of usable blocks obtained from the dataset are 1651
INFO: Number of distinct episodes for the current configuration are 838047

Important Information

Upon first use, the environment downloads latest transactions dataset from the exchange which are then cached in tempory directory of the operating system for future use.

Examples

Coming soon.

Recent Updates and Breaking Changes

Listing changes from b9af98db728230569a18d54dcfa87f7337930314 commit. Visit here to browse the repository with head at this commit.

Breaking Changes