Skip to content

trading_agent.tools.search_instruments_tool

The search_instruments tool: finds securities whose trading symbol contains some text.

Typical usage example:

tool = SearchInstrumentsTool(reader, formatter)

SearchInstrumentsArguments

Bases: BaseModel

The arguments of search_instruments.

Attributes:

Name Type Description
exchange str

The lower-case exchange, such as nse, bse or mcx.

segment str

The segment, such as equities or equity_indices.

text str

Text the trading symbol must contain, such as INFY or RELI; company names do not match.

limit int

The most results to return.

SearchInstrumentsTool

SearchInstrumentsTool(reader, formatter)

Bases: BrokerTool

Searches UBI's instrument list by trading symbol.

Source code in src/trading_agent/tools/broker_tool.py
def __init__(
    self,
    reader: broker_reader_module.BrokerReader,
    formatter: result_formatter_module.ResultFormatter,
):
    """Creates the tool.

    Args:
        reader (broker_reader_module.BrokerReader): The shared reader of UBI.
        formatter (result_formatter_module.ResultFormatter): Turns tradingmachine's answers into text.
    """
    self._reader = reader
    self._formatter = formatter

run async

run(arguments)

Runs the search.

Parameters:

Name Type Description Default
arguments SearchInstrumentsArguments

Where and what to search.

required

Returns:

Type Description
ToolResult

The matching instruments, best match first, or an error.

Source code in src/trading_agent/tools/search_instruments_tool.py
async def run(
    self, arguments: SearchInstrumentsArguments
) -> tool.ToolResult:
    """Runs the search.

    Args:
        arguments (SearchInstrumentsArguments): Where and what to search.

    Returns:
        tool.ToolResult: The matching instruments, best match first, or an error.
    """
    return await self._answer(functools.partial(self._read, arguments))