class bourse.core.StepEnv

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.

Examples

import bourse

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

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

# Create an order to be placed in the
# next update
order_id = env.place_order(
    True, 100, 99, price=50
)

# Update the environment
env.step()

# Get price history data
bid_price, ask_prices = env.get_prices()

StepEnv Methods

StepEnv(**kwargs)

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

cancel_order(order_id: int)

Submit a cancel order transaction

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_prices() tuple[numpy.ndarray, numpy.ndarray]

Get touch price histories

get_touch_order_counts() tuple[numpy.ndarray, numpy.ndarray]

Get touch volume histories

get_touch_volumes() tuple[numpy.ndarray, numpy.ndarray]

Get touch volume histories

get_trade_volumes() numpy.ndarray

Get trade volume history

get_trades() list[tuple]

Get trade data

get_volumes() tuple[numpy.ndarray, numpy.ndarray]

Get volume histories

level_1_data_array() numpy.ndarray

Get current level 1 data as a Numpy array

level_2_data_array() numpy.ndarray

Get current level 2 data as a Numpy array

modify_order(order_id: int, new_price: int = None, ...)

Submit an transaction to modify an order

order_status(order_id: int) int

Get the status of an order

place_order(bid: bool, vol: int, trader_id: int, ...) int

Submit a new-order transaction

step()

Update the state of the environment

StepEnv Attributes

ask_vol

Current total ask side volume

best_ask_vol

Current ask side touch volume

best_ask_vol_and_orders

Current ask touch volume and order count

best_bid_vol

Current bid side touch volume

best_bid_vol_and_orders

Current bid touch volume and order count

bid_ask

Current bid-ask prices

bid_vol

Current total bid side volume

time

Current simulated time

trade_vol

Trade volume in the last step