Skip to main content

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 the tn launcher (tribulnation-cli), which the cli extra installs and puts on the PATH as tn. It also runs alone as tn-terminal.

API docs: api.tribulnation.com/docs · for agents: llms.txt · keys: app.tribulnation.com/integrations.

Install

pip install tribulnation-terminal                  # the Python client
pip install 'tribulnation-terminal[cli]'           # the client and the tn command line
uv tool install 'tribulnation-terminal[cli]'       # tn alone, in its own environment (or pipx install)

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 datetime import date
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(start=date(2026, 11, 10))
    print(overview['data']['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['data']['books'][:3]:
      print(venue['segment_id'], venue['bid'], venue['ask'])

    # the live socket, reconnecting by itself
    async for frame in terminal.live.stream('book:bitcoin', depth=5):
      if frame['type'] == 'view':  # the HTTP API's names; amounts are decimal strings
        print(frame['ts_ms'], [(b['segment_id'], 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(start=date(2026, 11, 10))
  print(overview['data']['summary']['pnl'], overview['meta']['range'])  # every answer is {data, meta}
  for row in overview['data']['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(start=, end=, profile=), .portfolio.asset(asset, ...), .portfolio.activity(kind, ...), .charts.list(), .charts.get(id)
terminal.v1 .assets.list(...), .assets.get(id), .assets.summary(id), .assets.instruments(id), .prices.latest(...), .prices.historical(...), .candles(...), .market.tickers.latest(...), .market.perps.stats.latest(...), .market.perps.funding.latest(...) / .historical(...), .earn.latest(...), .earn.historical(...), .earn.facets(), .venues.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/, /v2/ or /live/ read, as raw JSON

Answers are TypedDicts, validated with pydantic: /v1 answers are typed (tribulnation.terminal.v1.models), ISO times become UTC datetimes, dates dates. Numbers go by meaning: anything denominated in a currency or an asset (prices, amounts, sizes, notionals, balances, market caps, volumes, open interest) is a decimal string on the wire ("64250.5") and a Decimal in the typed models; rates, fractions, APRs, counts and durations (_s) are numbers. /me, /v2 records and /live answer {data, meta} with data as the JSON the server sent (amounts stay decimal strings: Decimal(row['net_usd']) reads one exactly). Fields the API adds later are kept. validate=False (per client or per call) returns the JSON as the server sent it.

Live socket frames (livestream.ViewFrame, ControlFrame) carry the HTTP API's field names: {"type": "view", "seq", "v": 2, "ts_ms", ...}, where ... is the view /live/asset/{asset} answers as data (segment_id, quote_asset_id, mark_price, bid_qty, received_at, book levels [price, size] as decimal strings). ts_ms (epoch milliseconds) is the one epoch number; every other instant is ISO-8601. livestream.top_of_book(frame) gives the top per book as Decimals.

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 (from=), 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/, /v2/ or /live/ 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 holds api, key, key_id, label, scopes, saved_at. The CLI refuses a file other users can read, as ssh does.
  • TN_API_KEY and TN_API_BASE override the file; TN_OUTPUT=json is --json. There is no --key option, 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 --api or TN_API_BASE naming another host is refused (exit 2) rather than sending it there; auth logout revokes at the issuing host only. A key from TN_API_KEY goes to the host given. Any host other than https://api.tribulnation.com (a staging host too) is named in a warning: 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 status shows its tn_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.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tribulnation-terminal 0.5.0
File Size Uploaded Provenance Actions
tribulnation_terminal-0.5.0.tar.gz 87.1 kB With provenance Details for tribulnation_terminal-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tribulnation-terminal 0.5.0
File Interpreter ABI Platform Actions
tribulnation_terminal-0.5.0-py3-none-any.whl Python 3 none any Details for tribulnation_terminal-0.5.0-py3-none-any.whl

Total release size: 158.4 kB

Release files / tribulnation_terminal-0.5.0.tar.gz

Download URL tribulnation_terminal-0.5.0.tar.gz
Size 87.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ff9c396e9644b3202b100af3088e299d86a675971ec6482a68d84c10907bc43e
BLAKE2b-256 checksum
How to use checksums
db27c9405121626df0ccd74d7d4e393265b0a2888808be551dec2db7d45f8ba7
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 22, 2026.

Transparency log

Release files / tribulnation_terminal-0.5.0-py3-none-any.whl

Download URL tribulnation_terminal-0.5.0-py3-none-any.whl
Size 71.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4feddaac4243fada6d5017ce64dce43db239e916b0961d573607edc1e2209dcf
BLAKE2b-256 checksum
How to use checksums
64aab42ab38ebe5c0366cf4880f2f8883eb91f44187221fba5a5ea3eeaca6e29
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 22, 2026.

Transparency log

Security for tribulnation-terminal 0.5.0

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.

Select from 2 files

Attestation for tribulnation_terminal-0.5.0.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 22, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page