@tribulnation/terminal 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ // Generated by docs/site/api/ts-types.ts (node docs/site/api/ts-types-cli.ts) from the
2
+ // public OpenAPI document the API host serves: do not edit. docs/site/api/api-reference.test.ts
3
+ // and typescript/test/types.test.ts fail when this file is not what it generates.
4
+ /* eslint-disable */
5
+ /** The HTTP status of each `ApiErrorCode`. */
6
+ export const API_ERROR_STATUS = {
7
+ bad_request: 400,
8
+ unauthorized: 401,
9
+ forbidden: 403,
10
+ not_found: 404,
11
+ gone: 410,
12
+ rate_limited: 429,
13
+ unavailable: 503,
14
+ warming: 503,
15
+ upgrade_required: 426,
16
+ internal: 500
17
+ };
18
+ /** The live socket's close codes: `grant` reconnects at once, the others end the stream. */
19
+ export const LIVE_CLOSE = {
20
+ grant: 4001,
21
+ revoked: 4401,
22
+ notInPlan: 4003,
23
+ unknownTopic: 4004
24
+ };
package/dist/v1.d.ts ADDED
@@ -0,0 +1,154 @@
1
+ /** `/v1`: market data (scope `market:read`, included with Ultra). */
2
+ import type { Answer } from './answer.js';
3
+ import { type Instant, type Transport } from './client.js';
4
+ /** One catalogue id, or several (sent as a comma list). */
5
+ export type Ids = string | readonly string[];
6
+ /** The currency money values are in. */
7
+ export type Currency = 'usd' | 'eur';
8
+ /** A page of a paged list. */
9
+ export type Paging = {
10
+ page?: number;
11
+ limit?: number;
12
+ cursor?: string;
13
+ };
14
+ /** A cursor-paged read: the previous page's `meta.page.next_cursor`, and rows per page. */
15
+ export type Cursor = {
16
+ cursor?: string;
17
+ limit?: number;
18
+ };
19
+ export type AssetsApi = {
20
+ /** The ranking by market cap (`GET /v1/assets`). */
21
+ list(opts?: {
22
+ /** A case-insensitive match on id, symbol and name. */
23
+ search?: string;
24
+ /** Only these categories (`crypto`, `stablecoin`, `stock`, …). */
25
+ categories?: Ids;
26
+ currency?: Currency;
27
+ /** Add up to 30 daily prices to every row. */
28
+ sparkline?: boolean;
29
+ } & Paging): Promise<Answer<'get_assets'>>;
30
+ /** Everything an asset page shows, in one call (`GET /v1/assets/{id}`). */
31
+ get(asset: string, opts?: {
32
+ currency?: Currency;
33
+ }): Promise<Answer<'get_assets_detail'>>;
34
+ /** An asset and its latest price only (`GET /v1/assets/{id}/summary`). */
35
+ summary(asset: string, opts?: {
36
+ currency?: Currency;
37
+ }): Promise<Answer<'get_assets_detail_summary'>>;
38
+ /** An asset's trading pages on each venue (`GET /v1/assets/{id}/instruments`). */
39
+ instruments(asset: string): Promise<Answer<'get_assets_detail_instruments'>>;
40
+ };
41
+ export type PricesApi = {
42
+ /** The current price and market cap (`GET /v1/prices/latest`). */
43
+ latest(opts: {
44
+ assets: Ids;
45
+ currency?: Currency;
46
+ }): Promise<Answer<'get_prices_latest'>>;
47
+ /** The daily price series, each day labelled by its start
48
+ * (`GET /v1/prices/historical`); `start` inclusive, `end` exclusive (default now). */
49
+ historical(opts: {
50
+ assets: Ids;
51
+ start: Instant;
52
+ end?: Instant;
53
+ currency?: Currency;
54
+ } & Cursor): Promise<Answer<'get_prices_historical'>>;
55
+ };
56
+ export type CandlesOptions = {
57
+ /** A catalogue asset id (or several). */
58
+ asset: Ids;
59
+ /** From this day or instant (`from`, inclusive). */
60
+ start: Instant;
61
+ /** To this day or instant (`to`, exclusive; default now). */
62
+ end?: Instant;
63
+ /** `1h`, `4h` or `1d` (default). */
64
+ interval?: '1h' | '4h' | '1d';
65
+ currency?: Currency;
66
+ } & Cursor;
67
+ export type MarketApi = {
68
+ tickers: {
69
+ /** The last trade and best quotes per venue market (`GET /v1/market/tickers/latest`). */
70
+ latest(opts?: {
71
+ assets?: Ids;
72
+ venues?: Ids;
73
+ kinds?: Ids;
74
+ } & Paging): Promise<Answer<'get_market_tickers_latest'>>;
75
+ };
76
+ perps: {
77
+ stats: {
78
+ /** Mark and index price, open interest and funding rate now
79
+ * (`GET /v1/market/perps/stats/latest`). */
80
+ latest(opts?: {
81
+ assets?: Ids;
82
+ venues?: Ids;
83
+ } & Paging): Promise<Answer<'get_market_perps_stats_latest'>>;
84
+ };
85
+ funding: {
86
+ /** The most recent settled rate per market (`GET /v1/market/perps/funding/latest`). */
87
+ latest(opts: {
88
+ assets: Ids;
89
+ venues?: Ids;
90
+ } & Paging): Promise<Answer<'get_market_perps_funding_latest'>>;
91
+ /** The settled funding series per market (`GET /v1/market/perps/funding/historical`);
92
+ * `start` inclusive, `end` exclusive (default now). */
93
+ historical(opts: {
94
+ assets: Ids;
95
+ start: Instant;
96
+ end?: Instant;
97
+ venues?: Ids;
98
+ /** Venue market ids. */
99
+ markets?: Ids;
100
+ /** `1h` (default: each settlement) or `1d` (summed per UTC day). */
101
+ interval?: '1h' | '1d';
102
+ } & Cursor): Promise<Answer<'get_market_perps_funding_historical'>>;
103
+ };
104
+ };
105
+ };
106
+ export type EarnApi = {
107
+ /** Earn instruments with their APR (`GET /v1/earn/latest`). */
108
+ latest(opts?: {
109
+ assets?: Ids;
110
+ venues?: Ids;
111
+ types?: Ids;
112
+ region?: 'eu' | 'us';
113
+ sort?: 'apr' | 'earnings';
114
+ /** The stake, in `currency`, `earnings_30d` is about (default 1000). */
115
+ stake?: number;
116
+ currency?: Currency;
117
+ } & Paging): Promise<Answer<'get_earn_latest'>>;
118
+ /** The venues, assets and tags with an earn product (`GET /v1/earn/facets`). */
119
+ facets(): Promise<Answer<'get_earn_facets'>>;
120
+ /** Daily APR history (`GET /v1/earn/historical`); `start` inclusive, `end` exclusive. */
121
+ historical(opts: {
122
+ assets: Ids;
123
+ start: Instant;
124
+ end?: Instant;
125
+ venues?: Ids;
126
+ } & Cursor): Promise<Answer<'get_earn_historical'>>;
127
+ };
128
+ export type DirectoryApi<L extends 'get_platforms' | 'get_networks', G extends 'get_platforms_detail' | 'get_networks_detail'> = {
129
+ /** Every row, unpaginated (`search` narrows it). */
130
+ list(opts?: {
131
+ search?: string;
132
+ }): Promise<Answer<L>>;
133
+ /** One row by id; `NotFound` for none. */
134
+ get(id: string): Promise<Answer<G>>;
135
+ };
136
+ export type V1Api = {
137
+ /** The asset ranking, and one asset's page. */
138
+ assets: AssetsApi;
139
+ /** Assets, venues and networks by name: their catalogue ids (`GET /v1/search`). */
140
+ search(text: string): Promise<Answer<'get_search'>>;
141
+ /** Asset prices: now and daily history. */
142
+ prices: PricesApi;
143
+ /** An asset's OHLC candles built from venue markets (`GET /v1/candles`). */
144
+ candles(opts: CandlesOptions): Promise<Answer<'get_candles'>>;
145
+ /** Tickers, perpetual stats and funding across venues. */
146
+ market: MarketApi;
147
+ /** Earn products and their APR. */
148
+ earn: EarnApi;
149
+ /** The venue directory: exchanges, chains and DEXs (`/v1/venues`). */
150
+ venues: DirectoryApi<'get_platforms', 'get_platforms_detail'>;
151
+ /** The blockchain directory. */
152
+ networks: DirectoryApi<'get_networks', 'get_networks_detail'>;
153
+ };
154
+ export declare function v1Api(http: Transport): V1Api;
package/dist/v1.js ADDED
@@ -0,0 +1,113 @@
1
+ import { day, instant, segment } from "./client.js";
2
+ const paging = (o) => ({
3
+ page: o.page,
4
+ limit: o.limit,
5
+ cursor: o.cursor
6
+ });
7
+ function directory(http, path) {
8
+ return {
9
+ list: (o = {}) => http.get(path, { search: o.search }),
10
+ get: (id) => http.get(`${path}/${segment(id)}`)
11
+ };
12
+ }
13
+ export function v1Api(http) {
14
+ return {
15
+ assets: {
16
+ list: (o = {}) => http.get('/v1/assets', {
17
+ search: o.search,
18
+ categories: o.categories,
19
+ currency: o.currency,
20
+ sparkline: o.sparkline ? '1' : undefined,
21
+ ...paging(o)
22
+ }),
23
+ get: (asset, o = {}) => http.get(`/v1/assets/${segment(asset)}`, { currency: o.currency }),
24
+ summary: (asset, o = {}) => http.get(`/v1/assets/${segment(asset)}/summary`, {
25
+ currency: o.currency
26
+ }),
27
+ instruments: (asset) => http.get(`/v1/assets/${segment(asset)}/instruments`)
28
+ },
29
+ search: (text) => http.get('/v1/search', { search: text }),
30
+ prices: {
31
+ latest: (o) => http.get('/v1/prices/latest', {
32
+ assets: o.assets,
33
+ currency: o.currency
34
+ }),
35
+ historical: (o) => http.get('/v1/prices/historical', {
36
+ assets: o.assets,
37
+ from: day(o.start),
38
+ to: day(o.end),
39
+ currency: o.currency,
40
+ cursor: o.cursor,
41
+ limit: o.limit
42
+ })
43
+ },
44
+ candles: (o) => http.get('/v1/candles', {
45
+ asset: o.asset,
46
+ interval: o.interval,
47
+ from: day(o.start),
48
+ to: day(o.end),
49
+ currency: o.currency,
50
+ cursor: o.cursor,
51
+ limit: o.limit
52
+ }),
53
+ market: {
54
+ tickers: {
55
+ latest: (o = {}) => http.get('/v1/market/tickers/latest', {
56
+ assets: o.assets,
57
+ venues: o.venues,
58
+ kinds: o.kinds,
59
+ ...paging(o)
60
+ })
61
+ },
62
+ perps: {
63
+ stats: {
64
+ latest: (o = {}) => http.get('/v1/market/perps/stats/latest', {
65
+ assets: o.assets,
66
+ venues: o.venues,
67
+ ...paging(o)
68
+ })
69
+ },
70
+ funding: {
71
+ latest: (o) => http.get('/v1/market/perps/funding/latest', {
72
+ assets: o.assets,
73
+ venues: o.venues,
74
+ ...paging(o)
75
+ }),
76
+ historical: (o) => http.get('/v1/market/perps/funding/historical', {
77
+ assets: o.assets,
78
+ venues: o.venues,
79
+ markets: o.markets,
80
+ from: instant(o.start),
81
+ to: instant(o.end),
82
+ interval: o.interval,
83
+ cursor: o.cursor,
84
+ limit: o.limit
85
+ })
86
+ }
87
+ }
88
+ },
89
+ earn: {
90
+ latest: (o = {}) => http.get('/v1/earn/latest', {
91
+ assets: o.assets,
92
+ venues: o.venues,
93
+ types: o.types,
94
+ region: o.region,
95
+ sort: o.sort,
96
+ stake: o.stake,
97
+ currency: o.currency,
98
+ ...paging(o)
99
+ }),
100
+ facets: () => http.get('/v1/earn/facets'),
101
+ historical: (o) => http.get('/v1/earn/historical', {
102
+ assets: o.assets,
103
+ from: day(o.start),
104
+ to: day(o.end),
105
+ venues: o.venues,
106
+ cursor: o.cursor,
107
+ limit: o.limit
108
+ })
109
+ },
110
+ venues: directory(http, '/v1/venues'),
111
+ networks: directory(http, '/v1/networks')
112
+ };
113
+ }
package/dist/v2.d.ts ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * `/v2`: published series and snapshots, each with its contract (scope `market:read`).
3
+ * Records are typed by id: `series.data('perp.funding.settlements', …)` answers
4
+ * `PerpFundingSettlementsRecord` rows. Filters are the contract's own names (`asset`,
5
+ * `venue`, …).
6
+ */
7
+ import type { Answer } from './answer.js';
8
+ import { type Instant, type QueryValue, type Transport } from './client.js';
9
+ import type { Envelope, SeriesCatalogue, SeriesId, SnapshotCatalogue, SnapshotId, V2Meta, WireRecord } from './types.gen.js';
10
+ /** Any series id the API lists; the known ones are typed. */
11
+ export type AnySeriesId = SeriesId | (string & {});
12
+ /** Any snapshot id the API lists; the known ones are typed. */
13
+ export type AnySnapshotId = SnapshotId | (string & {});
14
+ /** One record of series `I`. */
15
+ export type SeriesRecord<I extends string> = I extends SeriesId ? SeriesCatalogue[I]['record'] : WireRecord;
16
+ /** One instance of series `I`. */
17
+ export type SeriesInstance<I extends string> = I extends SeriesId ? SeriesCatalogue[I]['instance'] : WireRecord;
18
+ /** One record of snapshot `I`. */
19
+ export type SnapshotRecord<I extends string> = I extends SnapshotId ? SnapshotCatalogue[I]['record'] : WireRecord;
20
+ /** The contract of series `I` (`series.get`). */
21
+ export type SeriesContract<I extends string> = I extends SeriesId ? SeriesCatalogue[I]['contract'] : SeriesCatalogue[SeriesId]['contract'];
22
+ /** The contract of snapshot `I` (`snapshots.get`). */
23
+ export type SnapshotContract<I extends string> = I extends SnapshotId ? SnapshotCatalogue[I]['contract'] : SnapshotCatalogue[SnapshotId]['contract'];
24
+ /** A page of `/v2` records: `meta.cursor.next` reads on. */
25
+ export type V2Page<R> = Envelope<R[], V2Meta>;
26
+ /** A contract's filters, by their wire names (`asset`, `assets`, `venue`, `venues`,
27
+ * `exchange`, `kind`, `market`, …). */
28
+ export type V2Filters = {
29
+ asset?: string;
30
+ assets?: string | readonly string[];
31
+ venue?: string;
32
+ venues?: string | readonly string[];
33
+ exchange?: string;
34
+ kind?: string;
35
+ market?: string;
36
+ [filter: string]: QueryValue;
37
+ };
38
+ export type V2Read = V2Filters & {
39
+ /** The previous page's `meta.cursor.next`. */
40
+ cursor?: string;
41
+ /** Records per page. */
42
+ limit?: number;
43
+ };
44
+ export type SeriesApi = {
45
+ /** The series available to this key (`GET /v2/series`). */
46
+ list(): Promise<Answer<'v2_series'>>;
47
+ /** One series' contract: fields, guarantees, filters (`GET /v2/series/{id}`).
48
+ * `'corrections'` is not a series: `/v2/series/corrections` is the corrections feed
49
+ * (`t.get('/v2/series/corrections')`). */
50
+ get<I extends AnySeriesId>(id: I extends 'corrections' ? never : I): Promise<SeriesContract<I>>;
51
+ /** Records with `start <= time < end` (`GET /v2/series/{id}/data`, `from`/`to`). */
52
+ data<I extends AnySeriesId>(id: I, opts?: V2Read & {
53
+ start?: Instant;
54
+ end?: Instant;
55
+ }): Promise<V2Page<SeriesRecord<I>>>;
56
+ /** Each matching instance's most recent record (`GET /v2/series/{id}/latest`). */
57
+ latest<I extends AnySeriesId>(id: I, opts?: V2Read): Promise<V2Page<SeriesRecord<I>>>;
58
+ /** Instance keys, descriptors and coverage (`GET /v2/series/{id}/instances`). */
59
+ instances<I extends AnySeriesId>(id: I, opts?: V2Read): Promise<V2Page<SeriesInstance<I>>>;
60
+ };
61
+ export type SnapshotsApi = {
62
+ /** The snapshots available to this key (`GET /v2/snapshots`). */
63
+ list(): Promise<Answer<'v2_snapshots'>>;
64
+ /** One snapshot's contract (`GET /v2/snapshots/{id}`). */
65
+ get<I extends AnySnapshotId>(id: I): Promise<SnapshotContract<I>>;
66
+ /** Current records in key order (`GET /v2/snapshots/{id}/data`). */
67
+ data<I extends AnySnapshotId>(id: I, opts?: V2Read): Promise<V2Page<SnapshotRecord<I>>>;
68
+ };
69
+ export type V2Api = {
70
+ /** Time series. */
71
+ series: SeriesApi;
72
+ /** Snapshots: the current record per key. */
73
+ snapshots: SnapshotsApi;
74
+ };
75
+ export declare function v2Api(http: Transport): V2Api;
package/dist/v2.js ADDED
@@ -0,0 +1,25 @@
1
+ import { instant, segment } from "./client.js";
2
+ function read(o = {}) {
3
+ const { start, end, cursor, limit, ...filters } = o;
4
+ return { ...filters, from: instant(start), to: instant(end), cursor, limit };
5
+ }
6
+ export function v2Api(http) {
7
+ return {
8
+ series: {
9
+ list: () => http.get('/v2/series'),
10
+ get: (id) => {
11
+ if (id === 'corrections')
12
+ throw new TypeError("'corrections' is not a series: read the feed with t.get('/v2/series/corrections')");
13
+ return http.get(`/v2/series/${segment(id)}`);
14
+ },
15
+ data: (id, o) => http.get(`/v2/series/${segment(id)}/data`, read(o)),
16
+ latest: (id, o) => http.get(`/v2/series/${segment(id)}/latest`, read(o)),
17
+ instances: (id, o) => http.get(`/v2/series/${segment(id)}/instances`, read(o))
18
+ },
19
+ snapshots: {
20
+ list: () => http.get('/v2/snapshots'),
21
+ get: (id) => http.get(`/v2/snapshots/${segment(id)}`),
22
+ data: (id, o) => http.get(`/v2/snapshots/${segment(id)}/data`, read(o))
23
+ }
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@tribulnation/terminal",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Typed client for the Tribulnation Terminal API: your portfolio (/me), market data (/v1, /v2) and the live socket. Read-only, zero dependencies.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "sideEffects": false,
25
+ "license": "MIT",
26
+ "keywords": [
27
+ "tribulnation",
28
+ "terminal",
29
+ "crypto",
30
+ "market-data",
31
+ "funding-rates",
32
+ "portfolio",
33
+ "api-client"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/tribulnation/terminal.git",
38
+ "directory": "typescript"
39
+ },
40
+ "homepage": "https://api.tribulnation.com/docs",
41
+ "bugs": {
42
+ "url": "https://github.com/tribulnation/terminal/issues"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "provenance": true
47
+ },
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.build.json && node scripts/dts-extensions.mjs",
50
+ "check": "tsc --noEmit -p tsconfig.json",
51
+ "test": "node --test --test-reporter=dot \"test/*.test.ts\"",
52
+ "prepack": "npm run check && npm run build"
53
+ },
54
+ "dependencies": {},
55
+ "devDependencies": {
56
+ "typescript": "5.9.3"
57
+ }
58
+ }