Skip to content

trading_agent.tools.flatten_desk_tool

The flatten_desk tool: cancels every open order of the desk and closes every position the desk owns.

It touches only what the desk itself placed or owns, never another desk's trades or the user's own holdings; flattening the whole account is left to the kill switch and to the user. Each closing order passes the risk engine, which always lets a desk reduce its own position but still checks that the exchange is open.

Typical usage example:

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

FlattenDeskArguments

Bases: BaseModel

Why the desk is flattening.

Attributes:

Name Type Description
reason str

Why, kept in the journal.

FlattenDeskTool

FlattenDeskTool(services, desk, mode)

Bases: OrderTool

Cancels the desk's orders and closes the desk's positions.

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]