ManifoldMarketManager

Manifold Market Manager Library.

This module provides the ability to construct a Manifold Markets manager bot. In particular, it gives you a framework to have automatically resolving markets. A future goal may be to allow trading, but this will likely be done using limits, rather than time sensitive trades. Expect intervals of minutes, not microseconds.

In order to use this library, some things need to be loaded in your environment variables. See the comments below for more information on this.

class ManifoldMarketManager.DoResolveRule[source]

Bases: Rule[Optional[bool]]

The subtype of rule which determines if a market should resolve, returning a bool.

_abc_impl = <_abc_data object>
abstract _explain_abstract(indent: int = 0, **kwargs: Any) str
_explain_specific(market: Market, indent: int = 0, sig_figs: int = 4) str
_is_protocol = False
abstract _value(market: Market) T
explain_abstract(indent: int = 0, **kwargs: Any) str

Explain how the market will resolve and decide to resolve.

explain_specific(market: Market, indent: int = 0, sig_figs: int = 4) str

Explain why the market is resolving the way that it is.

classmethod from_dict(env: ModJSONDict) T

Take a dictionary and return an instance of the associated class.

logger: Logger
tags_used: set[str]
value(market: Market, format: Literal['NONE'] | OutcomeType = 'NONE', refresh: bool = False) AnyResolution

Return the resolution value of a market, appropriately formatted for its market type.

class ManifoldMarketManager.Market(market: APIMarket, notes: str = '', account: Account = <factory>, do_resolve_rules: list[Rule[Optional[bool]]] = <factory>, resolve_to_rules: list[Rule[AnyResolution]] = <factory>)[source]

Bases: DictDeserializable

Represent a market and its corresponding rules.

Events

before_check(market: Market): after_check(market: Market):

Called before/after a market is checked. Please don’t put anything intensive in here.

before_create(market: Market): after_create(market: Market):

Called before/after a market is created.

before_resolve(market: Market, outcome: AnyResolution): after_resolve(market: Market, outcome: AnyResolution, response: Response):

Called before/after a market is resolved. Please don’t put anything intensive in here.

before_remove(market: Market): after_remove(market: Market):

Called before/after a market is removed from the database.

__format_resolve_to(sig_figs: int) str
_after_resolve(market: Market, outcome: AnyResolution, response: Response) None[source]
account: Account
cancel(**kwargs: Any) T
client: ManifoldClient
current_answer() AnyResolution[source]

Return the current market consensus.

do_resolve_rules: list[Rule[Optional[bool]]]
event_emitter: EventEmitter
explain_abstract(**kwargs: Any) str[source]

Explain how the market will resolve and decide to resolve.

explain_specific(sig_figs: int = 4) str[source]

Explain why the market is resolving the way that it is.

classmethod from_dict(env: ModJSONDict) Market[source]

Take a dictionary and return an instance of the associated class.

classmethod from_id(id: str, *args: Any, **kwargs: Any) Market[source]

Reconstruct a Market object from the market ID and other arguments.

classmethod from_slug(slug: str, *args: Any, **kwargs: Any) Market[source]

Reconstruct a Market object from the market slug and other arguments.

classmethod from_url(url: str, *args: Any, **kwargs: Any) Market[source]

Reconstruct a Market object from the market url and other arguments.

property id: str

Return the ID of a market as reported by Manifold.

logger: Logger = None
market: APIMarket
notes: str = ''
on(*args, **kwargs)[source]

Register an event with EventEmitter.

refresh() None[source]

Ensure market data is recent.

resolve(**kwargs: Any) T
resolve_to() AnyResolution[source]

Select a value to be resolved to.

This is done by iterating through a series of Rules, each of which have opportunity to recommend a value. The first resolved value is resolved to.

Binary markets must return a float between 0 and 100. Numeric markets must return a float in its correct range. Free response markets must resolve to either a single index integer or

a mapping of indices to weights.

Any rule may return “CANCEL” to instead refund all orders.

resolve_to_rules: list[Rule[AnyResolution]]
should_resolve() bool[source]

Return whether the market should resolve, according to our rules.

property status: MarketStatus

Return whether a market is OPEN, CLOSED, or RESOLVED.

class ManifoldMarketManager.ResolutionValueRule[source]

Bases: Rule[Union[Literal[‘CANCEL’], bool, float, Mapping[str, float], Mapping[int, float], Mapping[float, float]]]

The subtype of rule which determines what a market should resolve to.

_abc_impl = <_abc_data object>
abstract _explain_abstract(indent: int = 0, **kwargs: Any) str
_explain_specific(market: Market, indent: int = 0, sig_figs: int = 4) str
_is_protocol = False
abstract _value(market: Market) T
explain_abstract(indent: int = 0, **kwargs: Any) str

Explain how the market will resolve and decide to resolve.

explain_specific(market: Market, indent: int = 0, sig_figs: int = 4) str

Explain why the market is resolving the way that it is.

classmethod from_dict(env: ModJSONDict) T

Take a dictionary and return an instance of the associated class.

logger: Logger
tags_used: set[str]
value(market: Market, format: Literal['NONE'] | OutcomeType = 'NONE', refresh: bool = False) AnyResolution

Return the resolution value of a market, appropriately formatted for its market type.

class ManifoldMarketManager.Rule[source]

Bases: ABC, Generic[T], DictDeserializable

The basic unit of market automation, rules defmine how a market should react to given events.

__binary_value(market: Market, ret: Any) float
__multiple_choice_value(market: Market, ret: Any) Mapping[int, float]
_abc_impl = <_abc_data object>
abstract _explain_abstract(indent: int = 0, **kwargs: Any) str[source]
_explain_specific(market: Market, indent: int = 0, sig_figs: int = 4) str[source]
_is_protocol = False
abstract _value(market: Market) T[source]
explain_abstract(indent: int = 0, **kwargs: Any) str[source]

Explain how the market will resolve and decide to resolve.

explain_specific(market: Market, indent: int = 0, sig_figs: int = 4) str[source]

Explain why the market is resolving the way that it is.

classmethod from_dict(env: ModJSONDict) T

Take a dictionary and return an instance of the associated class.

logger: Logger
tags_used: set[str]
value(market: Market, format: Literal['NONE'] | OutcomeType = 'NONE', refresh: bool = False) AnyResolution[source]

Return the resolution value of a market, appropriately formatted for its market type.

ManifoldMarketManager.get_client(account: Optional[Account] = None) ManifoldClient[source]

Return a (possibly non-unique) Manifold client.

ManifoldMarketManager.require_env(*env: str) Callable[[Callable[..., T]], Callable[..., T]][source]

Enforce the presence of environment variables that may be necessary for a function to properly run.