Skip to content

trading_agent.tools.place_bracket_order_tool

The place_bracket_order tool: an entry order that sets up its own stop-loss and target when it fills.

UBI's order engine works the exits, so they act in real time even while the desk's model is busy or asleep: on the entry's first fill it places a stop-limit and a target sized to what filled, and when either exit fills it cancels the other. The risk engine checks the entry, because only the entry adds risk.

Typical usage example:

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

BracketOrderArguments

Bases: OrderArguments

An entry order with its stop-loss and target.

Attributes:

Name Type Description
order_type Literal['market', 'limit']

The entry's type, "market" or "limit".

stop_price float | None

The stop-loss trigger in rupees, or None for no stop.

stop_limit_price float | None

The stop-loss's limit in rupees, needed with stop_price, because every stop is a stop-limit; for a long position it is at or below stop_price.

target_price float | None

The target's limit in rupees, or None for no target.

PlaceBracketOrderTool

PlaceBracketOrderTool(services, desk, mode)

Bases: OrderTool

Places one bracket order.

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]