Skip to content

trading_agent.tools.cancel_order_tool

The cancel_order tool: cancels one of the desk's own orders, or one part of a bracket.

Cancelling takes risk away, so the risk engine is not asked; the desk order book only confirms that the desk placed the order. An order that has a parent_id is cancelled through UBI's order engine, which stops the whole order and every leg it has resting at a broker, so a bracket's exits go with it. A position the order already opened stays open.

Typical usage example:

tool = CancelOrderTool(services, 'main', 'dry_run')

CancelOrderArguments

Bases: BaseModel

Which order to cancel.

Attributes:

Name Type Description
parent_id str | None

The parent_id that place_order or place_bracket_order answered with, or None.

order_id str | None

The broker's order_id, or None.

part str | None

With parent_id, the path of one part of a bracket to cancel alone, such as root.each_fill.children.1 for its target; or None for the whole order.

reason str

Why the desk is cancelling, kept in the journal.

CancelOrderTool

CancelOrderTool(services, desk, mode)

Bases: OrderTool

Cancels one of the desk's own orders.

Source code in src/trading_agent/tools/order_tool.py
def __init__(self, services: OrderServices, desk: str, mode: str):
    """Creates the tool.

    Args:
        services (OrderServices): What the tool uses.
        desk (str): The desk the tool works for.
        mode (str): "dry_run" to send everything to UBI as a dry run, "live" to trade.
    """
    self._services = services
    self._desk = desk
    self._dry_run = mode != 'live'
    tag_characters = []
    for character in desk:
        if character.isalnum():
            tag_characters.append(character)
    self._tag = ''.join(tag_characters)[:_TAG_LENGTH]