trading_agent.tools.order_tool
¶
The shallow base class of the tools that place, change, cancel and close orders.
Every order tool asks the risk engine before it sends anything that adds risk, tags each order with the desk's name, records the order in the desk order book, and publishes what it did on the event bus, where the journal keeps it with the model's stated reason. In dry_run mode every request goes to UBI as a dry run, which UBI checks and answers without sending anything to a broker.
Typical usage example:
class PlaceOrderTool(OrderTool): async def _act(self, arguments): ...
OrderServices
dataclass
¶
What the order tools use, shared by every desk.
Attributes:
| Name | Type | Description |
|---|---|---|
reader |
BrokerReader
|
The shared reader of UBI, whose lock every UBI call goes through. |
risk_engine |
RiskEngine
|
The engine every order that adds risk must pass. |
order_book |
DeskOrderBook
|
The record of which desk placed which order. |
snapshot_reader |
AccountSnapshotReader
|
Reads the account's positions, for closing a desk's positions. |
ledger |
RiskLedger
|
The risk ledger, for the instruments a desk owns. |
event_bus |
EventBus
|
Where every order action is published. |
formatter |
ResultFormatter
|
Turns UBI's answers into text. |
OrderTool
¶
Bases: Tool
A tool that sends orders, or changes or cancels them, for one desk.
Creates the tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
services
|
OrderServices
|
What the tool uses. |
required |
desk
|
str
|
The desk the tool works for. |
required |
mode
|
str
|
"dry_run" to send everything to UBI as a dry run, "live" to trade. |
required |
Source code in src/trading_agent/tools/order_tool.py
run
async
¶
Does the tool's work, and explains any failure in words the model can act on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
BaseModel
|
The checked arguments. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
What happened, or why it could not happen. |