Skip to content

contango.trading.execution.engine.fills.fill_policy

contango.trading.execution.engine.fills.fill_policy

FillPolicy

FillPolicy(rules: tuple[FillRule[T], ...])

Bases: Generic[T]

The policy for a certain mode of trading to pre-validate that all trading rules are met.

Initializes FillPolicy.

Parameters:

Name Type Description Default
rules tuple[FillRule[T], ...]

An iterable of fill rules for the policy.

required
Source code in src\contango\trading\execution\engine\fills\fill_policy.py
15
16
17
18
19
20
21
22
def __init__(self, rules: tuple[FillRule[T], ...]) -> None:
    """
    Initializes `FillPolicy`.

    Args:
        rules: An iterable of fill rules for the policy.
    """
    self._rules = rules

validate_rules

validate_rules(context: T) -> str | None

Validates all rules for the policy.

Returns:

Type Description
str | None

str | None: The violation reason for the first violated rule, or None if none were violated.

Source code in src\contango\trading\execution\engine\fills\fill_policy.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def validate_rules(self, context: T) -> str | None:
    """
    Validates all rules for the policy.

    Returns:
        str | None: The violation reason for the first violated rule, or `None` if none were violated.
    """
    for rule in self._rules:
        passing = rule.validate(context)

        if not passing:
            return rule.reason

    return None