trading_agent.gateway.gateway_application
¶
Builds the gateway's FastAPI application and runs the desks inside it.
The desks' loops are started when the web server starts and cancelled when it stops, so the gateway is one process that owns every desk.
Typical usage example:
gateway = GatewayApplication(event_bus, desks, guard) uvicorn.run(gateway.build(), host='127.0.0.1', port=8120)
BackgroundWorker
¶
GatewayApplication
¶
GatewayApplication(event_bus, desks, guard, background_workers=(), redactor=None, webhook_token='', route_groups=(), frontend_directory=None, allowed_origins=())
The gateway: its web routes and the desks it runs.
Creates the gateway without starting anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_bus
|
EventBus
|
The bus every component publishes on. |
required |
desks
|
Mapping[str, DeskRuntime]
|
The desks to run, keyed by name. |
required |
guard
|
AccessGuard
|
The guard that checks the access token. |
required |
background_workers
|
Sequence[BackgroundWorker]
|
Other loops to run beside the desks, such as the trade journal. |
()
|
redactor
|
SecretRedactor | None
|
Masks secrets in the live event stream, or None to send events unchanged. |
None
|
webhook_token
|
str
|
The token incoming webhooks must present, or an empty string to switch them off. |
''
|
route_groups
|
Sequence[RouteGroup]
|
The API's route groups; when empty, only the basic desk routes are offered. |
()
|
frontend_directory
|
Path | None
|
The built web page to serve at every other address, or None to serve no page. |
None
|
allowed_origins
|
Sequence[str]
|
The other web origins whose pages may call the API, such as the Android app's "https://localhost"; empty allows none. |
()
|
Source code in src/trading_agent/gateway/gateway_application.py
build
¶
Builds the FastAPI application with every route.
Returns:
| Type | Description |
|---|---|
FastAPI
|
The application, ready for uvicorn. |