class bourse.core.StepEnvNumpy

Discrete event simulation environment

Simulation environment wrapping an orderbook and functionality to update the state of the simulation. This environment is designed for discrete event simulations, where each step agents submit transactions to the market that are shuffled and executed as a batch at the end of each step. Hence there is no guarantee of the ordering of transactions. Agents do not directly alter the state of the market, rather they do by submitting transactions to be processed.

This environment returns data and receives instructions via Numpy arrays.

Examples

import numpy as np
import bourse

seed = 101
start_time = 0
tick_size = 1
step_size = 1000

env = bourse.core.StepEnvNumpy(
    seed, start_time, tick_size, step_size
)

# Submit orders via Numpy arrays
order_ids = env.submit_limit_orders(
    (
        np.array([True, False]),
        np.array([10, 20], dtype=np.uint32),
        np.array([101, 202], dtype=np.uint32),
        np.array([50, 55], dtype=np.uint32),
    ),
)

# Update the environment
env.step()

# Cancel orders
env.submit_cancellations(order_ids)

# Get level-2 data history
level_2_data = env.get_market_data()

StepEnvNumpy Methods

StepEnvNumpy(**kwargs)

Create and return a new object. See help(type) for accurate signature.

disable_trading()

Disable trading

enable_trading()

Enable trading

get_market_data() dict[str, numpy.ndarray]

Get simulation market data

get_orders() list[tuple]

Get order data

get_trades() list[tuple]

Get trade data

level_1_data() numpy.ndarray

Get current level 1 data as a Numpy array

level_2_data() numpy.ndarray

Get current level 2 data as a Numpy array

step()

Update the state of the environment

submit_cancellations(order_ids: numpy.ndarray)

Submit a Numpy array of order ids to cancel

submit_instructions(instructions)

Submit market instructions as a tuple of Numpy arrays. This allows new limit orders and cancellations to be submitted from a tuple of Numpy arrays. Values that are not used for instructions (e.g. order-id for a new-order) can be set to a default value that will be ignored.

submit_limit_orders(orders)

Submit new limit orders from a Numpy array