tribulnation-terminal
Read your Terminal portfolio, positions and (with Ultra)
live and historical crypto market data from Python or the command line, for you and your
agents. Read-only, always: one API key with me:read (and optionally market:read),
which can place no order, change nothing and see no exchange key.
from tribulnation.terminal import Terminal: a typed, async client.tn terminal: the command line, a thin layer on that client and a plugin of thetnlauncher (tribulnation-cli). It also runs alone astn-terminal.
API docs: api.tribulnation.com/docs · for agents: llms.txt · keys: app.tribulnation.com/integrations.
Install
pip install tribulnation-terminal # the Python client
uv tool install tribulnation-cli --with tribulnation-terminal # tn terminal
pip install 'tribulnation-terminal[cli]' # both, in one environment
Quickstart
1. A key. Either sign in from the command line (it prints a code to approve in your browser and saves the key, mode 600):
tn terminal auth login # me:read: your own data
tn terminal auth login --scopes me:read,market:read # with market data (Ultra)
or make one on /integrations and export it as
TN_API_KEY.
2. Your portfolio, an order book snapshot and a live stream:
import asyncio
from tribulnation.terminal import Terminal
async def main():
async with Terminal.new() as terminal: # TN_API_KEY, or the saved login
overview = await terminal.me.portfolio.get(hours=24 * 7)
print(overview['summary']['pnl'])
# market data: a key with market:read, on Ultra
book = await terminal.live.book('bitcoin', depth=10) # fresh, never older than 30 s
for venue in book['books'][:3]:
print(venue['exchange'], venue['bid'], venue['ask'])
# the live socket, reconnecting by itself
async for frame in terminal.live.stream('book:bitcoin', depth=5):
if frame['t'] == 'view':
print([(b['exchange'], b['bid'], b['ask']) for b in frame['books'][:3]])
break
asyncio.run(main())
3. The same from a shell:
tn terminal portfolio --window 7d
tn terminal positions --json | jq .
tn terminal funding bitcoin --venue binance,hyperliquid --since 3d
tn terminal watch book:bitcoin --depth 10 # a refreshing top of book per venue
Python
async with Terminal.new() as terminal:
me = await terminal.me.get() # the key and your plan
overview = await terminal.me.portfolio.get(hours=24 * 7)
print(overview['summary']['pnl'], overview['start']) # a float, a UTC datetime
for row in overview['assets']:
print(row['symbol'], row['pos']) # size per exchange
funding = await terminal.v1.market.perps.funding.latest(
assets=['bitcoin', 'ethereum']
)
prices = await terminal.v1.prices.latest(assets='bitcoin') # price: Decimal
The key. Terminal.new(api_key=None, *, base_url=None, validate=True, saved=True, http=None) takes the key from api_key, else TN_API_KEY, else the key
tn terminal auth login saved. The host is base_url, else TN_API_BASE, else (for a
key from TN_API_KEY or the saved login, never for api_key) the saved key's host, else
https://api.tribulnation.com. A saved key is only sent to
the host that issued it (KeyHostError otherwise). Keys are made on /integrations.
The surface mirrors the API's paths:
terminal.me |
.get(), .accounts(), .profiles(), .position(asset), .portfolio.get(hours=, start=, end=, profile=), .portfolio.asset(asset, ...), .charts.list(), .charts.get(id) |
terminal.v1 |
.assets.list(...), .assets.get(id), .prices.latest(...), .prices.historical(...), .candles(...), .market.tickers.latest(...), .market.perps.stats.latest(...), .market.perps.funding.latest(...) / .historical(...), .earn.latest(...), .earn.facets(), .platforms.list() / .get(id), .networks.list() / .get(id), .search(text) |
terminal.v2 |
.series.list(), .get(id), .data(id, start=, end=, **filters), .latest(id, **filters), .instances(id, ...); .snapshots.list(), .get(id), .data(id, **filters) |
terminal.live |
.profile(asset, ...); .book(asset, depth=) and .asset(asset): fresh snapshots (never older than 30 s; warming retried for up to wait=10 s); .stream(topic, depth=): the live socket wss://<host>/live/<topic> as an async iterator of ViewFrame / ControlFrame (tribulnation.terminal.livestream), reconnecting at once on the server's once-a-minute close (4001), pinging every 20 s, backing off on other closes and raising LiveClosed on 4401 (key revoked), 4003, 4004 |
terminal.get(path, **params) |
any /me, /v1/ or /v2/ read, as raw JSON |
Answers are TypedDicts (tribulnation.terminal.me.models,
.me.portfolio_models, .v1.models), validated with pydantic: epoch-millisecond and
ISO times become UTC datetimes (series arrays stay epoch ms), dates dates, decimal
text Decimal. Fields the API adds later are kept. validate=False (per client or per
call) returns the JSON as the server sent it.
Errors subclass the typed_core ones: AuthError (401), Forbidden (403: the scope
or the plan), NotFound, BadRequest, RateLimited (retry_after), Unavailable
(502-504), all ApiError with status, code and message (keys cut out);
NetworkError (no answer), Redirected (never followed: the key would go along),
ValidationError (an unexpected shape), NotLoggedIn, KeyHostError. A portfolio served
from the stored last answer (the live sync failed or was slow) raises a
LastAnswerWarning warning.
Command line: sign in
tn terminal auth login # me:read, this machine's name
tn terminal auth login --name laptop --scopes me:read,market:read
tn terminal auth login --api https://<another API host> # e.g. a staging deployment
It prints a code like BCDF-GHJK and a link to /integrations/device (and opens a
browser where there is one). Sign in there, check the code matches, choose the scopes and
the key's expiry (1 year by default) and approve. The command then saves the key and
says so. --no-browser only prints the link (on a server, open it on your laptop).
Logging in again replaces the saved key and revokes the old one.
The key is listed on /integrations as Command line under the device's name, and can be
revoked there at any time. market:read is offered only on Ultra; the API checks the plan
again on every market read.
tn terminal auth status # the key in use: name, tn_key_ prefix, scopes, source, expiry, plan
tn terminal auth logout # revoke it on the server, then delete it here
How the device login works (RFC 8628, /oauth/* on the API host):
api.tribulnation.com/docs.
Commands
Every command takes --json (the server's JSON, unchanged: for agents and jq) and
--api URL. Without --json the answer is a table.
| Command | Reads |
|---|---|
me |
GET /me: the key and your plan |
accounts |
GET /me/accounts: connected accounts and venues |
profiles |
GET /me/profiles |
portfolio [--window 24h|7d|30d|90d|1y] [--profile ID] [--asset A] |
GET /me/portfolio (hours=), one asset GET /me/portfolio/asset |
positions [ASSET] [--profile ID] |
positions per asset and exchange from /me/portfolio; one asset GET /me/position |
charts [ID] |
GET /me/charts, /me/charts/{id} |
funding ASSET [--venue V] [--since T] [--until T] [--interval hour|day] [--latest] |
GET /v1/market/perps/funding/historical (/latest) |
prices ASSET [--since DATE] [--until DATE] [--currency usd|eur] |
GET /v1/prices/latest, with --since /v1/prices/historical |
candles ASSET [--interval 1h|4h|day] [--since DATE] [--until DATE] |
GET /v1/candles |
assets [--search Q] [--limit N], search QUERY |
GET /v1/assets, /v1/search |
series [ID] [NAME=VALUE ...], snapshots [ID] [NAME=VALUE ...] |
GET /v2/series[/{id}/data], /v2/snapshots[/{id}/data] |
get PATH [NAME=VALUE ...] |
any /me, /v1/ or /v2/ path |
watch TOPIC [--depth N] [--count N] |
the live socket wss://<host>/live/<topic>: a refreshing top of book per venue for book:<asset> (bid, sizes, ask, spread), a summary for other topics; --json prints one frame per line; reconnects by itself until Ctrl-C |
Times: --since 7d, --since 24h, --since 2026-10-01 or an instant with a zone
(2026-10-01T00:00:00Z). Asset and venue ids are catalogue ids (bitcoin,
hyperliquid); funding and prices take comma lists. Market commands need
market:read and Ultra: otherwise a 403 that says so.
tn terminal portfolio --window 7d
tn terminal positions bitcoin --json | jq .position
tn terminal funding bitcoin --venue binance,hyperliquid --since 3d --interval day
tn terminal get /v1/market/perps/stats/latest assets=bitcoin
tn terminal watch book:bitcoin --depth 10
Exit codes
| Code | Meaning |
|---|---|
| 0 | ok |
| 1 | another API error |
| 2 | usage (a bad option, a non-https --api, or an --api/TN_API_BASE other than the saved key's host) |
| 3 | not logged in, or the key is invalid, expired or revoked (401) |
| 4 | forbidden: the scope or the plan (403) |
| 5 | rate limited (429; the message gives Retry-After) |
| 6 | network: unreachable, a redirect refused, or the service unavailable |
| 7 | login denied or expired |
Errors go to stderr as error: <code>: <message>, with anything shaped like a key cut out.
Config and safety
- The key lives in
~/.config/tn/terminal.json($XDG_CONFIG_HOME/tn/terminal.json): the folder mode 700, the file mode 600, written atomically. It holdsapi,key,key_id,label,scopes,saved_at. The CLI refuses a file other users can read, as ssh does. TN_API_KEYandTN_API_BASEoverride the file;TN_OUTPUT=jsonis--json. There is no--keyoption, so a key never appears on a command line or in shell history.- The saved key goes only to the host that issued it. An
--apiorTN_API_BASEnaming another host is refused (exit 2) rather than sending it there;auth logoutrevokes at the issuing host only. A key fromTN_API_KEYgoes to the host given. Any host other thanhttps://api.tribulnation.com(a staging host too) is named in awarning:line on stderr, at login and on every read. - The file must be a regular file owned by you; a crash prints a plain traceback (never local variables); server text in tables and errors has control characters removed; the browser is only opened on an https approval link.
- The key is never printed:
auth statusshows itstn_key_prefix (8 characters). - https only (plain http only to localhost), TLS verified, no redirects followed (the key would go along).
Develop
cd python
uv sync
uv run pytest -q
uv run ruff check --config ../.agents/tools/python/ruff.toml . && uv run ruff format --config ../.agents/tools/python/ruff.toml --check .
The tests mock the API (httpx.MockTransport): the client's key and host resolution,
the request every endpoint sends, the models against answers recorded on the prototype
(tests/fixtures/) and against the contracts' field names, errors; and the command line's
login loop (pending, slow_down, success), logout, key-file modes, environment overrides,
output, errors and exit codes, and tn's discovery of the terminal command.
Modules (src/tribulnation/terminal/): main.py (Terminal), me/, v1/, v2/ (the
endpoint groups and their models), core/ (base.py the client root, auth.py which key
to which host, transport.py HTTP, exc.py errors, config.py the key file, device.py
the device login and logout, endpoint.py, types.py), cli/ (commands.py the auth
commands, base.py the Typer apps, the client call and exit codes, mine.py your data,
market.py market data, render.py tables).
Metadata
Release files for tribulnation-terminal 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tribulnation_terminal-0.3.1.tar.gz | 75.0 kB | With provenance | Details for tribulnation_terminal-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tribulnation_terminal-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for tribulnation_terminal-0.3.1-py3-none-any.whl |
Total release size: 140.2 kB
Release files / tribulnation_terminal-0.3.1.tar.gz
| Download URL | tribulnation_terminal-0.3.1.tar.gz |
|---|---|
| Size | 75.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa436af8ab737b9c8d177d71d4110fbbfe98609c5cf232123c5814c09e830f7e
|
|
BLAKE2b-256 checksum How to use checksums |
f6882287c43951e6d3885f5c7d85ac9b8681e7cd7132ef0c82ca4cc096f76903
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / tribulnation_terminal-0.3.1-py3-none-any.whl
| Download URL | tribulnation_terminal-0.3.1-py3-none-any.whl |
|---|---|
| Size | 65.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ed5d6186e63d137232d3e4573e34ef7a97c26342271fb358d5d3c2d29f6e5a2
|
|
BLAKE2b-256 checksum How to use checksums |
29ce7df08fd737595c00b7fd57bf293332309c16b8cdb61cd9e8896addc529fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for tribulnation-terminal 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tribulnation_terminal-0.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.