trading_agent.gateway.routes.account_routes
¶
Routes for the account: balances, positions, profit and loss, orders, ownership, halts and the kill switch.
GET /api/account the account now, each desk's profit and loss, ownership and halts GET /api/orders?kind=orders UBI's order book: orders, trades or open_parents GET /api/desk-orders each desk's open orders in the desk order book POST /api/account/kill halt every desk and flatten the account; needs {"confirm": "FLATTEN"}
Typical usage example:
application.include_router(AccountRoutes(guard, shared, desk_names).router())
KillRequest
¶
Bases: BaseModel
The body of a kill-switch request.
Attributes:
| Name | Type | Description |
|---|---|---|
confirm |
str
|
Must be exactly FLATTEN, so the switch cannot fire by accident. |
reason |
str
|
Why, for the ledger and the journal. |
AccountRoutes
¶
Bases: RouteGroup
The account routes.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
AccessGuard
|
Checks the access token. |
required |
shared
|
SharedParts
|
The shared parts. |
required |
desk_names
|
Sequence[str]
|
The desks, for their order lists. |
required |
clock
|
Callable[[], datetime] | None
|
Returns the current time; None uses the system clock. |
None
|
Source code in src/trading_agent/gateway/routes/account_routes.py
account
async
¶
The account now.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Balance, margin, today's and this week's profit and loss, each desk's profit and loss, positions, ownership and halts. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
UBI cannot be read (status 503). |
Source code in src/trading_agent/gateway/routes/account_routes.py
orders
async
¶
UBI's order book, as UBI serves it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
Literal['orders', 'trades', 'open_parents']
|
Which book. |
'orders'
|
Returns:
| Type | Description |
|---|---|
Any
|
UBI's document. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
UBI cannot be read (status 503). |
Source code in src/trading_agent/gateway/routes/account_routes.py
desk_orders
¶
Each desk's open orders in the desk order book, dry runs included.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The orders, keyed by desk name. |
Source code in src/trading_agent/gateway/routes/account_routes.py
kill
async
¶
Halts every desk until tomorrow and flattens the account.
In dry_run mode the flatten is a dry run, exactly as when the loss limit fires it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
KillRequest
|
The confirmation and the reason. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
UBI's answer to the flatten, or a note that the switch had already fired. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The confirmation is not FLATTEN (status 400). |