Skip to content

trading.execution.engine.orders.order_api

trading.execution.engine.orders.order_api

OrderAPI

OrderAPI(event_bus: EventBus)

API that allows OrderEvent instances to be published to the execution engine.

Initializes OrderAPI.

Parameters:

Name Type Description Default
event_bus EventBus

The event bus to publish OrderEvent objects to.

required
Source code in src\contango\trading\execution\engine\orders\order_api.py
31
32
33
34
35
36
37
38
def __init__(self, event_bus: EventBus) -> None:
    """
    Initializes `OrderAPI`.

    Args:
        event_bus: The event bus to publish `OrderEvent` objects to.
    """
    self._event_bus = event_bus

submit_order

submit_order(market_data: MarketDataEvent, symbol: str, quantity: units, reason: str | None = None) -> None

Submits a market order object to the engine.

Attributes:

Name Type Description
market_data

The market data event for the order.

symbol

The symbol to create the order for.

quantity

The amount of units of the symbol to trade (positive or negative depending on buy or sell).

reason

The optional reason for the trade.

Source code in src\contango\trading\execution\engine\orders\order_api.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def submit_order(
    self, 
    market_data: MarketDataEvent, 
    symbol: str, 
    quantity: units,
    reason: str | None = None,
) -> None:
    """
    Submits a market order object to the engine.

    Attributes:
        market_data: The market data event for the order.
        symbol: The symbol to create the order for.
        quantity: The amount of units of the symbol to trade (positive or negative depending on buy or sell).
        reason: The optional reason for the trade.
    """
    order = OrderEvent(
        market_data.timestamp,
        quantity=quantity,
        reason=reason
    )
    self._event_bus.publish(order)

submit_stoploss_order

submit_stoploss_order(market_data: MarketDataEvent, symbol: str, quantity: units, stoploss_price: USD, reason: str | None = None) -> None

Submits a stoploss order object to the engine.

Attributes:

Name Type Description
market_data

The market data event for the order.

symbol

The symbol to create the order for.

quantity

The amount of units of the symbol to trade (positive or negative depending on buy or sell).

stoploss_price

The price in which the quantity amount of shares will be sold upon being met.

reason

The optional reason for the trade.

Source code in src\contango\trading\execution\engine\orders\order_api.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
def submit_stoploss_order(
    self, 
    market_data: MarketDataEvent, 
    symbol: str, 
    quantity: units,
    stoploss_price: USD,
    reason: str | None = None,
) -> None:
    """
    Submits a stoploss order object to the engine.

    Attributes:
        market_data: The market data event for the order.
        symbol: The symbol to create the order for.
        quantity: The amount of units of the symbol to trade (positive or negative depending on buy or sell).
        stoploss_price: The price in which the quantity amount of shares will be sold upon being met.
        reason: The optional reason for the trade.
    """
    order = StoplossOrderEvent(
        market_data.timestamp,
        quantity=quantity,
        stop_price=stoploss_price,
        reason=reason
    )
    self._event_bus.publish(order)