@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 @@
|
|
|
1
|
+
{"version":3,"file":"serverQueryTypes.js","names":[],"sources":["../../src/types/serverQueryTypes.ts"],"sourcesContent":["import type {\n NuanzeCandleInterval,\n NuanzeCoverage,\n NuanzeFlowBucket,\n NuanzeFlowTimeframe,\n NuanzeLeaderboardTimeframe,\n NuanzeMarketVenue,\n NuanzePlatformWindow,\n NuanzePnlWindow,\n NuanzeSeriesMetric,\n NuanzeSourceInterval,\n} from './clientModelTypes';\nimport { NuanzeNewsStory } from './clientModelTypes';\nimport { NuanzeErrorCode } from './nuanzeErrorCodes';\nimport {\n NuanzeServerCandle,\n NuanzeServerCollateralFlow,\n NuanzeServerCollateralFlowPoint,\n NuanzeServerFollowedLeaderboardItem,\n NuanzeServerFundingRate,\n NuanzeServerLeaderboardItem,\n NuanzeServerMarket,\n NuanzeServerMarketDetail,\n NuanzeServerMarketPosition,\n NuanzeServerMarketTrade,\n NuanzeServerOpenPosition,\n NuanzeServerPlatformDeltas,\n NuanzeServerSeriesPoint,\n NuanzeServerWalletPosition,\n NuanzeServerWalletTrade,\n} from './serverModelTypes';\n\n/**\n * Failure envelope returned with every non-2xx response.\n *\n * Structurally unrelated to `BaseServerFailureResponse`: Nuanze nests a string `code` under `error`\n * instead of carrying a top-level numeric `error_code` and `status: 'failure'`.\n */\nexport interface NuanzeServerFailureResponse {\n error: {\n code: NuanzeErrorCode;\n message: string;\n requestId: string;\n };\n}\n\n/**\n * `GET /markets` response as returned on the wire.\n */\nexport interface NuanzeServerMarketsResponse {\n markets: NuanzeServerMarket[];\n count: number;\n asOf: string;\n}\n\n/**\n * `GET /news` response as returned on the wire. Stories have no decimals.\n */\nexport interface NuanzeServerNewsResponse {\n stories: NuanzeNewsStory[];\n nextCursor: string | null;\n asOf: string;\n}\n\n/**\n * `GET /markets/{ticker}` response as returned on the wire.\n */\nexport type NuanzeServerMarketByTickerResponse = NuanzeServerMarketDetail;\n\n/**\n * `GET /funding/rates` response as returned on the wire.\n */\nexport interface NuanzeServerFundingRatesResponse {\n rates: NuanzeServerFundingRate[];\n asOf: string;\n}\n\n/**\n * `GET /leaderboard` response as returned on the wire.\n */\nexport interface NuanzeServerLeaderboardResponse {\n timeframe: NuanzeLeaderboardTimeframe;\n items: NuanzeServerLeaderboardItem[];\n limit: number;\n offset: number;\n total: number;\n asOf: string;\n}\n\n/**\n * `POST /wallets/leaderboard` response as returned on the wire.\n */\nexport interface NuanzeServerFollowedLeaderboardResponse {\n timeframe: NuanzeLeaderboardTimeframe;\n items: NuanzeServerFollowedLeaderboardItem[];\n count: number;\n asOf: string;\n}\n\n/**\n * `GET /platform/summary` response as returned on the wire.\n */\nexport interface NuanzeServerPlatformSummaryResponse {\n window: NuanzePlatformWindow;\n volume24h: string;\n trades24h: number;\n traders24h: number;\n windowVolume: string;\n windowTrades: number;\n windowTraders: number;\n deltas: NuanzeServerPlatformDeltas;\n asOf: string;\n}\n\n/**\n * `GET /wallets/{address}` response as returned on the wire.\n */\nexport interface NuanzeServerWalletSummaryResponse {\n address: string;\n subaccountName: string | null;\n subaccountCount: number;\n pnlWindow: NuanzePnlWindow;\n accountPnl: string;\n windowPnl: string;\n equity: string | null;\n cumulativeVolume: string;\n windowVolume: string;\n totalTrades: number;\n wins: number;\n losses: number;\n winRate: string | null;\n snapshotAt: string;\n coverage: NuanzeCoverage;\n asOf: string;\n}\n\n/**\n * `GET /wallets/{address}/positions` response as returned on the wire.\n */\nexport interface NuanzeServerWalletPositionsResponse {\n address: string;\n positions: NuanzeServerWalletPosition[];\n count: number;\n newestSnapshotAt: string | null;\n oldestSnapshotAt: string | null;\n asOf: string;\n}\n\n/**\n * `GET /markets/{ticker}/trades` response as returned on the wire.\n */\nexport interface NuanzeServerMarketTradesResponse {\n productId: number;\n symbol: string;\n ticker: string;\n venue: NuanzeMarketVenue;\n trades: NuanzeServerMarketTrade[];\n nextCursor: string | null;\n asOf: string;\n}\n\n/**\n * `GET /markets/{ticker}/candles` response as returned on the wire.\n */\nexport interface NuanzeServerMarketCandlesResponse {\n productId: number;\n symbol: string;\n ticker: string;\n venue: NuanzeMarketVenue;\n interval: NuanzeCandleInterval;\n candles: NuanzeServerCandle[];\n asOf: string;\n}\n\n/**\n * `GET /wallets/{address}/trades` response as returned on the wire.\n */\nexport interface NuanzeServerWalletTradesResponse {\n address: string;\n trades: NuanzeServerWalletTrade[];\n nextCursor: string | null;\n asOf: string;\n}\n\n/**\n * `GET /wallets/{address}/pnl` response as returned on the wire.\n */\nexport interface NuanzeServerWalletPnlResponse {\n address: string;\n subaccountName: string | null;\n window: NuanzePnlWindow;\n windowStart: string;\n windowEnd: string;\n openingAccountPnl: string;\n latestAccountPnl: string;\n windowPnl: string;\n openingEquity: string | null;\n latestEquity: string | null;\n volumeDelta: string;\n sourceInterval: NuanzeSourceInterval;\n latestSnapshotAt: string;\n coverage: NuanzeCoverage;\n asOf: string;\n}\n\n/**\n * `GET /wallets/{address}/pnl/series` response as returned on the wire.\n */\nexport interface NuanzeServerWalletPnlSeriesResponse {\n address: string;\n subaccountName: string | null;\n metric: NuanzeSeriesMetric;\n window: NuanzePnlWindow;\n points: NuanzeServerSeriesPoint[];\n sourceInterval: NuanzeSourceInterval;\n coverage: NuanzeCoverage;\n asOf: string;\n}\n\n/**\n * `GET /flows` response as returned on the wire.\n */\nexport interface NuanzeServerCollateralFlowsResponse {\n events: NuanzeServerCollateralFlow[];\n nextCursor: string | null;\n asOf: string;\n}\n\n/**\n * `GET /flows/summary` response as returned on the wire.\n */\nexport interface NuanzeServerCollateralFlowSummaryResponse {\n timeframe: NuanzeFlowTimeframe;\n deposited: string;\n withdrawn: string;\n net: string;\n gross: string;\n depositCount: number;\n withdrawalCount: number;\n valuedCount: number;\n unvaluedCount: number;\n priorNet: string | null;\n asOf: string;\n}\n\n/**\n * `GET /flows/series` response as returned on the wire.\n */\nexport interface NuanzeServerCollateralFlowSeriesResponse {\n timeframe: NuanzeFlowTimeframe;\n bucket: NuanzeFlowBucket;\n points: NuanzeServerCollateralFlowPoint[];\n asOf: string;\n}\n\n/**\n * `GET /markets/{ticker}/positions` response as returned on the wire.\n */\nexport interface NuanzeServerMarketPositionsResponse {\n productId: number;\n symbol: string;\n ticker: string;\n venue: NuanzeMarketVenue;\n positions: NuanzeServerMarketPosition[];\n nextCursor: string | null;\n dataUpdatedAt: string | null;\n asOf: string;\n}\n\n/**\n * `GET /positions` response as returned on the wire.\n */\nexport interface NuanzeServerOpenPositionsResponse {\n positions: NuanzeServerOpenPosition[];\n nextCursor: string | null;\n dataUpdatedAt: string | null;\n asOf: string;\n}\n\n/**\n * Checks whether a response body is a Nuanze failure envelope. The `code` is not compared against\n * {@link NUANZE_ERROR_CODES}, so a code added by a newer API release still reaches the caller.\n */\nexport function isNuanzeServerFailureResponse(\n data: unknown,\n): data is NuanzeServerFailureResponse {\n if (typeof data !== 'object' || data === null || !('error' in data)) {\n return false;\n }\n\n const { error } = data;\n return (\n typeof error === 'object' &&\n error !== null &&\n typeof (error as { code?: unknown }).code === 'string' &&\n typeof (error as { message?: unknown }).message === 'string'\n );\n}\n"],"mappings":";;;;;AA2RA,SAAgB,8BACd,MACqC;CACrC,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,EAAE,WAAW,OAC5D,OAAO;CAGT,MAAM,EAAE,UAAU;CAClB,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS,YAC9C,OAAQ,MAAgC,YAAY;AAExD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nadohq/nuanze-client",
|
|
3
|
+
"version": "0.41.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "HTTP client for the Nuanze public analytics API - markets, wallets, trades, candles, flows, positioning, and open positions",
|
|
7
|
+
"author": "Przemek Paczoski <przemek@inkfnd.com>",
|
|
8
|
+
"homepage": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": "https://github.com/nadohq/nado-typescript-sdk",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo",
|
|
17
|
+
"build": "tsdown",
|
|
18
|
+
"dev": "tsc -w",
|
|
19
|
+
"lint": "eslint --cache './**/*.{ts,tsx}'",
|
|
20
|
+
"lint:fix": "eslint --cache --fix './**/*.{ts,tsx}'",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"react-native": "./dist/index.js",
|
|
40
|
+
"main": "./dist/index.cjs",
|
|
41
|
+
"module": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@nadohq/shared": "^0.41.0",
|
|
45
|
+
"axios": "1.16.1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"bignumber.js": "11.1.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"bignumber.js": "11.1.1"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "bd534f98c5e429aafc861e1fcc4a639ffd2850a6"
|
|
54
|
+
}
|
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import {
|
|
3
|
+
mapNuanzeCollateralFlowSeriesResponse,
|
|
4
|
+
mapNuanzeCollateralFlowSummaryResponse,
|
|
5
|
+
mapNuanzeCollateralFlowsResponse,
|
|
6
|
+
mapNuanzeFollowedLeaderboardResponse,
|
|
7
|
+
mapNuanzeFundingRatesResponse,
|
|
8
|
+
mapNuanzeLeaderboardResponse,
|
|
9
|
+
mapNuanzeMarketByTickerResponse,
|
|
10
|
+
mapNuanzeMarketCandlesResponse,
|
|
11
|
+
mapNuanzeMarketPositioningResponse,
|
|
12
|
+
mapNuanzeMarketPositionsResponse,
|
|
13
|
+
mapNuanzeMarketTradesResponse,
|
|
14
|
+
mapNuanzeMarketsResponse,
|
|
15
|
+
mapNuanzeNewsResponse,
|
|
16
|
+
mapNuanzeOpenPositionsResponse,
|
|
17
|
+
mapNuanzePlatformSummaryResponse,
|
|
18
|
+
mapNuanzeWalletPnlResponse,
|
|
19
|
+
mapNuanzeWalletPnlSeriesResponse,
|
|
20
|
+
mapNuanzeWalletPositionsResponse,
|
|
21
|
+
mapNuanzeWalletSummaryResponse,
|
|
22
|
+
mapNuanzeWalletTradesResponse,
|
|
23
|
+
} from './dataMappers';
|
|
24
|
+
import {
|
|
25
|
+
GetNuanzeCollateralFlowSeriesParams,
|
|
26
|
+
GetNuanzeCollateralFlowSeriesResponse,
|
|
27
|
+
GetNuanzeCollateralFlowSummaryParams,
|
|
28
|
+
GetNuanzeCollateralFlowSummaryResponse,
|
|
29
|
+
GetNuanzeCollateralFlowsParams,
|
|
30
|
+
GetNuanzeCollateralFlowsResponse,
|
|
31
|
+
GetNuanzeFollowedLeaderboardParams,
|
|
32
|
+
GetNuanzeFollowedLeaderboardResponse,
|
|
33
|
+
GetNuanzeFundingRatesParams,
|
|
34
|
+
GetNuanzeFundingRatesResponse,
|
|
35
|
+
GetNuanzeLeaderboardParams,
|
|
36
|
+
GetNuanzeLeaderboardResponse,
|
|
37
|
+
GetNuanzeMarketByTickerParams,
|
|
38
|
+
GetNuanzeMarketByTickerResponse,
|
|
39
|
+
GetNuanzeMarketCandlesParams,
|
|
40
|
+
GetNuanzeMarketCandlesResponse,
|
|
41
|
+
GetNuanzeMarketPositioningParams,
|
|
42
|
+
GetNuanzeMarketPositioningResponse,
|
|
43
|
+
GetNuanzeMarketPositionsParams,
|
|
44
|
+
GetNuanzeMarketPositionsResponse,
|
|
45
|
+
GetNuanzeMarketTradesParams,
|
|
46
|
+
GetNuanzeMarketTradesResponse,
|
|
47
|
+
GetNuanzeMarketsParams,
|
|
48
|
+
GetNuanzeMarketsResponse,
|
|
49
|
+
GetNuanzeNewsParams,
|
|
50
|
+
GetNuanzeNewsResponse,
|
|
51
|
+
GetNuanzeOpenPositionsParams,
|
|
52
|
+
GetNuanzeOpenPositionsResponse,
|
|
53
|
+
GetNuanzePlatformSummaryParams,
|
|
54
|
+
GetNuanzePlatformSummaryResponse,
|
|
55
|
+
GetNuanzeWalletPnlParams,
|
|
56
|
+
GetNuanzeWalletPnlResponse,
|
|
57
|
+
GetNuanzeWalletPnlSeriesParams,
|
|
58
|
+
GetNuanzeWalletPnlSeriesResponse,
|
|
59
|
+
GetNuanzeWalletPositionsParams,
|
|
60
|
+
GetNuanzeWalletPositionsResponse,
|
|
61
|
+
GetNuanzeWalletSummaryParams,
|
|
62
|
+
GetNuanzeWalletSummaryResponse,
|
|
63
|
+
GetNuanzeWalletTradesParams,
|
|
64
|
+
GetNuanzeWalletTradesResponse,
|
|
65
|
+
} from './types/clientTypes';
|
|
66
|
+
import { NuanzeServerFailureError } from './types/NuanzeServerFailureError';
|
|
67
|
+
import { NuanzeServerMarketPositioningResponse } from './types/serverModelTypes';
|
|
68
|
+
import {
|
|
69
|
+
NuanzeServerCollateralFlowSeriesResponse,
|
|
70
|
+
NuanzeServerCollateralFlowSummaryResponse,
|
|
71
|
+
NuanzeServerCollateralFlowsResponse,
|
|
72
|
+
NuanzeServerFollowedLeaderboardResponse,
|
|
73
|
+
NuanzeServerFundingRatesResponse,
|
|
74
|
+
NuanzeServerLeaderboardResponse,
|
|
75
|
+
NuanzeServerMarketByTickerResponse,
|
|
76
|
+
NuanzeServerMarketCandlesResponse,
|
|
77
|
+
NuanzeServerMarketPositionsResponse,
|
|
78
|
+
NuanzeServerMarketTradesResponse,
|
|
79
|
+
NuanzeServerMarketsResponse,
|
|
80
|
+
NuanzeServerNewsResponse,
|
|
81
|
+
NuanzeServerOpenPositionsResponse,
|
|
82
|
+
NuanzeServerPlatformSummaryResponse,
|
|
83
|
+
NuanzeServerWalletPnlResponse,
|
|
84
|
+
NuanzeServerWalletPnlSeriesResponse,
|
|
85
|
+
NuanzeServerWalletPositionsResponse,
|
|
86
|
+
NuanzeServerWalletSummaryResponse,
|
|
87
|
+
NuanzeServerWalletTradesResponse,
|
|
88
|
+
isNuanzeServerFailureResponse,
|
|
89
|
+
} from './types/serverQueryTypes';
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Options for constructing a {@link NuanzeClient}.
|
|
93
|
+
*/
|
|
94
|
+
export interface NuanzeClientOpts {
|
|
95
|
+
/**
|
|
96
|
+
* Base URL of the Nuanze API, including the version segment, e.g. {@link NUANZE_CLIENT_ENDPOINTS}.
|
|
97
|
+
*/
|
|
98
|
+
url: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Client for the Nuanze public analytics API: markets, wallets, trades, candles, collateral flows,
|
|
103
|
+
* and positioning.
|
|
104
|
+
*
|
|
105
|
+
* Read-only and credential-free, so unlike the other service clients it takes no wallet client or
|
|
106
|
+
* linked signer. It also sends no `x-nado-client-type` header: Nuanze is a public API that does not
|
|
107
|
+
* attribute traffic per client, and its `Access-Control-Allow-Headers` does not list the header, so
|
|
108
|
+
* sending it would fail CORS preflight in the browser. Most operations are GET;
|
|
109
|
+
* {@link NuanzeClient.getFollowedLeaderboard} is a non-mutating POST whose body carries a followed
|
|
110
|
+
* set larger than a query string can reliably hold. The API meters a weighted token bucket per
|
|
111
|
+
* client IP and reports its state in the `RateLimit-Limit`, `RateLimit-Remaining`, and
|
|
112
|
+
* `RateLimit-Reset` response headers; add an interceptor on {@link axiosInstance} to observe them.
|
|
113
|
+
*/
|
|
114
|
+
export class NuanzeClient {
|
|
115
|
+
readonly opts: NuanzeClientOpts;
|
|
116
|
+
readonly axiosInstance: AxiosInstance;
|
|
117
|
+
|
|
118
|
+
constructor(opts: NuanzeClientOpts) {
|
|
119
|
+
this.opts = opts;
|
|
120
|
+
this.axiosInstance = axios.create({
|
|
121
|
+
// Nuanze is public and answers every origin with `Access-Control-Allow-Origin: *`, which
|
|
122
|
+
// browsers reject for credentialed requests.
|
|
123
|
+
withCredentials: false,
|
|
124
|
+
// We have custom logic to validate response status and create an appropriate error
|
|
125
|
+
validateStatus: () => true,
|
|
126
|
+
// Repeatable `productId` must serialize as `productId=1&productId=2` (OpenAPI explode).
|
|
127
|
+
paramsSerializer: { indexes: null },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Lists published editorial stories, sorted by `publishedAt` descending then `id` descending.
|
|
133
|
+
* The opaque cursor is exclusive and bound to normalized filters. Raw article ingestion, scoring,
|
|
134
|
+
* queue, and newsdesk fields are excluded.
|
|
135
|
+
*
|
|
136
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST`, `INVALID_CURSOR`, or
|
|
137
|
+
* `CURSOR_FILTER_MISMATCH` when filters or the cursor are invalid.
|
|
138
|
+
*/
|
|
139
|
+
async getNews(
|
|
140
|
+
params: GetNuanzeNewsParams = {},
|
|
141
|
+
): Promise<GetNuanzeNewsResponse> {
|
|
142
|
+
return mapNuanzeNewsResponse(
|
|
143
|
+
await this.getJson<NuanzeServerNewsResponse>('/news', params),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Gets the active market universe, ordered by `productId` ascending. Never truncated, so `count`
|
|
149
|
+
* always equals the length of `markets`. Market metadata refreshes about every five minutes and
|
|
150
|
+
* prices about every minute.
|
|
151
|
+
*
|
|
152
|
+
* @throws {NuanzeServerFailureError} With error code `BAD_REQUEST` if a filter value is not a
|
|
153
|
+
* documented venue or tradability state.
|
|
154
|
+
*/
|
|
155
|
+
async getMarkets(
|
|
156
|
+
params: GetNuanzeMarketsParams = {},
|
|
157
|
+
): Promise<GetNuanzeMarketsResponse> {
|
|
158
|
+
return mapNuanzeMarketsResponse(
|
|
159
|
+
await this.getJson<NuanzeServerMarketsResponse>('/markets', params),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Resolves a market by ticker. Lookup is case-insensitive and accepts canonical tickers or
|
|
165
|
+
* legacy source symbols. An explicit unavailable venue returns `MARKET_NOT_FOUND`. With no
|
|
166
|
+
* venue, `strictVenue=true` returns `AMBIGUOUS_MARKET` for multi-venue assets; otherwise the
|
|
167
|
+
* primary venue is used.
|
|
168
|
+
*
|
|
169
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or
|
|
170
|
+
* `BAD_REQUEST` on invalid selectors, and `MARKET_NOT_FOUND` when the ticker does not resolve.
|
|
171
|
+
*/
|
|
172
|
+
async getMarketByTicker(
|
|
173
|
+
params: GetNuanzeMarketByTickerParams,
|
|
174
|
+
): Promise<GetNuanzeMarketByTickerResponse> {
|
|
175
|
+
const { ticker, ...query } = params;
|
|
176
|
+
return mapNuanzeMarketByTickerResponse(
|
|
177
|
+
await this.getJson<NuanzeServerMarketByTickerResponse>(
|
|
178
|
+
`/markets/${encodeURIComponent(ticker)}`,
|
|
179
|
+
query,
|
|
180
|
+
),
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Lists the latest funding observation per active perpetual market, refreshed about every five
|
|
186
|
+
* minutes.
|
|
187
|
+
*
|
|
188
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.
|
|
189
|
+
*/
|
|
190
|
+
async getFundingRates(
|
|
191
|
+
params: GetNuanzeFundingRatesParams = {},
|
|
192
|
+
): Promise<GetNuanzeFundingRatesResponse> {
|
|
193
|
+
return mapNuanzeFundingRatesResponse(
|
|
194
|
+
await this.getJson<NuanzeServerFundingRatesResponse>(
|
|
195
|
+
'/funding/rates',
|
|
196
|
+
params,
|
|
197
|
+
),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Gets the account PnL leaderboard. Equity-basis account PnL includes realized and unrealized
|
|
203
|
+
* movement plus funding and is not realized PnL. All-time analytics cost five rate-limit units.
|
|
204
|
+
*
|
|
205
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.
|
|
206
|
+
*/
|
|
207
|
+
async getLeaderboard(
|
|
208
|
+
params: GetNuanzeLeaderboardParams = {},
|
|
209
|
+
): Promise<GetNuanzeLeaderboardResponse> {
|
|
210
|
+
return mapNuanzeLeaderboardResponse(
|
|
211
|
+
await this.getJson<NuanzeServerLeaderboardResponse>(
|
|
212
|
+
'/leaderboard',
|
|
213
|
+
params,
|
|
214
|
+
),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Gets platform activity summary from five-minute aggregates.
|
|
220
|
+
*
|
|
221
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if the window is not a documented value.
|
|
222
|
+
*/
|
|
223
|
+
async getPlatformSummary(
|
|
224
|
+
params: GetNuanzePlatformSummaryParams = {},
|
|
225
|
+
): Promise<GetNuanzePlatformSummaryResponse> {
|
|
226
|
+
return mapNuanzePlatformSummaryResponse(
|
|
227
|
+
await this.getJson<NuanzeServerPlatformSummaryResponse>(
|
|
228
|
+
'/platform/summary',
|
|
229
|
+
params,
|
|
230
|
+
),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Gets leaderboard stats for a set of followed subaccounts. POST rather than GET so the body can
|
|
236
|
+
* carry up to 300 `subaccountHex` values. The response preserves request order. Subaccounts with
|
|
237
|
+
* no data in the window are backfilled with `pnl: null`, `globalRank: null`, zero counts, and an
|
|
238
|
+
* empty `productIds`. Costs five rate-limit units. The response is not cached.
|
|
239
|
+
*
|
|
240
|
+
* @throws {NuanzeServerFailureError} With `INVALID_SUBACCOUNT` if a hex is not 32-byte
|
|
241
|
+
* 0x-prefixed, and `BAD_REQUEST` if the set is empty, exceeds 300, or `timeframe` is not a
|
|
242
|
+
* documented value.
|
|
243
|
+
*/
|
|
244
|
+
async getFollowedLeaderboard(
|
|
245
|
+
params: GetNuanzeFollowedLeaderboardParams,
|
|
246
|
+
): Promise<GetNuanzeFollowedLeaderboardResponse> {
|
|
247
|
+
return mapNuanzeFollowedLeaderboardResponse(
|
|
248
|
+
await this.postJson<NuanzeServerFollowedLeaderboardResponse>(
|
|
249
|
+
'/wallets/leaderboard',
|
|
250
|
+
params,
|
|
251
|
+
),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Gets replica-backed wallet analytics. Without `subaccountName`, latest cumulative values are
|
|
257
|
+
* selected per known subaccount and then summed. The response is a snapshot and does not claim
|
|
258
|
+
* live health, withdrawable collateral, open-order, or signer state.
|
|
259
|
+
*
|
|
260
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
261
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
262
|
+
*/
|
|
263
|
+
async getWalletSummary(
|
|
264
|
+
params: GetNuanzeWalletSummaryParams,
|
|
265
|
+
): Promise<GetNuanzeWalletSummaryResponse> {
|
|
266
|
+
const { address, ...query } = params;
|
|
267
|
+
return mapNuanzeWalletSummaryResponse(
|
|
268
|
+
await this.getJson<NuanzeServerWalletSummaryResponse>(
|
|
269
|
+
`/wallets/${encodeURIComponent(address)}`,
|
|
270
|
+
query,
|
|
271
|
+
),
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Lists at most 500 current replica position rows across all known subaccounts by default. Rows
|
|
277
|
+
* remain per subaccount. Spot rows are excluded unless `includeSpot=true`. This is not an
|
|
278
|
+
* execution-grade live feed.
|
|
279
|
+
*
|
|
280
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
281
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
282
|
+
*/
|
|
283
|
+
async getWalletPositions(
|
|
284
|
+
params: GetNuanzeWalletPositionsParams,
|
|
285
|
+
): Promise<GetNuanzeWalletPositionsResponse> {
|
|
286
|
+
const { address, ...query } = params;
|
|
287
|
+
return mapNuanzeWalletPositionsResponse(
|
|
288
|
+
await this.getJson<NuanzeServerWalletPositionsResponse>(
|
|
289
|
+
`/wallets/${encodeURIComponent(address)}/positions`,
|
|
290
|
+
query,
|
|
291
|
+
),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Lists market trades: one taker-side row per match, sorted by `matchedAt` then `id` descending.
|
|
297
|
+
* The exclusive cursor is bound to operation and normalized filters. `from` is inclusive and
|
|
298
|
+
* `to` exclusive. Wallet identity is absent.
|
|
299
|
+
*
|
|
300
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`,
|
|
301
|
+
* `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, `RANGE_TOO_LARGE`, or `BAD_REQUEST` on invalid
|
|
302
|
+
* input, and `MARKET_NOT_FOUND` when the ticker does not resolve.
|
|
303
|
+
*/
|
|
304
|
+
async getMarketTrades(
|
|
305
|
+
params: GetNuanzeMarketTradesParams,
|
|
306
|
+
): Promise<GetNuanzeMarketTradesResponse> {
|
|
307
|
+
const { ticker, ...query } = params;
|
|
308
|
+
return mapNuanzeMarketTradesResponse(
|
|
309
|
+
await this.getJson<NuanzeServerMarketTradesResponse>(
|
|
310
|
+
`/markets/${encodeURIComponent(ticker)}/trades`,
|
|
311
|
+
query,
|
|
312
|
+
),
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Lists market candles. Source storage is 1h; 4h and 1d are UTC-aligned rollups and missing bars
|
|
318
|
+
* are not interpolated. The newest `limit` matching bars are selected and returned
|
|
319
|
+
* oldest-to-newest, at most 750, with no pagination. A current bucket has `complete=false`.
|
|
320
|
+
*
|
|
321
|
+
* @throws {NuanzeServerFailureError} With `UNSUPPORTED_INTERVAL`, `RANGE_TOO_LARGE`,
|
|
322
|
+
* `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or `BAD_REQUEST` on invalid input, and
|
|
323
|
+
* `MARKET_NOT_FOUND` when the ticker does not resolve.
|
|
324
|
+
*/
|
|
325
|
+
async getMarketCandles(
|
|
326
|
+
params: GetNuanzeMarketCandlesParams,
|
|
327
|
+
): Promise<GetNuanzeMarketCandlesResponse> {
|
|
328
|
+
const { ticker, ...query } = params;
|
|
329
|
+
return mapNuanzeMarketCandlesResponse(
|
|
330
|
+
await this.getJson<NuanzeServerMarketCandlesResponse>(
|
|
331
|
+
`/markets/${encodeURIComponent(ticker)}/candles`,
|
|
332
|
+
query,
|
|
333
|
+
),
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Lists wallet-owned maker and taker execution rows, sorted by `matchedAt` then `id` descending.
|
|
339
|
+
* The cursor is exclusive and filter-bound. `from` is inclusive and `to` exclusive.
|
|
340
|
+
*
|
|
341
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS`, `INVALID_CURSOR`,
|
|
342
|
+
* `CURSOR_FILTER_MISMATCH`, `RANGE_TOO_LARGE`, or `BAD_REQUEST` on invalid input, and
|
|
343
|
+
* `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
344
|
+
*/
|
|
345
|
+
async getWalletTrades(
|
|
346
|
+
params: GetNuanzeWalletTradesParams,
|
|
347
|
+
): Promise<GetNuanzeWalletTradesResponse> {
|
|
348
|
+
const { address, ...query } = params;
|
|
349
|
+
return mapNuanzeWalletTradesResponse(
|
|
350
|
+
await this.getJson<NuanzeServerWalletTradesResponse>(
|
|
351
|
+
`/wallets/${encodeURIComponent(address)}/trades`,
|
|
352
|
+
query,
|
|
353
|
+
),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Gets wallet account PnL. 24h is rolling and uses hourly snapshots with a daily fallback
|
|
359
|
+
* baseline. Longer windows use daily snapshots; `all` starts at earliest coverage. PnL includes
|
|
360
|
+
* realized and unrealized movement plus funding.
|
|
361
|
+
*
|
|
362
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
363
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
364
|
+
*/
|
|
365
|
+
async getWalletPnl(
|
|
366
|
+
params: GetNuanzeWalletPnlParams,
|
|
367
|
+
): Promise<GetNuanzeWalletPnlResponse> {
|
|
368
|
+
const { address, ...query } = params;
|
|
369
|
+
return mapNuanzeWalletPnlResponse(
|
|
370
|
+
await this.getJson<NuanzeServerWalletPnlResponse>(
|
|
371
|
+
`/wallets/${encodeURIComponent(address)}/pnl`,
|
|
372
|
+
query,
|
|
373
|
+
),
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Gets a wallet account series of at most 1,000 deterministically sampled points ordered by
|
|
379
|
+
* timestamp. Series contain a boundary anchor and a carried-forward request-time tip; synthetic
|
|
380
|
+
* points are identified. Latest buckets may be provisional.
|
|
381
|
+
*
|
|
382
|
+
* @throws {NuanzeServerFailureError} With `INVALID_ADDRESS` or `BAD_REQUEST` on invalid input,
|
|
383
|
+
* and `WALLET_NOT_FOUND` when the address has no wallet data.
|
|
384
|
+
*/
|
|
385
|
+
async getWalletPnlSeries(
|
|
386
|
+
params: GetNuanzeWalletPnlSeriesParams,
|
|
387
|
+
): Promise<GetNuanzeWalletPnlSeriesResponse> {
|
|
388
|
+
const { address, ...query } = params;
|
|
389
|
+
return mapNuanzeWalletPnlSeriesResponse(
|
|
390
|
+
await this.getJson<NuanzeServerWalletPnlSeriesResponse>(
|
|
391
|
+
`/wallets/${encodeURIComponent(address)}/pnl/series`,
|
|
392
|
+
query,
|
|
393
|
+
),
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Lists public collateral events, sorted by timestamp then `id` descending. Repeated `productId`
|
|
399
|
+
* uses OR semantics. `minUsd` excludes unvalued events; without it unvalued events remain.
|
|
400
|
+
*
|
|
401
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST`, `INVALID_CURSOR`, or
|
|
402
|
+
* `CURSOR_FILTER_MISMATCH` when filters or the cursor are invalid.
|
|
403
|
+
*/
|
|
404
|
+
async getCollateralFlows(
|
|
405
|
+
params: GetNuanzeCollateralFlowsParams = {},
|
|
406
|
+
): Promise<GetNuanzeCollateralFlowsResponse> {
|
|
407
|
+
return mapNuanzeCollateralFlowsResponse(
|
|
408
|
+
await this.getJson<NuanzeServerCollateralFlowsResponse>('/flows', params),
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Gets collateral flow aggregates: deposited, withdrawn, net, and gross, with valuation coverage
|
|
414
|
+
* and a prior equal-window comparison. `all` has no prior window.
|
|
415
|
+
*
|
|
416
|
+
* @throws {NuanzeServerFailureError} With `BAD_REQUEST` if a filter value is invalid.
|
|
417
|
+
*/
|
|
418
|
+
async getCollateralFlowSummary(
|
|
419
|
+
params: GetNuanzeCollateralFlowSummaryParams = {},
|
|
420
|
+
): Promise<GetNuanzeCollateralFlowSummaryResponse> {
|
|
421
|
+
return mapNuanzeCollateralFlowSummaryResponse(
|
|
422
|
+
await this.getJson<NuanzeServerCollateralFlowSummaryResponse>(
|
|
423
|
+
'/flows/summary',
|
|
424
|
+
params,
|
|
425
|
+
),
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Gets collateral flow series of at most 1,000 UTC buckets. Allowed timeframe/bucket pairs are
|
|
431
|
+
* 24h/hour, 7d/hour or day (default hour), 30d/day, and all/day.
|
|
432
|
+
*
|
|
433
|
+
* @throws {NuanzeServerFailureError} With `UNSUPPORTED_BUCKET` or `BAD_REQUEST` when the pair or
|
|
434
|
+
* filters are invalid.
|
|
435
|
+
*/
|
|
436
|
+
async getCollateralFlowSeries(
|
|
437
|
+
params: GetNuanzeCollateralFlowSeriesParams = {},
|
|
438
|
+
): Promise<GetNuanzeCollateralFlowSeriesResponse> {
|
|
439
|
+
return mapNuanzeCollateralFlowSeriesResponse(
|
|
440
|
+
await this.getJson<NuanzeServerCollateralFlowSeriesResponse>(
|
|
441
|
+
'/flows/series',
|
|
442
|
+
params,
|
|
443
|
+
),
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Gets privacy-preserving aggregate positioning for an active perpetual. Cross and isolated legs
|
|
449
|
+
* are summed within owner/subaccount/product before direction classification. Every cell requires
|
|
450
|
+
* at least 20 distinct contributing owners. No identity, individual position, entry price, PnL,
|
|
451
|
+
* margin, or leverage fields are returned. This operation costs five rate-limit units.
|
|
452
|
+
*
|
|
453
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`, or
|
|
454
|
+
* `BAD_REQUEST` on invalid input, and `MARKET_NOT_FOUND` when the ticker does not resolve to a
|
|
455
|
+
* perp.
|
|
456
|
+
*/
|
|
457
|
+
async getMarketPositioning(
|
|
458
|
+
params: GetNuanzeMarketPositioningParams,
|
|
459
|
+
): Promise<GetNuanzeMarketPositioningResponse> {
|
|
460
|
+
const { ticker, ...query } = params;
|
|
461
|
+
return mapNuanzeMarketPositioningResponse(
|
|
462
|
+
await this.getJson<NuanzeServerMarketPositioningResponse>(
|
|
463
|
+
`/markets/${encodeURIComponent(ticker)}/positioning`,
|
|
464
|
+
query,
|
|
465
|
+
),
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Lists open perpetual position legs for the resolved market. Results default to absolute
|
|
471
|
+
* notional descending and can be ordered by signed unrealized PnL or absolute base amount in
|
|
472
|
+
* either direction. Spot markets are not supported. Legs below $10 absolute notional are excluded.
|
|
473
|
+
* Wallet addresses and signed exact base amounts are returned.
|
|
474
|
+
*
|
|
475
|
+
* @throws {NuanzeServerFailureError} With `AMBIGUOUS_MARKET`, `MARKET_SELECTOR_MISMATCH`,
|
|
476
|
+
* `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, or `BAD_REQUEST` on invalid input, and
|
|
477
|
+
* `MARKET_NOT_FOUND` when the ticker does not resolve to a perp.
|
|
478
|
+
*/
|
|
479
|
+
async getMarketPositions(
|
|
480
|
+
params: GetNuanzeMarketPositionsParams,
|
|
481
|
+
): Promise<GetNuanzeMarketPositionsResponse> {
|
|
482
|
+
const { ticker, ...query } = params;
|
|
483
|
+
return mapNuanzeMarketPositionsResponse(
|
|
484
|
+
await this.getJson<NuanzeServerMarketPositionsResponse>(
|
|
485
|
+
`/markets/${encodeURIComponent(ticker)}/positions`,
|
|
486
|
+
query,
|
|
487
|
+
),
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Lists current open perpetual position legs across every market by signed unrealized PnL.
|
|
493
|
+
* Descending returns the largest gainers and ascending returns the largest losers. This is a
|
|
494
|
+
* latest indexed snapshot with no timeframe. Legs below $10 absolute notional are excluded.
|
|
495
|
+
* Each row includes market identity and its source snapshot timestamp. Costs five rate-limit
|
|
496
|
+
* units.
|
|
497
|
+
*
|
|
498
|
+
* @throws {NuanzeServerFailureError} With `INVALID_CURSOR`, `CURSOR_FILTER_MISMATCH`, or
|
|
499
|
+
* `BAD_REQUEST` when the query or cursor is invalid.
|
|
500
|
+
*/
|
|
501
|
+
async getOpenPositions(
|
|
502
|
+
params: GetNuanzeOpenPositionsParams = {},
|
|
503
|
+
): Promise<GetNuanzeOpenPositionsResponse> {
|
|
504
|
+
return mapNuanzeOpenPositionsResponse(
|
|
505
|
+
await this.getJson<NuanzeServerOpenPositionsResponse>(
|
|
506
|
+
'/positions',
|
|
507
|
+
params,
|
|
508
|
+
),
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Performs a GET against `{baseUrl}{path}` and classifies the status before returning the body.
|
|
514
|
+
*/
|
|
515
|
+
private async getJson<T>(path: string, params?: object): Promise<T> {
|
|
516
|
+
return this.requestJson<T>('GET', path, { params });
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Performs a POST against `{baseUrl}{path}` with a JSON body and classifies the status before
|
|
521
|
+
* returning the response. Used only for the non-mutating followed-leaderboard operation.
|
|
522
|
+
*/
|
|
523
|
+
private async postJson<T>(path: string, data: object): Promise<T> {
|
|
524
|
+
return this.requestJson<T>('POST', path, { data });
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
private async requestJson<T>(
|
|
528
|
+
method: 'GET' | 'POST',
|
|
529
|
+
path: string,
|
|
530
|
+
config: { params?: object; data?: object } = {},
|
|
531
|
+
): Promise<T> {
|
|
532
|
+
const response = await this.axiosInstance.request<T>({
|
|
533
|
+
method,
|
|
534
|
+
url: `${this.opts.url}${path}`,
|
|
535
|
+
...config,
|
|
536
|
+
});
|
|
537
|
+
this.checkResponseStatus(response);
|
|
538
|
+
return response.data;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Validates the HTTP status before interpreting the body. Nuanze maps every domain failure onto a
|
|
543
|
+
* non-2xx status carrying a failure envelope, so anything else is a transport-level error.
|
|
544
|
+
*/
|
|
545
|
+
private checkResponseStatus(response: AxiosResponse<unknown>) {
|
|
546
|
+
if (response.status >= 200 && response.status < 300) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (isNuanzeServerFailureResponse(response.data)) {
|
|
550
|
+
throw new NuanzeServerFailureError(response.data, response.status);
|
|
551
|
+
}
|
|
552
|
+
throw new Error(
|
|
553
|
+
`Unexpected response from Nuanze: ${response.status} ${response.statusText}. Data: ${JSON.stringify(response.data)}`,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
}
|