Market Structure

class markets.models.Account(*args, **kwargs)[source]

Represents a user’s bank account for a given market. Normal users are allowed only a primary account while admin users can create multiple secondary accounts.

place_order(market, position)[source]

Tries to place an order from this account on the given market with the given positions. Each position is a tuple of an outcome, and the amount to wager on that outcome.

Returns None if the position list is empty.

class markets.models.AccountBalance(*args, **kwargs)[source]

Represents the current holdings of an account for a given outcome (variable).

Contains the amount of shares held by present by the account owner.

static get(acc, outcome)[source]

Gets or creates the supply for the given account.

static reset(ev)[source]

Resets the account balances for all players and outcomes in the given event.

class markets.models.DataSet(id, market, name, description, is_training, is_active, datum_count, active_datum_id, challenge_start, reveal_interval)[source]
active_datum()[source]

Gets the active datum. Throws an exception if it does not exist.

challenge_duration()[source]

Gets a timedelta representation of the duration of a challenge.

challenge_end()[source]

Gets the DateTime the active challenge ends at.

If this challenge has a negative duration, it is assumed to continue indefinitely.

challenge_expired()[source]

Gets whether this set’s current challenge has expired.

force_advance()[source]

Forces the finalisation of this dataset’s current challenge and start the new one.

get_datum(set_id)[source]

Gets the datum with the specified set_id. Throws an exception if it does not exist.

get_outcomes()[source]

Gets all outcomes defined for this market.

has_data()[source]

Gets whether this dataset has any datums.

has_datum(id)[source]

Gets whether this DataSet contains a datum with the given id.

next()[source]

Advances this active set to the next datum (challenge) _once_, and raises the dataset_expired signal. If there is no datum with such id, the set is made inactive. Returns whether the set is active.

next_challenge_id()[source]

Gets the id of the next challenge (datum). Throws an exception if there is no such datum.

next_challenge_in()[source]

Gets the time remaining until this challenge ends as a string.

next_id()[source]

Retrieves an id for the next datum and advances self.datum_count.

random(n_data=10)[source]

Generates some random datums for this dataset.

reset()[source]

Resets active_datum_id to 0. If there is no datum with id of 0, an exception is thrown.

set_challenge(i)[source]

Sets the next challenge.

start()[source]

Sets this DataSet as the active set for its market.

class markets.models.Datum(*args, **kwargs)[source]

Represents an observation in the prediction market.

Defines a result for each event that was observed in this instance, along with a description specific to the observation.

is_valid()[source]

Checks whether this datum contains results for all market events.

static random(set, name='', description='')[source]

Creates a new datum with random results for the outcomes of this DataSet, and then saves it

class markets.models.Document(*args, **kwargs)[source]

A document uploaded by the user to be potentially used as a dataset source.

class markets.models.Event(*args, **kwargs)[source]

A set of outcomes for a market.

activity_histogram(dt_from, dt_to, interval)[source]

Gets the amount of trades that occured in the given time interval.

normalise_outcomes()[source]

Makes sure all outcomes sum to 1

price_histogram(dt_from, dt_to)[source]

Gets the price histogram for the event in the given time interval.

random_outcome()[source]

Draws a random outcome from this set.

class markets.models.Interval[source]
class markets.models.Market(id, name, description, pub_date, type)[source]
active_set()[source]

Gets the active dataset for this market, or None if the market is inactive.

api_accounts(u)[source]

Gets all API accounts created by the given user for this market.

challenge_end_ticks()[source]

Gets the challenge_end datetime in the form of ticks elapsed since the Epoch.

challenge_start_ticks()[source]

Gets the challenge_start datetime in the form of ticks elapsed since the Epoch.

create_primary_account(u)[source]

Creates a primary account for the given user. Throws an exception if the account exists.

is_active()[source]

Gets whether this market has an active dataset.

n_datasets()[source]

Gets the total number of datasets for this market.

n_events()[source]

Gets the total amount of events registered with this market.

parse_bid(post)[source]

Parses the data from the given POST request. Returns a list of tuples containing the amount wagered on each outcome for this market.

primary_account(u)[source]

Returns the user’s primary account for this market, or None if they are not registered.

class markets.models.MarketBalance(*args, **kwargs)[source]

The current market supply for a given outcome.

static accept_order(order)[source]

Adds the amounts from the given order to the market supply.

static for_event(ev)[source]

Gets the market maker supplies for all outcomes in the given event.

static get(outcome)[source]

Gets or creates the supply for the given outcome.

static reset(ev)[source]

Resets the market maker’s balance for all outcomes in the given event.

class markets.models.MarketType[source]

The different types of markets with regard to the market maker that is used.

class markets.models.Order(*args, **kwargs)[source]

A pending or already processed order from a user for some market

get_position(outcome)[source]

Gets this order’s position for the specified outcome.

group_by_event()[source]

Groups all positions in this order by their event. Returns a dictionary of the events with the list of positions on them as the value.

is_processed()[source]

Returns whether all positions in this order are processed.

static new(market, account, positions)[source]

Creates a new order for the specified market by the given account, specifying the provided positions.

static reset(ev)[source]

Cancels all orders for the given event.

set_processed()[source]

Marks all positions in this order as processed.

unprocessed_orders()[source]

Retrieves all unprocessed orders from the database.

class markets.models.Outcome(id, event, name, description, current_price, sell_offer, buy_offer)[source]
class markets.models.Position(*args, **kwargs)[source]

A player’s position (opinion) about a given outcome as part of an order.

partial_complete(pa, pb)[source]

Attempts to partially complete the given two positions.

In order to do so the positions must be of opposite type, compatible prices and on the same outcome.

The price at which the deal is completed is taken as the average of each player’s suggested price.

The amount of shares exchanged depends on the amounts defined by each position. In case one of the positions can be completed only partially, the amount of traded shares are subtracted from it and the trade is completed by creating a new Order which contains the fulfilled part of the transaction.

split(amount, price)[source]

Resolves a part of this position.

Returns the newly created order which partially completes the solution, or None if the position was fulfilled.

class markets.models.Result(*args, **kwargs)[source]

The actual outcome of a given event for the specified datum.