Skip to content

trading_agent.tools.get_candles_tool

The get_candles tool: price candles of one instrument over a range.

Typical usage example:

tool = GetCandlesTool(reader, formatter)

GetCandlesArguments

Bases: InstrumentArguments

The arguments of get_candles: the instrument's fields plus the range.

Attributes:

Name Type Description
interval str

The candle length, such as day, 60minute, 15minute, 5minute or minute.

days int | None

How many days to count back from today; used when from_date is not given.

from_date str | None

The first day, as YYYY-MM-DD.

to_date str | None

The last day, as YYYY-MM-DD; needed with from_date.

rows int

How many of the most recent candles to return.

GetCandlesTool

GetCandlesTool(reader, formatter)

Bases: BrokerTool

Reads one instrument's candles.

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)

Reads the candles.

Parameters:

Name Type Description Default
arguments GetCandlesArguments

The instrument and range.

required

Returns:

Type Description
ToolResult

The candles as CSV, or an error.

Source code in src/trading_agent/tools/get_candles_tool.py
async def run(self, arguments: GetCandlesArguments) -> tool.ToolResult:
    """Reads the candles.

    Args:
        arguments (GetCandlesArguments): The instrument and range.

    Returns:
        tool.ToolResult: The candles as CSV, or an error.
    """
    return await self._answer(
        functools.partial(self._read, arguments),
        rows=arguments.rows,
    )