Skip to content

trading_agent.tools.modify_order_tool

The modify_order tool: changes the quantity, price or trigger price of one of the desk's own open orders.

A desk can change only an order it placed, as the desk order book records. Making an order bigger adds risk, so the extra quantity goes through the risk engine as if it were a new order; a smaller order or a new price does not. A dry-run order reached no broker, so changing it is only recorded.

Typical usage example:

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

ModifyOrderArguments

Bases: BaseModel

Which order to change, and how.

Attributes:

Name Type Description
parent_id str | None

The parent_id that place_order or place_bracket_order answered with, for an order UBI is still holding or for one part of a bracket; or None.

order_id str | None

The broker's order_id, for an order already at a broker; or None.

part str | None

With parent_id, the path of one part of a bracket that has not been sent yet, such as root.each_fill.children.0 for its stop, as get_orders open_parents lists it; or None.

quantity int | None

The new total quantity in units, counting what has filled, or None to keep it.

price float | None

The new limit price in rupees, or None to keep it.

trigger_price float | None

The new trigger price in rupees, or None to keep it.

reason str

Why the desk is changing the order, kept in the journal.

ModifyOrderTool

ModifyOrderTool(services, desk, mode)

Bases: OrderTool

Changes 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]