Skip to content

trading_agent.gateway.routes.route_group

The shared base of the gateway's API route groups.

Every route of a group needs the access token, so the group builds its router with the guard's check attached, and each subclass only adds its own routes.

Typical usage example:

class AccountRoutes(RouteGroup): def _add_routes(self, router): router.add_api_route('/api/account', self.account, methods=['GET'])

RouteGroup

RouteGroup(guard)

A set of related API routes behind the access token.

Creates the group.

Parameters:

Name Type Description Default
guard AccessGuard

Checks the access token.

required
Source code in src/trading_agent/gateway/routes/route_group.py
def __init__(self, guard: access_guard.AccessGuard):
    """Creates the group.

    Args:
        guard (access_guard.AccessGuard): Checks the access token.
    """
    self._guard = guard

router

router()

Builds the router, every route requiring the token.

Returns:

Type Description
APIRouter

The router.

Source code in src/trading_agent/gateway/routes/route_group.py
def router(self) -> fastapi.APIRouter:
    """Builds the router, every route requiring the token.

    Returns:
        fastapi.APIRouter: The router.
    """
    router = fastapi.APIRouter(
        dependencies=[
            fastapi.Depends(self._guard.require_http_token),
        ],
    )
    self._add_routes(router)
    return router