Market Classes#

Subpackages#

Submodules#

assume.markets.base_market module#

class assume.markets.base_market.MarketMechanism(marketconfig: MarketConfig)#

Bases: object

This class represents a market mechanism.

It is different than the MarketRole, in the way that the functionality is unrelated to mango. The MarketMechanism is embedded into the general MarketRole, which takes care of simulation concerns. In the Marketmechanism, all data needed for the clearing is present.

all_orders#

The list of all orders.

Type:

Orderbook

marketconfig#

The configuration of the market.

Type:

MarketConfig

open_auctions#

The list of open auctions.

Type:

set

results#

The list of market metadata.

Type:

list[dict]

Parameters:

marketconfig (MarketConfig) – The configuration of the market.

clear(orderbook: list[assume.common.market_objects.Order], market_products: list[assume.common.market_objects.MarketProduct]) tuple[list[assume.common.market_objects.Order], list[assume.common.market_objects.Order], list[dict]]#

Clears the market.

Parameters:
  • orderbook (Orderbook) – The orderbook to be cleared.

  • market_products (list[MarketProduct]) – The products to be traded.

Returns:

The empty accepted orderbook, the empty rejected orderbook and the empty market metadata.

Return type:

(Orderbook, Orderbook, list[dict])

validate_orderbook(orderbook: list[assume.common.market_objects.Order], agent_tuple: tuple) None#

Validates a given orderbook.

This is needed to check if all required fields for this mechanism are present.

Parameters:
  • orderbook (Orderbook) – The orderbook to be validated.

  • agent_tuple (tuple) – The tuple of the agent.

Raises:

AssertionError – If the orderbook is invalid.

validate_registration(content: RegistrationMessage, meta: MetaDict) bool#

Validates a given registration. Used to check if a participant is eligible to bid on this market.

Parameters:
Returns:

True if the registration is valid, False otherwise.

Return type:

bool

class assume.markets.base_market.MarketRole(marketconfig: MarketConfig)#

Bases: MarketMechanism, Role

This is the base class for all market roles. It implements the basic functionality of a market role, such as registering agents, clearing the market and sending the results to the database agent.

Parameters:

marketconfig (MarketConfig) – The configuration of the market.

async clear_market(market_products: list[assume.common.market_objects.MarketProduct])#

This method clears the market and sends the results to the database agent.

Parameters:

market_products (list[MarketProduct]) – The products to be traded.

handle_data_request(content: DataRequestMessage, meta: MetaDict)#

This method handles incoming data request messages.

Parameters:
Raises:

AssertionError – If the order book is invalid.

handle_get_unmatched(content: dict, meta: MetaDict)#

A handler which sends the orderbook with unmatched orders to an agent and allows to query a subset of the orderbook.

Parameters:
  • content (dict) – The content of the message.

  • meta (MetaDict) – The metadata of the message.

Raises:

AssertionError – If the order book is invalid.

handle_orderbook(content: OrderBookMessage, meta: MetaDict)#

Handles incoming order book messages and validates th order book and adds it to the list of all orders.

Parameters:
Raises:

AssertionError – If the order book is invalid.

handle_registration(content: RegistrationMessage, meta: MetaDict)#

This method handles incoming registration messages and adds the sender of the message to the list of registered agents.

Parameters:
latitude: float#
longitude: float#
marketconfig: MarketConfig#
async opening()#

Sends an opening message to all registered agents, handles scheduling the clearing of the market and the next opening.

registered_agents: dict[tuple[str, str], dict]#
required_fields: list[str] = []#
setup()#

This method sets up the initial configuration and subscriptions for the market role.

It sets the address and agent ID of the market config to match the current context. It Defines three filter methods (accept_orderbook, accept_registration, and accept_get_unmatched) that serve as validation steps for different types of incoming messages. Subscribes the role to handle incoming order book messages using the handle_orderbook method. Subscribes the role to handle incoming registration messages using the handle_registration method If the market configuration supports “get unmatched” functionality, subscribes the role to handle such messages using the handle_get_unmatched. Schedules the opening() method to run at the next opening time of the market.

Raises:

AssertionError – If a required field is missing.

async store_market_results(market_meta)#

Sends a message to the OutputRole to update data in the database.

Parameters:

market_meta – The metadata of the market.

async store_order_book(orderbook: list[assume.common.market_objects.Order])#

Sends a message to the OutputRole to update data in the database.

Parameters:

orderbook (Orderbook) – The order book to be stored.

Module contents#