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:
  • ValueError – If max_price, min_price, or max_volume are unset when required.

  • KeyError – If a required field is missing in an order.

  • TypeError – If order[‘price’] or order[‘volume’] is not an integer when required.

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)#

Handles incoming data request messages.

Parameters:
handle_get_unmatched(content: dict, meta: MetaDict)#

Sends the orderbook with unmatched orders to an agent and allows querying a subset of the orderbook.

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

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

Raises:

KeyError – If required keys (‘sender_addr’, ‘sender_id’) are missing in meta.

handle_orderbook(content: OrderBookMessage, meta: MetaDict)#

Handles incoming order book messages, validates the order book, and adds valid orders to the list of all orders.

If the order book is invalid or an error occurs during processing, logs the error and sends a single rejection message to the sender.

Parameters:
  • content (OrderBookMessage) – The content of the message, expected to contain an ‘orderbook’.

  • meta (MetaDict) – The metadata of the message, expected to contain ‘sender_addr’ and ‘sender_id’.

Raises:
  • KeyError – If required keys (‘orderbook’, ‘sender_addr’, ‘sender_id’) are missing in the message.

  • ValueError – If the order book fails validation.

  • Exception – If an unexpected error occurs during processing.

handle_registration(content: RegistrationMessage, meta: MetaDict)#

Handles incoming registration messages and adds the sender to the list of registered agents.

This method performs the following actions:
  • Validates that the incoming message’s market ID matches the current market configuration.

  • Validates the registration details using the validate_registration method.

  • Registers the agent if validation is successful.

  • Sends a registration reply message indicating acceptance or rejection.

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

  • meta (MetaDict) – The metadata of the message, including sender information.

Raises:

KeyError – If required keys are missing in content or meta.

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()#

Sets up the initial configuration and subscriptions for the market role.

This method performs the following actions:
  • Sets the address and agent ID of the market configuration to match the current context.

  • Validates that all required fields are present in the market configuration.

  • Defines filter methods (accept_orderbook, accept_registration, accept_get_unmatched, accept_data_request)

that serve as validation steps for different types of incoming messages. - Subscribes the role to handle incoming messages using the appropriate handler methods. - Schedules the opening() method to run at the next opening time of the market. - Sends grid topology data once, if available.

Raises:

ValueError – If a required field is missing from the market configuration.

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#