@nadohq/nuanze-client 0.41.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.
- package/README.md +72 -0
- package/dist/NuanzeClient-BUjoXpWV.cjs +327 -0
- package/dist/NuanzeClient-BUjoXpWV.cjs.map +1 -0
- package/dist/NuanzeClient.cjs +4 -0
- package/dist/NuanzeClient.d.cts +229 -0
- package/dist/NuanzeClient.d.cts.map +1 -0
- package/dist/NuanzeClient.d.ts +229 -0
- package/dist/NuanzeClient.d.ts.map +1 -0
- package/dist/NuanzeClient.js +293 -0
- package/dist/NuanzeClient.js.map +1 -0
- package/dist/NuanzeServerFailureError-B9EhXPyW.d.cts +29 -0
- package/dist/NuanzeServerFailureError-B9EhXPyW.d.cts.map +1 -0
- package/dist/NuanzeServerFailureError-DqWaKEMA.d.ts +29 -0
- package/dist/NuanzeServerFailureError-DqWaKEMA.d.ts.map +1 -0
- package/dist/clientModelTypes-A-D7ER-p.d.ts +932 -0
- package/dist/clientModelTypes-A-D7ER-p.d.ts.map +1 -0
- package/dist/clientModelTypes-BLPA-e3V.d.cts +932 -0
- package/dist/clientModelTypes-BLPA-e3V.d.cts.map +1 -0
- package/dist/clientTypes-DdpinbkS.d.ts +642 -0
- package/dist/clientTypes-DdpinbkS.d.ts.map +1 -0
- package/dist/clientTypes-Du2RLy4W.d.cts +642 -0
- package/dist/clientTypes-Du2RLy4W.d.cts.map +1 -0
- package/dist/dataMappers.cjs +688 -0
- package/dist/dataMappers.cjs.map +1 -0
- package/dist/dataMappers.d.cts +159 -0
- package/dist/dataMappers.d.cts.map +1 -0
- package/dist/dataMappers.d.ts +159 -0
- package/dist/dataMappers.d.ts.map +1 -0
- package/dist/dataMappers.js +650 -0
- package/dist/dataMappers.js.map +1 -0
- package/dist/endpoints.cjs +18 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +14 -0
- package/dist/endpoints.d.cts.map +1 -0
- package/dist/endpoints.d.ts +14 -0
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +17 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.cjs +79 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/nuanzeErrorCodes-CWCTWh2k.d.cts +14 -0
- package/dist/nuanzeErrorCodes-CWCTWh2k.d.cts.map +1 -0
- package/dist/nuanzeErrorCodes-Dh6juim0.d.ts +14 -0
- package/dist/nuanzeErrorCodes-Dh6juim0.d.ts.map +1 -0
- package/dist/serverModelTypes-D-vS_7uc.d.ts +377 -0
- package/dist/serverModelTypes-D-vS_7uc.d.ts.map +1 -0
- package/dist/serverModelTypes-DZDxdIzz.d.cts +377 -0
- package/dist/serverModelTypes-DZDxdIzz.d.cts.map +1 -0
- package/dist/serverQueryTypes-BBIFZZ36.d.cts +240 -0
- package/dist/serverQueryTypes-BBIFZZ36.d.cts.map +1 -0
- package/dist/serverQueryTypes-e7HWmE8t.d.ts +240 -0
- package/dist/serverQueryTypes-e7HWmE8t.d.ts.map +1 -0
- package/dist/types/NuanzeServerFailureError.cjs +21 -0
- package/dist/types/NuanzeServerFailureError.cjs.map +1 -0
- package/dist/types/NuanzeServerFailureError.d.cts +2 -0
- package/dist/types/NuanzeServerFailureError.d.ts +2 -0
- package/dist/types/NuanzeServerFailureError.js +20 -0
- package/dist/types/NuanzeServerFailureError.js.map +1 -0
- package/dist/types/clientModelTypes.cjs +236 -0
- package/dist/types/clientModelTypes.cjs.map +1 -0
- package/dist/types/clientModelTypes.d.cts +2 -0
- package/dist/types/clientModelTypes.d.ts +2 -0
- package/dist/types/clientModelTypes.js +208 -0
- package/dist/types/clientModelTypes.js.map +1 -0
- package/dist/types/clientTypes.cjs +0 -0
- package/dist/types/clientTypes.d.cts +2 -0
- package/dist/types/clientTypes.d.ts +2 -0
- package/dist/types/clientTypes.js +1 -0
- package/dist/types/index.cjs +36 -0
- package/dist/types/index.d.cts +7 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +5 -0
- package/dist/types/nuanzeErrorCodes.cjs +32 -0
- package/dist/types/nuanzeErrorCodes.cjs.map +1 -0
- package/dist/types/nuanzeErrorCodes.d.cts +2 -0
- package/dist/types/nuanzeErrorCodes.d.ts +2 -0
- package/dist/types/nuanzeErrorCodes.js +31 -0
- package/dist/types/nuanzeErrorCodes.js.map +1 -0
- package/dist/types/serverModelTypes.cjs +0 -0
- package/dist/types/serverModelTypes.d.cts +2 -0
- package/dist/types/serverModelTypes.d.ts +2 -0
- package/dist/types/serverModelTypes.js +1 -0
- package/dist/types/serverQueryTypes.cjs +15 -0
- package/dist/types/serverQueryTypes.cjs.map +1 -0
- package/dist/types/serverQueryTypes.d.cts +2 -0
- package/dist/types/serverQueryTypes.d.ts +2 -0
- package/dist/types/serverQueryTypes.js +14 -0
- package/dist/types/serverQueryTypes.js.map +1 -0
- package/package.json +54 -0
- package/src/NuanzeClient.ts +556 -0
- package/src/dataMappers.ts +889 -0
- package/src/endpoints.ts +14 -0
- package/src/index.ts +4 -0
- package/src/types/NuanzeServerFailureError.ts +36 -0
- package/src/types/clientModelTypes.ts +1085 -0
- package/src/types/clientTypes.ts +719 -0
- package/src/types/index.ts +6 -0
- package/src/types/nuanzeErrorCodes.ts +31 -0
- package/src/types/serverModelTypes.ts +422 -0
- package/src/types/serverQueryTypes.ts +298 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { mapNuanzeCollateralFlowSeriesResponse, mapNuanzeCollateralFlowSummaryResponse, mapNuanzeCollateralFlowsResponse, mapNuanzeFollowedLeaderboardResponse, mapNuanzeFundingRatesResponse, mapNuanzeLeaderboardResponse, mapNuanzeMarketByTickerResponse, mapNuanzeMarketCandlesResponse, mapNuanzeMarketPositioningResponse, mapNuanzeMarketPositionsResponse, mapNuanzeMarketTradesResponse, mapNuanzeMarketsResponse, mapNuanzeNewsResponse, mapNuanzeOpenPositionsResponse, mapNuanzePlatformSummaryResponse, mapNuanzeWalletPnlResponse, mapNuanzeWalletPnlSeriesResponse, mapNuanzeWalletPositionsResponse, mapNuanzeWalletSummaryResponse, mapNuanzeWalletTradesResponse } from "./dataMappers.js";
|
|
2
|
+
import { NuanzeServerFailureError } from "./types/NuanzeServerFailureError.js";
|
|
3
|
+
import { isNuanzeServerFailureResponse } from "./types/serverQueryTypes.js";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
//#region src/NuanzeClient.ts
|
|
6
|
+
/**
|
|
7
|
+
* Client for the Nuanze public analytics API: markets, wallets, trades, candles, collateral flows,
|
|
8
|
+
* and positioning.
|
|
9
|
+
*
|
|
10
|
+
* Read-only and credential-free, so unlike the other service clients it takes no wallet client or
|
|
11
|
+
* linked signer. It also sends no `x-nado-client-type` header: Nuanze is a public API that does not
|
|
12
|
+
* attribute traffic per client, and its `Access-Control-Allow-Headers` does not list the header, so
|
|
13
|
+
* sending it would fail CORS preflight in the browser. Most operations are GET;
|
|
14
|
+
* {@link NuanzeClient.getFollowedLeaderboard} is a non-mutating POST whose body carries a followed
|
|
15
|
+
* set larger than a query string can reliably hold. The API meters a weighted token bucket per
|
|
16
|
+
* client IP and reports its state in the `RateLimit-Limit`, `RateLimit-Remaining`, and
|
|
17
|
+
* `RateLimit-Reset` response headers; add an interceptor on {@link axiosInstance} to observe them.
|
|
18
|
+
*/
|
|
19
|
+
var NuanzeClient = class {
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
this.opts = opts;
|
|
22
|
+
this.axiosInstance = axios.create({
|
|
23
|
+
withCredentials: false,
|
|
24
|
+
validateStatus: () => true,
|
|
25
|
+
paramsSerializer: { indexes: null }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Lists published editorial stories, sorted by `publishedAt` descending then `id` descending.
|
|
30
|
+
* The opaque cursor is exclusive and bound to normalized filters. Raw article ingestion, scoring,
|
|
31
|
+
* queue, and newsdesk fields are excluded.
|
|
32
|
+
*
|
|
33
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST`, `INVALID_CURSOR`, or
|
|
34
|
+
* `CURSOR_FILTER_MISMATCH` when filters or the cursor are invalid.
|
|
35
|
+
*/
|
|
36
|
+
async getNews(params = {}) {
|
|
37
|
+
return mapNuanzeNewsResponse(await this.getJson("/news", params));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the active market universe, ordered by `productId` ascending. Never truncated, so `count`
|
|
41
|
+
* always equals the length of `markets`. Market metadata refreshes about every five minutes and
|
|
42
|
+
* prices about every minute.
|
|
43
|
+
*
|
|
44
|
+
* @throws {NuanzeServerFailureError} With error code `BAD_REQUEST` if a filter value is not a
|
|
45
|
+
* documented venue or tradability state.
|
|
46
|
+
*/
|
|
47
|
+
async getMarkets(params = {}) {
|
|
48
|
+
return mapNuanzeMarketsResponse(await this.getJson("/markets", params));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a market by ticker. Lookup is case-insensitive and accepts canonical tickers or
|
|
52
|
+
* legacy source symbols. An explicit unavailable venue returns `MARKET_NOT_FOUND`. With no
|
|
53
|
+
* venue, `strictVenue=true` returns `AMBIGUOUS_MARKET` for multi-venue assets; otherwise the
|
|
54
|
+
* primary venue is used.
|
|
55
|
+
*
|
|
56
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or
|
|
57
|
+
* `BAD_REQUEST` on invalid selectors, and `MARKET_NOT_FOUND` when the ticker does not resolve.
|
|
58
|
+
*/
|
|
59
|
+
async getMarketByTicker(params) {
|
|
60
|
+
const { ticker, ...query } = params;
|
|
61
|
+
return mapNuanzeMarketByTickerResponse(await this.getJson(`/markets/${encodeURIComponent(ticker)}`, query));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Lists the latest funding observation per active perpetual market, refreshed about every five
|
|
65
|
+
* minutes.
|
|
66
|
+
*
|
|
67
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.
|
|
68
|
+
*/
|
|
69
|
+
async getFundingRates(params = {}) {
|
|
70
|
+
return mapNuanzeFundingRatesResponse(await this.getJson("/funding/rates", params));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the account PnL leaderboard. Equity-basis account PnL includes realized and unrealized
|
|
74
|
+
* movement plus funding and is not realized PnL. All-time analytics cost five rate-limit units.
|
|
75
|
+
*
|
|
76
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.
|
|
77
|
+
*/
|
|
78
|
+
async getLeaderboard(params = {}) {
|
|
79
|
+
return mapNuanzeLeaderboardResponse(await this.getJson("/leaderboard", params));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets platform activity summary from five-minute aggregates.
|
|
83
|
+
*
|
|
84
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if the window is not a documented value.
|
|
85
|
+
*/
|
|
86
|
+
async getPlatformSummary(params = {}) {
|
|
87
|
+
return mapNuanzePlatformSummaryResponse(await this.getJson("/platform/summary", params));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Gets leaderboard stats for a set of followed subaccounts. POST rather than GET so the body can
|
|
91
|
+
* carry up to 300 `subaccountHex` values. The response preserves request order. Subaccounts with
|
|
92
|
+
* no data in the window are backfilled with `pnl: null`, `globalRank: null`, zero counts, and an
|
|
93
|
+
* empty `productIds`. Costs five rate-limit units. The response is not cached.
|
|
94
|
+
*
|
|
95
|
+
* @throws {NuanzeServerFailureError} With `INVALID_SUBACCOUNT` if a hex is not 32-byte
|
|
96
|
+
* 0x-prefixed, and `BAD_REQUEST` if the set is empty, exceeds 300, or `timeframe` is not a
|
|
97
|
+
* documented value.
|
|
98
|
+
*/
|
|
99
|
+
async getFollowedLeaderboard(params) {
|
|
100
|
+
return mapNuanzeFollowedLeaderboardResponse(await this.postJson("/wallets/leaderboard", params));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Gets replica-backed wallet analytics. Without `subaccountName`, latest cumulative values are
|
|
104
|
+
* selected per known subaccount and then summed. The response is a snapshot and does not claim
|
|
105
|
+
* live health, withdrawable collateral, open-order, or signer state.
|
|
106
|
+
*
|
|
107
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
108
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
109
|
+
*/
|
|
110
|
+
async getWalletSummary(params) {
|
|
111
|
+
const { address, ...query } = params;
|
|
112
|
+
return mapNuanzeWalletSummaryResponse(await this.getJson(`/wallets/${encodeURIComponent(address)}`, query));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Lists at most 500 current replica position rows across all known subaccounts by default. Rows
|
|
116
|
+
* remain per subaccount. Spot rows are excluded unless `includeSpot=true`. This is not an
|
|
117
|
+
* execution-grade live feed.
|
|
118
|
+
*
|
|
119
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
120
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
121
|
+
*/
|
|
122
|
+
async getWalletPositions(params) {
|
|
123
|
+
const { address, ...query } = params;
|
|
124
|
+
return mapNuanzeWalletPositionsResponse(await this.getJson(`/wallets/${encodeURIComponent(address)}/positions`, query));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Lists market trades: one taker-side row per match, sorted by `matchedAt` then `id` descending.
|
|
128
|
+
* The exclusive cursor is bound to operation and normalized filters. `from` is inclusive and
|
|
129
|
+
* `to` exclusive. Wallet identity is absent.
|
|
130
|
+
*
|
|
131
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`,
|
|
132
|
+
* `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, `RANGE_TOO_LARGE`, or `BAD_REQUEST` on invalid
|
|
133
|
+
* input, and `MARKET_NOT_FOUND` when the ticker does not resolve.
|
|
134
|
+
*/
|
|
135
|
+
async getMarketTrades(params) {
|
|
136
|
+
const { ticker, ...query } = params;
|
|
137
|
+
return mapNuanzeMarketTradesResponse(await this.getJson(`/markets/${encodeURIComponent(ticker)}/trades`, query));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Lists market candles. Source storage is 1h; 4h and 1d are UTC-aligned rollups and missing bars
|
|
141
|
+
* are not interpolated. The newest `limit` matching bars are selected and returned
|
|
142
|
+
* oldest-to-newest, at most 750, with no pagination. A current bucket has `complete=false`.
|
|
143
|
+
*
|
|
144
|
+
* @throws {NuanzeServerFailureError} With `UNSUPPORTED_INTERVAL`, `RANGE_TOO_LARGE`,
|
|
145
|
+
* `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or `BAD_REQUEST` on invalid input, and
|
|
146
|
+
* `MARKET_NOT_FOUND` when the ticker does not resolve.
|
|
147
|
+
*/
|
|
148
|
+
async getMarketCandles(params) {
|
|
149
|
+
const { ticker, ...query } = params;
|
|
150
|
+
return mapNuanzeMarketCandlesResponse(await this.getJson(`/markets/${encodeURIComponent(ticker)}/candles`, query));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Lists wallet-owned maker and taker execution rows, sorted by `matchedAt` then `id` descending.
|
|
154
|
+
* The cursor is exclusive and filter-bound. `from` is inclusive and `to` exclusive.
|
|
155
|
+
*
|
|
156
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS`, `INVALID_CURSOR`,
|
|
157
|
+
* `CURSOR_FILTER_MISMATCH`, `RANGE_TOO_LARGE`, or `BAD_REQUEST` on invalid input, and
|
|
158
|
+
* `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
159
|
+
*/
|
|
160
|
+
async getWalletTrades(params) {
|
|
161
|
+
const { address, ...query } = params;
|
|
162
|
+
return mapNuanzeWalletTradesResponse(await this.getJson(`/wallets/${encodeURIComponent(address)}/trades`, query));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Gets wallet account PnL. 24h is rolling and uses hourly snapshots with a daily fallback
|
|
166
|
+
* baseline. Longer windows use daily snapshots; `all` starts at earliest coverage. PnL includes
|
|
167
|
+
* realized and unrealized movement plus funding.
|
|
168
|
+
*
|
|
169
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
170
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
171
|
+
*/
|
|
172
|
+
async getWalletPnl(params) {
|
|
173
|
+
const { address, ...query } = params;
|
|
174
|
+
return mapNuanzeWalletPnlResponse(await this.getJson(`/wallets/${encodeURIComponent(address)}/pnl`, query));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Gets a wallet account series of at most 1,000 deterministically sampled points ordered by
|
|
178
|
+
* timestamp. Series contain a boundary anchor and a carried-forward request-time tip; synthetic
|
|
179
|
+
* points are identified. Latest buckets may be provisional.
|
|
180
|
+
*
|
|
181
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
182
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
183
|
+
*/
|
|
184
|
+
async getWalletPnlSeries(params) {
|
|
185
|
+
const { address, ...query } = params;
|
|
186
|
+
return mapNuanzeWalletPnlSeriesResponse(await this.getJson(`/wallets/${encodeURIComponent(address)}/pnl/series`, query));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Lists public collateral events, sorted by timestamp then `id` descending. Repeated `productId`
|
|
190
|
+
* uses OR semantics. `minUsd` excludes unvalued events; without it unvalued events remain.
|
|
191
|
+
*
|
|
192
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST`, `INVALID_CURSOR`, or
|
|
193
|
+
* `CURSOR_FILTER_MISMATCH` when filters or the cursor are invalid.
|
|
194
|
+
*/
|
|
195
|
+
async getCollateralFlows(params = {}) {
|
|
196
|
+
return mapNuanzeCollateralFlowsResponse(await this.getJson("/flows", params));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Gets collateral flow aggregates: deposited, withdrawn, net, and gross, with valuation coverage
|
|
200
|
+
* and a prior equal-window comparison. `all` has no prior window.
|
|
201
|
+
*
|
|
202
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.
|
|
203
|
+
*/
|
|
204
|
+
async getCollateralFlowSummary(params = {}) {
|
|
205
|
+
return mapNuanzeCollateralFlowSummaryResponse(await this.getJson("/flows/summary", params));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Gets collateral flow series of at most 1,000 UTC buckets. Allowed timeframe/bucket pairs are
|
|
209
|
+
* 24h/hour, 7d/hour or day (default hour), 30d/day, and all/day.
|
|
210
|
+
*
|
|
211
|
+
* @throws {NuanzeServerFailureError} With `UNSUPPORTED_BUCKET` or `BAD_REQUEST` when the pair or
|
|
212
|
+
* filters are invalid.
|
|
213
|
+
*/
|
|
214
|
+
async getCollateralFlowSeries(params = {}) {
|
|
215
|
+
return mapNuanzeCollateralFlowSeriesResponse(await this.getJson("/flows/series", params));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Gets privacy-preserving aggregate positioning for an active perpetual. Cross and isolated legs
|
|
219
|
+
* are summed within owner/subaccount/product before direction classification. Every cell requires
|
|
220
|
+
* at least 20 distinct contributing owners. No identity, individual position, entry price, PnL,
|
|
221
|
+
* margin, or leverage fields are returned. This operation costs five rate-limit units.
|
|
222
|
+
*
|
|
223
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or
|
|
224
|
+
* `BAD_REQUEST` on invalid input, and `MARKET_NOT_FOUND` when the ticker does not resolve to a
|
|
225
|
+
* perp.
|
|
226
|
+
*/
|
|
227
|
+
async getMarketPositioning(params) {
|
|
228
|
+
const { ticker, ...query } = params;
|
|
229
|
+
return mapNuanzeMarketPositioningResponse(await this.getJson(`/markets/${encodeURIComponent(ticker)}/positioning`, query));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Lists open perpetual position legs for the resolved market. Results default to absolute
|
|
233
|
+
* notional descending and can be ordered by signed unrealized PnL or absolute base amount in
|
|
234
|
+
* either direction. Spot markets are not supported. Legs below $10 absolute notional are excluded.
|
|
235
|
+
* Wallet addresses and signed exact base amounts are returned.
|
|
236
|
+
*
|
|
237
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`,
|
|
238
|
+
* `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, or `BAD_REQUEST` on invalid input, and
|
|
239
|
+
* `MARKET_NOT_FOUND` when the ticker does not resolve to a perp.
|
|
240
|
+
*/
|
|
241
|
+
async getMarketPositions(params) {
|
|
242
|
+
const { ticker, ...query } = params;
|
|
243
|
+
return mapNuanzeMarketPositionsResponse(await this.getJson(`/markets/${encodeURIComponent(ticker)}/positions`, query));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Lists current open perpetual position legs across every market by signed unrealized PnL.
|
|
247
|
+
* Descending returns the largest gainers and ascending returns the largest losers. This is a
|
|
248
|
+
* latest indexed snapshot with no timeframe. Legs below $10 absolute notional are excluded.
|
|
249
|
+
* Each row includes market identity and its source snapshot timestamp. Costs five rate-limit
|
|
250
|
+
* units.
|
|
251
|
+
*
|
|
252
|
+
* @throws {NuanzeServerFailureError} With `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, or
|
|
253
|
+
* `BAD_REQUEST` when the query or cursor is invalid.
|
|
254
|
+
*/
|
|
255
|
+
async getOpenPositions(params = {}) {
|
|
256
|
+
return mapNuanzeOpenPositionsResponse(await this.getJson("/positions", params));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Performs a GET against `{baseUrl}{path}` and classifies the status before returning the body.
|
|
260
|
+
*/
|
|
261
|
+
async getJson(path, params) {
|
|
262
|
+
return this.requestJson("GET", path, { params });
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Performs a POST against `{baseUrl}{path}` with a JSON body and classifies the status before
|
|
266
|
+
* returning the response. Used only for the non-mutating followed-leaderboard operation.
|
|
267
|
+
*/
|
|
268
|
+
async postJson(path, data) {
|
|
269
|
+
return this.requestJson("POST", path, { data });
|
|
270
|
+
}
|
|
271
|
+
async requestJson(method, path, config = {}) {
|
|
272
|
+
const response = await this.axiosInstance.request({
|
|
273
|
+
method,
|
|
274
|
+
url: `${this.opts.url}${path}`,
|
|
275
|
+
...config
|
|
276
|
+
});
|
|
277
|
+
this.checkResponseStatus(response);
|
|
278
|
+
return response.data;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Validates the HTTP status before interpreting the body. Nuanze maps every domain failure onto a
|
|
282
|
+
* non-2xx status carrying a failure envelope, so anything else is a transport-level error.
|
|
283
|
+
*/
|
|
284
|
+
checkResponseStatus(response) {
|
|
285
|
+
if (response.status >= 200 && response.status < 300) return;
|
|
286
|
+
if (isNuanzeServerFailureResponse(response.data)) throw new NuanzeServerFailureError(response.data, response.status);
|
|
287
|
+
throw new Error(`Unexpected response from Nuanze: ${response.status} ${response.statusText}. Data: ${JSON.stringify(response.data)}`);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
//#endregion
|
|
291
|
+
export { NuanzeClient };
|
|
292
|
+
|
|
293
|
+
//# sourceMappingURL=NuanzeClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuanzeClient.js","names":[],"sources":["../src/NuanzeClient.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapNuanzeCollateralFlowSeriesResponse,\n mapNuanzeCollateralFlowSummaryResponse,\n mapNuanzeCollateralFlowsResponse,\n mapNuanzeFollowedLeaderboardResponse,\n mapNuanzeFundingRatesResponse,\n mapNuanzeLeaderboardResponse,\n mapNuanzeMarketByTickerResponse,\n mapNuanzeMarketCandlesResponse,\n mapNuanzeMarketPositioningResponse,\n mapNuanzeMarketPositionsResponse,\n mapNuanzeMarketTradesResponse,\n mapNuanzeMarketsResponse,\n mapNuanzeNewsResponse,\n mapNuanzeOpenPositionsResponse,\n mapNuanzePlatformSummaryResponse,\n mapNuanzeWalletPnlResponse,\n mapNuanzeWalletPnlSeriesResponse,\n mapNuanzeWalletPositionsResponse,\n mapNuanzeWalletSummaryResponse,\n mapNuanzeWalletTradesResponse,\n} from './dataMappers';\nimport {\n GetNuanzeCollateralFlowSeriesParams,\n GetNuanzeCollateralFlowSeriesResponse,\n GetNuanzeCollateralFlowSummaryParams,\n GetNuanzeCollateralFlowSummaryResponse,\n GetNuanzeCollateralFlowsParams,\n GetNuanzeCollateralFlowsResponse,\n GetNuanzeFollowedLeaderboardParams,\n GetNuanzeFollowedLeaderboardResponse,\n GetNuanzeFundingRatesParams,\n GetNuanzeFundingRatesResponse,\n GetNuanzeLeaderboardParams,\n GetNuanzeLeaderboardResponse,\n GetNuanzeMarketByTickerParams,\n GetNuanzeMarketByTickerResponse,\n GetNuanzeMarketCandlesParams,\n GetNuanzeMarketCandlesResponse,\n GetNuanzeMarketPositioningParams,\n GetNuanzeMarketPositioningResponse,\n GetNuanzeMarketPositionsParams,\n GetNuanzeMarketPositionsResponse,\n GetNuanzeMarketTradesParams,\n GetNuanzeMarketTradesResponse,\n GetNuanzeMarketsParams,\n GetNuanzeMarketsResponse,\n GetNuanzeNewsParams,\n GetNuanzeNewsResponse,\n GetNuanzeOpenPositionsParams,\n GetNuanzeOpenPositionsResponse,\n GetNuanzePlatformSummaryParams,\n GetNuanzePlatformSummaryResponse,\n GetNuanzeWalletPnlParams,\n GetNuanzeWalletPnlResponse,\n GetNuanzeWalletPnlSeriesParams,\n GetNuanzeWalletPnlSeriesResponse,\n GetNuanzeWalletPositionsParams,\n GetNuanzeWalletPositionsResponse,\n GetNuanzeWalletSummaryParams,\n GetNuanzeWalletSummaryResponse,\n GetNuanzeWalletTradesParams,\n GetNuanzeWalletTradesResponse,\n} from './types/clientTypes';\nimport { NuanzeServerFailureError } from './types/NuanzeServerFailureError';\nimport { NuanzeServerMarketPositioningResponse } from './types/serverModelTypes';\nimport {\n NuanzeServerCollateralFlowSeriesResponse,\n NuanzeServerCollateralFlowSummaryResponse,\n NuanzeServerCollateralFlowsResponse,\n NuanzeServerFollowedLeaderboardResponse,\n NuanzeServerFundingRatesResponse,\n NuanzeServerLeaderboardResponse,\n NuanzeServerMarketByTickerResponse,\n NuanzeServerMarketCandlesResponse,\n NuanzeServerMarketPositionsResponse,\n NuanzeServerMarketTradesResponse,\n NuanzeServerMarketsResponse,\n NuanzeServerNewsResponse,\n NuanzeServerOpenPositionsResponse,\n NuanzeServerPlatformSummaryResponse,\n NuanzeServerWalletPnlResponse,\n NuanzeServerWalletPnlSeriesResponse,\n NuanzeServerWalletPositionsResponse,\n NuanzeServerWalletSummaryResponse,\n NuanzeServerWalletTradesResponse,\n isNuanzeServerFailureResponse,\n} from './types/serverQueryTypes';\n\n/**\n * Options for constructing a {@link NuanzeClient}.\n */\nexport interface NuanzeClientOpts {\n /**\n * Base URL of the Nuanze API, including the version segment, e.g. {@link NUANZE_CLIENT_ENDPOINTS}.\n */\n url: string;\n}\n\n/**\n * Client for the Nuanze public analytics API: markets, wallets, trades, candles, collateral flows,\n * and positioning.\n *\n * Read-only and credential-free, so unlike the other service clients it takes no wallet client or\n * linked signer. It also sends no `x-nado-client-type` header: Nuanze is a public API that does not\n * attribute traffic per client, and its `Access-Control-Allow-Headers` does not list the header, so\n * sending it would fail CORS preflight in the browser. Most operations are GET;\n * {@link NuanzeClient.getFollowedLeaderboard} is a non-mutating POST whose body carries a followed\n * set larger than a query string can reliably hold. The API meters a weighted token bucket per\n * client IP and reports its state in the `RateLimit-Limit`, `RateLimit-Remaining`, and\n * `RateLimit-Reset` response headers; add an interceptor on {@link axiosInstance} to observe them.\n */\nexport class NuanzeClient {\n readonly opts: NuanzeClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: NuanzeClientOpts) {\n this.opts = opts;\n this.axiosInstance = axios.create({\n // Nuanze is public and answers every origin with `Access-Control-Allow-Origin: *`, which\n // browsers reject for credentialed requests.\n withCredentials: false,\n // We have custom logic to validate response status and create an appropriate error\n validateStatus: () => true,\n // Repeatable `productId` must serialize as `productId=1&productId=2` (OpenAPI explode).\n paramsSerializer: { indexes: null },\n });\n }\n\n /**\n * Lists published editorial stories, sorted by `publishedAt` descending then `id` descending.\n * The opaque cursor is exclusive and bound to normalized filters. Raw article ingestion, scoring,\n * queue, and newsdesk fields are excluded.\n *\n * @throws {NuanzeServerFailureError} With `BAD_REQUEST`, `INVALID_CURSOR`, or\n * `CURSOR_FILTER_MISMATCH` when filters or the cursor are invalid.\n */\n async getNews(\n params: GetNuanzeNewsParams = {},\n ): Promise<GetNuanzeNewsResponse> {\n return mapNuanzeNewsResponse(\n await this.getJson<NuanzeServerNewsResponse>('/news', params),\n );\n }\n\n /**\n * Gets the active market universe, ordered by `productId` ascending. Never truncated, so `count`\n * always equals the length of `markets`. Market metadata refreshes about every five minutes and\n * prices about every minute.\n *\n * @throws {NuanzeServerFailureError} With error code `BAD_REQUEST` if a filter value is not a\n * documented venue or tradability state.\n */\n async getMarkets(\n params: GetNuanzeMarketsParams = {},\n ): Promise<GetNuanzeMarketsResponse> {\n return mapNuanzeMarketsResponse(\n await this.getJson<NuanzeServerMarketsResponse>('/markets', params),\n );\n }\n\n /**\n * Resolves a market by ticker. Lookup is case-insensitive and accepts canonical tickers or\n * legacy source symbols. An explicit unavailable venue returns `MARKET_NOT_FOUND`. With no\n * venue, `strictVenue=true` returns `AMBIGUOUS_MARKET` for multi-venue assets; otherwise the\n * primary venue is used.\n *\n * @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or\n * `BAD_REQUEST` on invalid selectors, and `MARKET_NOT_FOUND` when the ticker does not resolve.\n */\n async getMarketByTicker(\n params: GetNuanzeMarketByTickerParams,\n ): Promise<GetNuanzeMarketByTickerResponse> {\n const { ticker, ...query } = params;\n return mapNuanzeMarketByTickerResponse(\n await this.getJson<NuanzeServerMarketByTickerResponse>(\n `/markets/${encodeURIComponent(ticker)}`,\n query,\n ),\n );\n }\n\n /**\n * Lists the latest funding observation per active perpetual market, refreshed about every five\n * minutes.\n *\n * @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.\n */\n async getFundingRates(\n params: GetNuanzeFundingRatesParams = {},\n ): Promise<GetNuanzeFundingRatesResponse> {\n return mapNuanzeFundingRatesResponse(\n await this.getJson<NuanzeServerFundingRatesResponse>(\n '/funding/rates',\n params,\n ),\n );\n }\n\n /**\n * Gets the account PnL leaderboard. Equity-basis account PnL includes realized and unrealized\n * movement plus funding and is not realized PnL. All-time analytics cost five rate-limit units.\n *\n * @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.\n */\n async getLeaderboard(\n params: GetNuanzeLeaderboardParams = {},\n ): Promise<GetNuanzeLeaderboardResponse> {\n return mapNuanzeLeaderboardResponse(\n await this.getJson<NuanzeServerLeaderboardResponse>(\n '/leaderboard',\n params,\n ),\n );\n }\n\n /**\n * Gets platform activity summary from five-minute aggregates.\n *\n * @throws {NuanzeServerFailureError} With `BAD_REQUEST` if the window is not a documented value.\n */\n async getPlatformSummary(\n params: GetNuanzePlatformSummaryParams = {},\n ): Promise<GetNuanzePlatformSummaryResponse> {\n return mapNuanzePlatformSummaryResponse(\n await this.getJson<NuanzeServerPlatformSummaryResponse>(\n '/platform/summary',\n params,\n ),\n );\n }\n\n /**\n * Gets leaderboard stats for a set of followed subaccounts. POST rather than GET so the body can\n * carry up to 300 `subaccountHex` values. The response preserves request order. Subaccounts with\n * no data in the window are backfilled with `pnl: null`, `globalRank: null`, zero counts, and an\n * empty `productIds`. Costs five rate-limit units. The response is not cached.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_SUBACCOUNT` if a hex is not 32-byte\n * 0x-prefixed, and `BAD_REQUEST` if the set is empty, exceeds 300, or `timeframe` is not a\n * documented value.\n */\n async getFollowedLeaderboard(\n params: GetNuanzeFollowedLeaderboardParams,\n ): Promise<GetNuanzeFollowedLeaderboardResponse> {\n return mapNuanzeFollowedLeaderboardResponse(\n await this.postJson<NuanzeServerFollowedLeaderboardResponse>(\n '/wallets/leaderboard',\n params,\n ),\n );\n }\n\n /**\n * Gets replica-backed wallet analytics. Without `subaccountName`, latest cumulative values are\n * selected per known subaccount and then summed. The response is a snapshot and does not claim\n * live health, withdrawable collateral, open-order, or signer state.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,\n * and `WALLET_NOT_FOUND` when the address has no wallet data.\n */\n async getWalletSummary(\n params: GetNuanzeWalletSummaryParams,\n ): Promise<GetNuanzeWalletSummaryResponse> {\n const { address, ...query } = params;\n return mapNuanzeWalletSummaryResponse(\n await this.getJson<NuanzeServerWalletSummaryResponse>(\n `/wallets/${encodeURIComponent(address)}`,\n query,\n ),\n );\n }\n\n /**\n * Lists at most 500 current replica position rows across all known subaccounts by default. Rows\n * remain per subaccount. Spot rows are excluded unless `includeSpot=true`. This is not an\n * execution-grade live feed.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,\n * and `WALLET_NOT_FOUND` when the address has no wallet data.\n */\n async getWalletPositions(\n params: GetNuanzeWalletPositionsParams,\n ): Promise<GetNuanzeWalletPositionsResponse> {\n const { address, ...query } = params;\n return mapNuanzeWalletPositionsResponse(\n await this.getJson<NuanzeServerWalletPositionsResponse>(\n `/wallets/${encodeURIComponent(address)}/positions`,\n query,\n ),\n );\n }\n\n /**\n * Lists market trades: one taker-side row per match, sorted by `matchedAt` then `id` descending.\n * The exclusive cursor is bound to operation and normalized filters. `from` is inclusive and\n * `to` exclusive. Wallet identity is absent.\n *\n * @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`,\n * `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, `RANGE_TOO_LARGE`, or `BAD_REQUEST` on invalid\n * input, and `MARKET_NOT_FOUND` when the ticker does not resolve.\n */\n async getMarketTrades(\n params: GetNuanzeMarketTradesParams,\n ): Promise<GetNuanzeMarketTradesResponse> {\n const { ticker, ...query } = params;\n return mapNuanzeMarketTradesResponse(\n await this.getJson<NuanzeServerMarketTradesResponse>(\n `/markets/${encodeURIComponent(ticker)}/trades`,\n query,\n ),\n );\n }\n\n /**\n * Lists market candles. Source storage is 1h; 4h and 1d are UTC-aligned rollups and missing bars\n * are not interpolated. The newest `limit` matching bars are selected and returned\n * oldest-to-newest, at most 750, with no pagination. A current bucket has `complete=false`.\n *\n * @throws {NuanzeServerFailureError} With `UNSUPPORTED_INTERVAL`, `RANGE_TOO_LARGE`,\n * `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or `BAD_REQUEST` on invalid input, and\n * `MARKET_NOT_FOUND` when the ticker does not resolve.\n */\n async getMarketCandles(\n params: GetNuanzeMarketCandlesParams,\n ): Promise<GetNuanzeMarketCandlesResponse> {\n const { ticker, ...query } = params;\n return mapNuanzeMarketCandlesResponse(\n await this.getJson<NuanzeServerMarketCandlesResponse>(\n `/markets/${encodeURIComponent(ticker)}/candles`,\n query,\n ),\n );\n }\n\n /**\n * Lists wallet-owned maker and taker execution rows, sorted by `matchedAt` then `id` descending.\n * The cursor is exclusive and filter-bound. `from` is inclusive and `to` exclusive.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_ADDRESS`, `INVALID_CURSOR`,\n * `CURSOR_FILTER_MISMATCH`, `RANGE_TOO_LARGE`, or `BAD_REQUEST` on invalid input, and\n * `WALLET_NOT_FOUND` when the address has no wallet data.\n */\n async getWalletTrades(\n params: GetNuanzeWalletTradesParams,\n ): Promise<GetNuanzeWalletTradesResponse> {\n const { address, ...query } = params;\n return mapNuanzeWalletTradesResponse(\n await this.getJson<NuanzeServerWalletTradesResponse>(\n `/wallets/${encodeURIComponent(address)}/trades`,\n query,\n ),\n );\n }\n\n /**\n * Gets wallet account PnL. 24h is rolling and uses hourly snapshots with a daily fallback\n * baseline. Longer windows use daily snapshots; `all` starts at earliest coverage. PnL includes\n * realized and unrealized movement plus funding.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,\n * and `WALLET_NOT_FOUND` when the address has no wallet data.\n */\n async getWalletPnl(\n params: GetNuanzeWalletPnlParams,\n ): Promise<GetNuanzeWalletPnlResponse> {\n const { address, ...query } = params;\n return mapNuanzeWalletPnlResponse(\n await this.getJson<NuanzeServerWalletPnlResponse>(\n `/wallets/${encodeURIComponent(address)}/pnl`,\n query,\n ),\n );\n }\n\n /**\n * Gets a wallet account series of at most 1,000 deterministically sampled points ordered by\n * timestamp. Series contain a boundary anchor and a carried-forward request-time tip; synthetic\n * points are identified. Latest buckets may be provisional.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,\n * and `WALLET_NOT_FOUND` when the address has no wallet data.\n */\n async getWalletPnlSeries(\n params: GetNuanzeWalletPnlSeriesParams,\n ): Promise<GetNuanzeWalletPnlSeriesResponse> {\n const { address, ...query } = params;\n return mapNuanzeWalletPnlSeriesResponse(\n await this.getJson<NuanzeServerWalletPnlSeriesResponse>(\n `/wallets/${encodeURIComponent(address)}/pnl/series`,\n query,\n ),\n );\n }\n\n /**\n * Lists public collateral events, sorted by timestamp then `id` descending. Repeated `productId`\n * uses OR semantics. `minUsd` excludes unvalued events; without it unvalued events remain.\n *\n * @throws {NuanzeServerFailureError} With `BAD_REQUEST`, `INVALID_CURSOR`, or\n * `CURSOR_FILTER_MISMATCH` when filters or the cursor are invalid.\n */\n async getCollateralFlows(\n params: GetNuanzeCollateralFlowsParams = {},\n ): Promise<GetNuanzeCollateralFlowsResponse> {\n return mapNuanzeCollateralFlowsResponse(\n await this.getJson<NuanzeServerCollateralFlowsResponse>('/flows', params),\n );\n }\n\n /**\n * Gets collateral flow aggregates: deposited, withdrawn, net, and gross, with valuation coverage\n * and a prior equal-window comparison. `all` has no prior window.\n *\n * @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.\n */\n async getCollateralFlowSummary(\n params: GetNuanzeCollateralFlowSummaryParams = {},\n ): Promise<GetNuanzeCollateralFlowSummaryResponse> {\n return mapNuanzeCollateralFlowSummaryResponse(\n await this.getJson<NuanzeServerCollateralFlowSummaryResponse>(\n '/flows/summary',\n params,\n ),\n );\n }\n\n /**\n * Gets collateral flow series of at most 1,000 UTC buckets. Allowed timeframe/bucket pairs are\n * 24h/hour, 7d/hour or day (default hour), 30d/day, and all/day.\n *\n * @throws {NuanzeServerFailureError} With `UNSUPPORTED_BUCKET` or `BAD_REQUEST` when the pair or\n * filters are invalid.\n */\n async getCollateralFlowSeries(\n params: GetNuanzeCollateralFlowSeriesParams = {},\n ): Promise<GetNuanzeCollateralFlowSeriesResponse> {\n return mapNuanzeCollateralFlowSeriesResponse(\n await this.getJson<NuanzeServerCollateralFlowSeriesResponse>(\n '/flows/series',\n params,\n ),\n );\n }\n\n /**\n * Gets privacy-preserving aggregate positioning for an active perpetual. Cross and isolated legs\n * are summed within owner/subaccount/product before direction classification. Every cell requires\n * at least 20 distinct contributing owners. No identity, individual position, entry price, PnL,\n * margin, or leverage fields are returned. This operation costs five rate-limit units.\n *\n * @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or\n * `BAD_REQUEST` on invalid input, and `MARKET_NOT_FOUND` when the ticker does not resolve to a\n * perp.\n */\n async getMarketPositioning(\n params: GetNuanzeMarketPositioningParams,\n ): Promise<GetNuanzeMarketPositioningResponse> {\n const { ticker, ...query } = params;\n return mapNuanzeMarketPositioningResponse(\n await this.getJson<NuanzeServerMarketPositioningResponse>(\n `/markets/${encodeURIComponent(ticker)}/positioning`,\n query,\n ),\n );\n }\n\n /**\n * Lists open perpetual position legs for the resolved market. Results default to absolute\n * notional descending and can be ordered by signed unrealized PnL or absolute base amount in\n * either direction. Spot markets are not supported. Legs below $10 absolute notional are excluded.\n * Wallet addresses and signed exact base amounts are returned.\n *\n * @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`,\n * `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, or `BAD_REQUEST` on invalid input, and\n * `MARKET_NOT_FOUND` when the ticker does not resolve to a perp.\n */\n async getMarketPositions(\n params: GetNuanzeMarketPositionsParams,\n ): Promise<GetNuanzeMarketPositionsResponse> {\n const { ticker, ...query } = params;\n return mapNuanzeMarketPositionsResponse(\n await this.getJson<NuanzeServerMarketPositionsResponse>(\n `/markets/${encodeURIComponent(ticker)}/positions`,\n query,\n ),\n );\n }\n\n /**\n * Lists current open perpetual position legs across every market by signed unrealized PnL.\n * Descending returns the largest gainers and ascending returns the largest losers. This is a\n * latest indexed snapshot with no timeframe. Legs below $10 absolute notional are excluded.\n * Each row includes market identity and its source snapshot timestamp. Costs five rate-limit\n * units.\n *\n * @throws {NuanzeServerFailureError} With `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, or\n * `BAD_REQUEST` when the query or cursor is invalid.\n */\n async getOpenPositions(\n params: GetNuanzeOpenPositionsParams = {},\n ): Promise<GetNuanzeOpenPositionsResponse> {\n return mapNuanzeOpenPositionsResponse(\n await this.getJson<NuanzeServerOpenPositionsResponse>(\n '/positions',\n params,\n ),\n );\n }\n\n /**\n * Performs a GET against `{baseUrl}{path}` and classifies the status before returning the body.\n */\n private async getJson<T>(path: string, params?: object): Promise<T> {\n return this.requestJson<T>('GET', path, { params });\n }\n\n /**\n * Performs a POST against `{baseUrl}{path}` with a JSON body and classifies the status before\n * returning the response. Used only for the non-mutating followed-leaderboard operation.\n */\n private async postJson<T>(path: string, data: object): Promise<T> {\n return this.requestJson<T>('POST', path, { data });\n }\n\n private async requestJson<T>(\n method: 'GET' | 'POST',\n path: string,\n config: { params?: object; data?: object } = {},\n ): Promise<T> {\n const response = await this.axiosInstance.request<T>({\n method,\n url: `${this.opts.url}${path}`,\n ...config,\n });\n this.checkResponseStatus(response);\n return response.data;\n }\n\n /**\n * Validates the HTTP status before interpreting the body. Nuanze maps every domain failure onto a\n * non-2xx status carrying a failure envelope, so anything else is a transport-level error.\n */\n private checkResponseStatus(response: AxiosResponse<unknown>) {\n if (response.status >= 200 && response.status < 300) {\n return;\n }\n if (isNuanzeServerFailureResponse(response.data)) {\n throw new NuanzeServerFailureError(response.data, response.status);\n }\n throw new Error(\n `Unexpected response from Nuanze: ${response.status} ${response.statusText}. Data: ${JSON.stringify(response.data)}`,\n );\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { n as NuanzeErrorCode } from "./nuanzeErrorCodes-CWCTWh2k.cjs";
|
|
2
|
+
import { i as NuanzeServerFailureResponse } from "./serverQueryTypes-BBIFZZ36.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/types/NuanzeServerFailureError.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when the Nuanze API returns a failure envelope. Unlike the other service clients this
|
|
7
|
+
* does not extend `BaseServerFailureError`: Nuanze reports a string {@link NuanzeErrorCode} nested
|
|
8
|
+
* under `error` rather than a top-level numeric `error_code`, so there is no shared shape to inherit.
|
|
9
|
+
*/
|
|
10
|
+
declare class NuanzeServerFailureError extends Error {
|
|
11
|
+
readonly responseData: NuanzeServerFailureResponse;
|
|
12
|
+
/**
|
|
13
|
+
* Error code to branch on, comparable against {@link NUANZE_ERROR_CODES}. Codes are additive, so an
|
|
14
|
+
* unrecognized value here came from a newer API release than this client.
|
|
15
|
+
*/
|
|
16
|
+
readonly errorCode: NuanzeErrorCode;
|
|
17
|
+
/**
|
|
18
|
+
* HTTP status of the response, e.g. `404` for `MARKET_NOT_FOUND` or `429` for `RATE_LIMITED`.
|
|
19
|
+
*/
|
|
20
|
+
readonly httpStatus: number;
|
|
21
|
+
/**
|
|
22
|
+
* Correlation ID to quote when reporting the failure. Matches the response's `X-Request-Id`.
|
|
23
|
+
*/
|
|
24
|
+
readonly requestId: string;
|
|
25
|
+
constructor(responseData: NuanzeServerFailureResponse, httpStatus: number);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { NuanzeServerFailureError as t };
|
|
29
|
+
//# sourceMappingURL=NuanzeServerFailureError-B9EhXPyW.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuanzeServerFailureError-B9EhXPyW.d.cts","names":[],"sources":["../src/types/src/types/NuanzeServerFailureError.ts"],"mappings":";;;;;;AAQA;;;cAAa,wBAAA,SAAiC,KAAA;EAAA,SAkBjC,YAAA,EAAc,2BAAA;EAAA;;;;EAAA,SAbhB,SAAA,EAAW,eAAA;EAaT;;;EAAA,SARF,UAAA;EAAA;;;EAAA,SAKA,SAAA;cAGE,YAAA,EAAc,2BAAA,EACvB,UAAA;AAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { n as NuanzeErrorCode } from "./nuanzeErrorCodes-Dh6juim0.js";
|
|
2
|
+
import { i as NuanzeServerFailureResponse } from "./serverQueryTypes-e7HWmE8t.js";
|
|
3
|
+
|
|
4
|
+
//#region src/types/NuanzeServerFailureError.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when the Nuanze API returns a failure envelope. Unlike the other service clients this
|
|
7
|
+
* does not extend `BaseServerFailureError`: Nuanze reports a string {@link NuanzeErrorCode} nested
|
|
8
|
+
* under `error` rather than a top-level numeric `error_code`, so there is no shared shape to inherit.
|
|
9
|
+
*/
|
|
10
|
+
declare class NuanzeServerFailureError extends Error {
|
|
11
|
+
readonly responseData: NuanzeServerFailureResponse;
|
|
12
|
+
/**
|
|
13
|
+
* Error code to branch on, comparable against {@link NUANZE_ERROR_CODES}. Codes are additive, so an
|
|
14
|
+
* unrecognized value here came from a newer API release than this client.
|
|
15
|
+
*/
|
|
16
|
+
readonly errorCode: NuanzeErrorCode;
|
|
17
|
+
/**
|
|
18
|
+
* HTTP status of the response, e.g. `404` for `MARKET_NOT_FOUND` or `429` for `RATE_LIMITED`.
|
|
19
|
+
*/
|
|
20
|
+
readonly httpStatus: number;
|
|
21
|
+
/**
|
|
22
|
+
* Correlation ID to quote when reporting the failure. Matches the response's `X-Request-Id`.
|
|
23
|
+
*/
|
|
24
|
+
readonly requestId: string;
|
|
25
|
+
constructor(responseData: NuanzeServerFailureResponse, httpStatus: number);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { NuanzeServerFailureError as t };
|
|
29
|
+
//# sourceMappingURL=NuanzeServerFailureError-DqWaKEMA.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuanzeServerFailureError-DqWaKEMA.d.ts","names":[],"sources":["../src/types/src/types/NuanzeServerFailureError.ts"],"mappings":";;;;;;AAQA;;;cAAa,wBAAA,SAAiC,KAAA;EAAA,SAkBjC,YAAA,EAAc,2BAAA;EAAA;;;;EAAA,SAbhB,SAAA,EAAW,eAAA;EAaT;;;EAAA,SARF,UAAA;EAAA;;;EAAA,SAKA,SAAA;cAGE,YAAA,EAAc,2BAAA,EACvB,UAAA;AAAA"}
|