File size: 7,736 Bytes
9fe4fad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e13ca4
 
9fe4fad
23c102d
9fe4fad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23c102d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9fe4fad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a746412
 
 
 
 
 
 
 
 
23c102d
 
a746412
 
 
 
 
 
9fe4fad
23c102d
 
 
9fe4fad
23c102d
a746412
 
 
 
 
 
 
 
 
 
23c102d
 
 
 
a746412
 
 
9fe4fad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23c102d
9fe4fad
23c102d
9fe4fad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
title: API Reference
summary: Route map for TerraFin's page APIs, chart APIs, and hosted assistant APIs.
---

# API Reference

TerraFin serves one FastAPI application with several route families. This page
is the quick route map; the deeper behavior and state model live in
[Interface Overview](interface.md).

OpenAPI is available at `/openapi.json`.

## Root And Operational Routes

| Method | Path | Purpose |
|--------|------|---------|
| `GET` | `/` | Redirect to the dashboard page |
| `GET` | `/health` | Multi-component status page (HTML, 30 s in-process cache, `?refresh=1` to force) |
| `GET` | `/health.json` | Same data as JSON |
| `GET` | `/ready` | Readiness endpoint |
| `GET` | `/resolve-ticker?q=...` | Resolve a query string to a ticker symbol and company name (no `/stock/api/` prefix) |

## Chart

Prefix: `/chart/api/*`

Key routes:

- `GET /chart/api/chart-data`
- `POST /chart/api/chart-data`
- `POST /chart/api/chart-view`
- `GET /chart/api/chart-selection`
- `POST /chart/api/chart-selection`
- `POST /chart/api/chart-series/add`
- `POST /chart/api/chart-series/set`
- `POST /chart/api/chart-series/progressive/set`
- `POST /chart/api/chart-series/progressive/backfill`
- `POST /chart/api/chart-series/remove`
- `GET /chart/api/chart-series/names`
- `GET /chart/api/chart-series/search`

## Dashboard

Prefix: `/dashboard/api/*`

Representative routes include breadth, valuation, and cache-backed widget
payloads. See [Interface Overview](interface.md) for the current widget
contract and private-access fallback behavior. Watchlist routes are listed in
the [Watchlist](#watchlist) section below.

- SPX GEX snapshot: `GET /dashboard/api/gex/spx`
- SPX GEX history: `GET /dashboard/api/gex/spx/history`

## Watchlist

Prefix: `/dashboard/api/watchlist*`

| Method | Path | Body | Description |
|--------|------|------|-------------|
| `GET` | `/dashboard/api/watchlist` | β€” | Full snapshot |
| `POST` | `/dashboard/api/watchlist` | `{symbol, tags?}` | Add symbol |
| `DELETE` | `/dashboard/api/watchlist/{symbol}` | β€” | Remove symbol (optional `?group=` to scope) |
| `PATCH` | `/dashboard/api/watchlist/{symbol}/tags` | `{tags, mode}` | Set/add/remove tags (`mode`: `set`\|`add`\|`remove`, default `set`) |
| `GET` | `/dashboard/api/watchlist/groups` | β€” | List groups with counts |
| `POST` | `/dashboard/api/watchlist/groups` | `{name}` | Create group |
| `DELETE` | `/dashboard/api/watchlist/groups/{tag}` | β€” | Delete group |
| `POST` | `/dashboard/api/watchlist/groups/rename` | `{old, new}` | Rename group |
| `PUT` | `/dashboard/api/watchlist/groups/order` | `{groups: [name, ...]}` | Persist group order |
| `PUT` | `/dashboard/api/watchlist/groups/{group}/item-order` | `{symbols: [ticker, ...]}` | Persist item order within group |
| `PUT` | `/dashboard/api/watchlist` | `{symbols: [{symbol, tags}]}` | Bulk update all symbols and tags |

## Market Insights

Prefix: `/market-insights/api/*`

Representative routes include:

- guru portfolio views
- top-company payloads
- S&P 500 DCF payloads
- market-regime and macro widgets

## Stock Analysis

Prefix: `/stock/api/*`

Representative routes include:

- `GET /stock/api/overview?ticker=...`
- `GET /stock/api/dcf?ticker=...&projectionYears=5|10|15`
- `POST /stock/api/dcf?ticker=...` β€” accepts a `StockDCFRequest` body to override
  derived inputs. Beyond the existing `baseCashFlowPerShare`, `baseGrowthPct`,
  `terminalGrowthPct`, `beta`, `equityRiskPremiumPct`, `currentPrice` fields, the
  body now supports:
  - `projectionYears` (5 | 10 | 15) β€” explicit DCF horizon. Treasury rate curve
    is sized to match.
  - `fcfBaseSource` (`auto` | `3yr_avg` | `ttm` | `latest_annual`) β€” picks the
    base FCF/share. `auto` cascades 3yr_avg β†’ annual β†’ ttm. Default is `auto`.
    Note: `autoSelectedSource` in the `/fcf-history` response uses different
    string values (`quarterly_ttm`, `annual`) β€” do not pass it back here directly.
  - `breakevenYear`, `breakevenCashFlowPerShare`, `postBreakevenGrowthPct` β€”
    when all three are supplied, the model switches to **turnaround mode**: the
    base FCF/share input becomes the *current* (possibly negative) FCF; the
    schedule linearly interpolates from current FCF to the breakeven value
    across `breakevenYear` years, then compounds at the post-breakeven rate
    fading toward terminal growth.
- `GET /stock/api/reverse-dcf?ticker=...`
- `POST /stock/api/reverse-dcf?ticker=...` β€” optional body overrides: `baseCashFlowPerShare`,
  `terminalGrowthPct`, `beta`, `equityRiskPremiumPct`, `currentPrice`, `projectionYears` (1–20, default 5),
  `growthProfile` (`high_growth` | `early_maturity` | `fully_mature`, default `early_maturity`)
- `GET /stock/api/beta-estimate?ticker=...`
- `GET /stock/api/gex?ticker=` β€” GEX snapshot (regime, spot, zero-gamma, call/put walls, by-strike and by-expiration buckets)
- `GET /stock/api/fcf-history?ticker=...&years=10` β€” returns annual FCF/share
  history plus the base candidates the DCF would use:
  - `history`: chronological list of `{year, fcf, fcfPerShare}` (NaN years
    dropped, oldest→newest).
  - `ttmFcfPerShare`, `ttmSource` β€” most recent trailing-12-month value from
    quarterly cashflow when β‰₯4 quarters available, else latest annual.
  - `candidates`: `{threeYearAvg, latestAnnual, ttm}` per-share values, each
    nullable when the underlying data is absent.
  - `autoSelectedSource` β€” which candidate the backend's `auto` cascade would
    pick under the current data (one of `3yr_avg`, `annual`, `quarterly_ttm`,
    `missing`). Note: these response values differ from the `fcfBaseSource`
    input values β€” `ttm` input β†’ `quarterly_ttm` response, `latest_annual`
    input β†’ `annual` response. Do not pass `autoSelectedSource` back as
    `fcfBaseSource` directly.
  - `sharesOutstanding`, `sharesNote` β€” caveat that per-year FCF/share is
    computed using *current* sharesOutstanding (no per-year dilution
    adjustment).

## Calendar

Prefix: `/calendar/api/*`

Representative routes include macro and earnings event payloads plus
session-scoped calendar selection state.

## Agent Data APIs

Prefix: `/agent/api/*`

Current external-agent routes:

- `GET /agent/api/resolve`
- `GET /agent/api/market-data`
- `GET /agent/api/indicators`
- `GET /agent/api/market-snapshot`
- `GET /agent/api/company`
- `GET /agent/api/earnings`
- `GET /agent/api/financials`
- `GET /agent/api/portfolio`
- `GET /agent/api/economic`
- `GET /agent/api/macro-focus`
- `GET /agent/api/lppl`
- `GET /agent/api/calendar`

## Hosted Agent Runtime

Prefix: `/agent/api/runtime/*`

Core routes:

- `GET /agent/api/runtime/agents`
- `POST /agent/api/runtime/sessions`
- `GET /agent/api/runtime/sessions` β€” list all sessions
- `GET /agent/api/runtime/sessions/{session_id}`
- `DELETE /agent/api/runtime/sessions/{session_id}` β€” archive session
- `POST /agent/api/runtime/sessions/{session_id}/messages`
- `GET /agent/api/runtime/sessions/{session_id}/tasks`
- `GET /agent/api/runtime/sessions/{session_id}/approvals`
- `GET /agent/api/runtime/tasks/{task_id}`
- `POST /agent/api/runtime/tasks/{task_id}/cancel`
- `GET /agent/api/runtime/approvals/{approval_id}`
- `POST /agent/api/runtime/approvals/{approval_id}/approve`
- `POST /agent/api/runtime/approvals/{approval_id}/deny`

## Session Model

The important rule for route consumers is that stateful APIs are session-scoped.

- chart and calendar state default to the `"default"` session unless overridden
- browser flows usually use a per-tab session id
- hosted assistant sessions are persisted separately from chart sessions

For the implementation details, read [Interface Overview](interface.md) and
[Hosted Runtime](agent/hosted-runtime.md).