@n1xyz/nord-ts 0.1.12 → 0.3.1

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,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetricPeriod = void 0;
4
+ exports.aggregateMetrics = aggregateMetrics;
5
+ exports.getCurrentTps = getCurrentTps;
6
+ exports.getPeakTps = getPeakTps;
7
+ exports.getMedianLatency = getMedianLatency;
8
+ exports.getTotalTransactions = getTotalTransactions;
9
+ exports.queryPrometheus = queryPrometheus;
10
+ const types_1 = require("../../types");
11
+ const utils_1 = require("../../utils");
12
+ const NordError_1 = require("../utils/NordError");
13
+ /**
14
+ * Time periods for metrics queries
15
+ */
16
+ var MetricPeriod;
17
+ (function (MetricPeriod) {
18
+ MetricPeriod["ONE_MINUTE"] = "1m";
19
+ MetricPeriod["FIVE_MINUTES"] = "5m";
20
+ MetricPeriod["FIFTEEN_MINUTES"] = "15m";
21
+ MetricPeriod["ONE_HOUR"] = "1h";
22
+ MetricPeriod["FOUR_HOURS"] = "4h";
23
+ MetricPeriod["ONE_DAY"] = "24h";
24
+ MetricPeriod["ONE_WEEK"] = "7d";
25
+ })(MetricPeriod || (exports.MetricPeriod = MetricPeriod = {}));
26
+ /**
27
+ * Fetch aggregate metrics from the Nord API
28
+ *
29
+ * @param webServerUrl - Base URL for the Nord web server
30
+ * @param txPeakTpsPeriod - Period for peak TPS calculation
31
+ * @param txPeakTpsPeriodUnit - Unit for peak TPS period
32
+ * @returns Aggregate metrics
33
+ * @throws {NordError} If the request fails
34
+ */
35
+ async function aggregateMetrics(webServerUrl, txPeakTpsPeriod = 1, txPeakTpsPeriodUnit = types_1.PeakTpsPeriodUnit.Day) {
36
+ try {
37
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/metrics?tx_peak_tps_period=${txPeakTpsPeriod}&tx_peak_tps_period_unit=${txPeakTpsPeriodUnit}`);
38
+ // Get the raw text response (Prometheus format)
39
+ const text = await response.text();
40
+ // Parse the Prometheus-formatted metrics text into an AggregateMetrics object
41
+ const metrics = {
42
+ blocks_total: 0,
43
+ tx_total: extractMetricValue(text, "nord_requests_ok_count"),
44
+ tx_tps: calculateTps(text),
45
+ tx_tps_peak: calculatePeakTps(text),
46
+ request_latency_average: extractLatency(text),
47
+ };
48
+ return metrics;
49
+ }
50
+ catch (error) {
51
+ throw new NordError_1.NordError("Failed to fetch aggregate metrics", { cause: error });
52
+ }
53
+ }
54
+ /**
55
+ * Extract a metric value from Prometheus-formatted text
56
+ *
57
+ * @param text - Prometheus-formatted metrics text
58
+ * @param metricName - Name of the metric to extract
59
+ * @returns The metric value as a number, or 0 if not found
60
+ */
61
+ function extractMetricValue(text, metricName) {
62
+ const regex = new RegExp(`^${metricName}\\s+([\\d.]+)`, "m");
63
+ const match = text.match(regex);
64
+ return match ? parseFloat(match[1]) : 0;
65
+ }
66
+ /**
67
+ * Calculate TPS from Prometheus metrics
68
+ *
69
+ * @param text - Prometheus-formatted metrics text
70
+ * @returns Calculated TPS value
71
+ */
72
+ function calculateTps(text) {
73
+ // Use the request count and latency to estimate TPS
74
+ const requestCount = extractMetricValue(text, "nord_requests_ok_count");
75
+ const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
76
+ const latencyCount = extractSummaryValue(text, "nord_requests_ok_latency_count");
77
+ if (latencySum > 0 && latencyCount > 0) {
78
+ // Average latency in seconds
79
+ const avgLatency = latencySum / latencyCount;
80
+ // If we have valid latency data, estimate TPS as requests per second
81
+ return avgLatency > 0 ? requestCount / (latencyCount * avgLatency) : 0;
82
+ }
83
+ // Fallback: just return a small fraction of the total request count
84
+ return requestCount > 0 ? requestCount / 100 : 0;
85
+ }
86
+ /**
87
+ * Calculate peak TPS from Prometheus metrics
88
+ *
89
+ * @param text - Prometheus-formatted metrics text
90
+ * @returns Calculated peak TPS value
91
+ */
92
+ function calculatePeakTps(text) {
93
+ // For peak TPS, we'll use a simple heuristic: 2x the current TPS estimate
94
+ // TODO: fix this
95
+ return calculateTps(text) * 2;
96
+ }
97
+ /**
98
+ * Extract latency from Prometheus metrics
99
+ *
100
+ * @param text - Prometheus-formatted metrics text
101
+ * @returns Average latency in seconds
102
+ */
103
+ function extractLatency(text) {
104
+ // TODO: fix - using average for latency is kinda wack. ok to merge for now but should change.
105
+ const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
106
+ const latencyCount = extractSummaryValue(text, "nord_requests_ok_latency_count");
107
+ return latencyCount > 0 ? latencySum / latencyCount : 0;
108
+ }
109
+ /**
110
+ * Extract a summary value from Prometheus-formatted text
111
+ *
112
+ * @param text - Prometheus-formatted metrics text
113
+ * @param metricName - Name of the metric to extract
114
+ * @returns The metric value as a number, or 0 if not found
115
+ */
116
+ function extractSummaryValue(text, metricName) {
117
+ const regex = new RegExp(`^${metricName}\\s+([\\d.]+)`, "m");
118
+ const match = text.match(regex);
119
+ return match ? parseFloat(match[1]) : 0;
120
+ }
121
+ /**
122
+ * Get current transactions per second
123
+ *
124
+ * @param webServerUrl - Base URL for the Nord web server
125
+ * @param period - Time period for the query
126
+ * @returns Current TPS value
127
+ * @throws {NordError} If the request fails
128
+ */
129
+ async function getCurrentTps(webServerUrl, period = "1m") {
130
+ try {
131
+ // nord_tx_count doesn't exist in the metrics, use nord_requests_ok_count instead
132
+ return await queryPrometheus(webServerUrl, `sum(rate(nord_requests_ok_count[${period}]))`);
133
+ }
134
+ catch (error) {
135
+ throw new NordError_1.NordError(`Failed to get current TPS for period ${period}`, {
136
+ cause: error,
137
+ });
138
+ }
139
+ }
140
+ /**
141
+ * Get peak transactions per second
142
+ *
143
+ * @param webServerUrl - Base URL for the Nord web server
144
+ * @param period - Time period for the query
145
+ * @returns Peak TPS value
146
+ * @throws {NordError} If the request fails
147
+ */
148
+ async function getPeakTps(webServerUrl, period = "24h") {
149
+ try {
150
+ // nord_tx_count doesn't exist in the metrics, use nord_requests_ok_count instead
151
+ return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_requests_ok_count[1m]))[${period}:])`);
152
+ }
153
+ catch (error) {
154
+ throw new NordError_1.NordError(`Failed to get peak TPS for period ${period}`, {
155
+ cause: error,
156
+ });
157
+ }
158
+ }
159
+ /**
160
+ * Get median transaction latency
161
+ *
162
+ * @param webServerUrl - Base URL for the Nord web server
163
+ * @param period - Time period for the query
164
+ * @returns Median latency in milliseconds
165
+ * @throws {NordError} If the request fails
166
+ */
167
+ async function getMedianLatency(webServerUrl, period = "1m") {
168
+ try {
169
+ // nord_tx_latency_ms doesn't exist, use nord_requests_ok_latency instead
170
+ // which contains the latency data in the summary metric
171
+ return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_requests_ok_latency[${period}]) * 1000`);
172
+ }
173
+ catch (error) {
174
+ throw new NordError_1.NordError(`Failed to get median latency for period ${period}`, {
175
+ cause: error,
176
+ });
177
+ }
178
+ }
179
+ /**
180
+ * Get total transaction count
181
+ *
182
+ * @param webServerUrl - Base URL for the Nord web server
183
+ * @returns Total transaction count
184
+ * @throws {NordError} If the request fails
185
+ */
186
+ async function getTotalTransactions(webServerUrl) {
187
+ try {
188
+ // nord_tx_count doesn't exist, use nord_requests_ok_count instead
189
+ return await queryPrometheus(webServerUrl, "sum(nord_requests_ok_count)");
190
+ }
191
+ catch (error) {
192
+ throw new NordError_1.NordError("Failed to get total transactions", { cause: error });
193
+ }
194
+ }
195
+ /**
196
+ * Query Prometheus metrics
197
+ *
198
+ * @param webServerUrl - Base URL for the Nord web server
199
+ * @param params - Prometheus query parameters
200
+ * @returns Query result as a number
201
+ * @throws {NordError} If the request fails
202
+ */
203
+ async function queryPrometheus(webServerUrl, params) {
204
+ try {
205
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/prometheus?query=${encodeURIComponent(params)}`);
206
+ // Handle raw text response
207
+ const text = await response.text();
208
+ try {
209
+ // Try to parse as JSON first
210
+ const data = JSON.parse(text);
211
+ return data.data.result[0]?.value[1] || 0;
212
+ }
213
+ catch (error) {
214
+ console.log("Prometheus query failed:", error);
215
+ // Try to find a number in the response
216
+ const numberMatch = text.match(/[\d.]+/);
217
+ if (numberMatch) {
218
+ return parseFloat(numberMatch[0]);
219
+ }
220
+ // Return 0 if no number is found
221
+ return 0;
222
+ }
223
+ }
224
+ catch (error) {
225
+ throw new NordError_1.NordError(`Failed to query Prometheus: ${params}`, {
226
+ cause: error,
227
+ });
228
+ }
229
+ }
@@ -0,0 +1,7 @@
1
+ import { components } from "../../gen/openapi";
2
+ type AccountTriggerInfo = components["schemas"]["AccountTriggerInfo"];
3
+ type TriggerHistoryPage = components["schemas"]["PageResult_for_uint64_and_HistoryTriggerInfo"];
4
+ type HistoryTriggerQuery = components["schemas"]["AccountTriggersQuery"];
5
+ export type { AccountTriggerInfo, TriggerHistoryPage, HistoryTriggerQuery };
6
+ export declare function fetchAccountTriggers(serverUrl: string, accountId: number): Promise<AccountTriggerInfo[]>;
7
+ export declare function fetchAccountTriggerHistory(serverUrl: string, accountId: number, options: HistoryTriggerQuery): Promise<TriggerHistoryPage>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchAccountTriggers = fetchAccountTriggers;
7
+ exports.fetchAccountTriggerHistory = fetchAccountTriggerHistory;
8
+ const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
+ async function fetchAccountTriggers(serverUrl, accountId) {
10
+ const client = (0, openapi_fetch_1.default)({ baseUrl: serverUrl });
11
+ const response = await client.GET("/account/{account_id}/triggers", {
12
+ params: {
13
+ path: { account_id: accountId },
14
+ },
15
+ });
16
+ if (response.data === undefined) {
17
+ throw new Error(`Failed to fetch triggers for account ${accountId}: HTTP ${response.response.status}`);
18
+ }
19
+ return response.data ?? [];
20
+ }
21
+ async function fetchAccountTriggerHistory(serverUrl, accountId, options) {
22
+ const client = (0, openapi_fetch_1.default)({ baseUrl: serverUrl });
23
+ const response = await client.GET("/account/{account_id}/triggers/history", {
24
+ params: {
25
+ path: { account_id: accountId },
26
+ query: {
27
+ since: options.since,
28
+ until: options.until,
29
+ pageSize: options.pageSize,
30
+ startInclusive: options.startInclusive,
31
+ },
32
+ },
33
+ });
34
+ if (!response.data) {
35
+ throw new Error(`Failed to fetch trigger history for account ${accountId}: HTTP ${response.response.status}`);
36
+ }
37
+ return response.data;
38
+ }
@@ -0,0 +1,387 @@
1
+ import { ProtonClient } from "@n1xyz/proton";
2
+ import { PublicKey } from "@solana/web3.js";
3
+ import { EventEmitter } from "events";
4
+ import { Client } from "openapi-fetch";
5
+ import type { paths } from "../../gen/openapi.ts";
6
+ import { Account, AccountPnlPage, AccountPnlQuery, ActionResponse, AggregateMetrics, MarketsInfo, Market, MarketStats, NordConfig, OrderbookQuery, OrderbookResponse, FeeTierConfig, PeakTpsPeriodUnit, Token, TradesResponse, User, AccountTriggerInfo, HistoryTriggerQuery, TriggerHistoryPage, FeeTierId, AccountFeeTierPage, PageResultStringOrderInfo, PageResultStringTrade, OrderInfoFromApi, TokenStats, FillRole } from "../../types";
7
+ import { NordWebSocketClient } from "../../websocket/index";
8
+ import { OrderbookSubscription, TradeSubscription } from "../models/Subscriber";
9
+ /**
10
+ * Main Nord client class for interacting with the Nord API
11
+ */
12
+ export declare class Nord {
13
+ /** Base URL for the Nord web server */
14
+ readonly webServerUrl: string;
15
+ /** Solana RPC URL */
16
+ readonly solanaUrl: string;
17
+ /** Available markets */
18
+ markets: Market[];
19
+ /** Available tokens */
20
+ tokens: Token[];
21
+ /** Map of symbol to market_id */
22
+ private symbolToMarketId;
23
+ /** Proton client for proton related operations */
24
+ protonClient: ProtonClient;
25
+ /** Shared HTTP client */
26
+ readonly client: Client<paths>;
27
+ /**
28
+ * Create a new Nord client
29
+ *
30
+ * @param config - Configuration options for the Nord client
31
+ * @param config.webServerUrl - Base URL for the Nord web server
32
+ * @param config.solanaUrl - Solana cluster URL
33
+ * @throws {Error} If required configuration is missing
34
+ */
35
+ private constructor();
36
+ /**
37
+ * Create a WebSocket client with specific subscriptions
38
+ *
39
+ * @param options - Subscription options that specify which data streams to subscribe to
40
+ * @returns A new WebSocket client with the requested subscriptions
41
+ * @throws {NordError} If invalid subscription options are provided
42
+ *
43
+ * @example
44
+ * // Create a client for trades and deltas from one market and an account
45
+ * const wsClient = nord.createWebSocketClient({
46
+ * trades: ["BTCUSDC"],
47
+ * deltas: ["BTCUSDC"],
48
+ * accounts: [123]
49
+ * });
50
+ *
51
+ * @example
52
+ * // Create a client for trades from multiple markets
53
+ * const tradesClient = nord.createWebSocketClient({
54
+ * trades: ["BTCUSDC", "ETHUSDC"]
55
+ * });
56
+ */
57
+ createWebSocketClient(options: Readonly<{
58
+ trades?: string[];
59
+ deltas?: string[];
60
+ accounts?: number[];
61
+ }>): NordWebSocketClient;
62
+ private GET;
63
+ /**
64
+ * Get the current timestamp from the Nord server
65
+ *
66
+ * @returns Current timestamp as a bigint
67
+ * @throws {NordError} If the request fails
68
+ */
69
+ getTimestamp(): Promise<bigint>;
70
+ /**
71
+ * Get the last event nonce from the Nord server
72
+ *
73
+ * @returns Next action nonce
74
+ * @throws {NordError} If the request fails
75
+ */
76
+ getActionNonce(): Promise<number>;
77
+ /**
78
+ * Fetch information about Nord markets and tokens
79
+ *
80
+ * @throws {NordError} If the request fails
81
+ */
82
+ fetchNordInfo(): Promise<void>;
83
+ /**
84
+ * Initialize a new Nord client
85
+ *
86
+ * @param nordConfig - Configuration options for the Nord client
87
+ * @param nordConfig.webServerUrl - Base URL for the Nord web server
88
+ * @param nordConfig.app - App address
89
+ * @param nordConfig.solanaUrl - Solana cluster URL
90
+ * @returns Initialized Nord client
91
+ * @throws {NordError} If initialization fails
92
+ */
93
+ static initNord({ app, solanaUrl, webServerUrl, protonUrl, }: Readonly<NordConfig>): Promise<Nord>;
94
+ /**
95
+ * Initialize the Nord client
96
+ * @private
97
+ */
98
+ private init;
99
+ /**
100
+ * Query a specific action
101
+ *
102
+ * @param query - Action query parameters
103
+ * @returns Action response
104
+ * @throws {NordError} If the request fails
105
+ */
106
+ queryAction({ action_id, }: {
107
+ action_id: number;
108
+ }): Promise<ActionResponse | null>;
109
+ /**
110
+ * Query recent actions
111
+ *
112
+ * @param from - Starting action index
113
+ * @param to - Ending action index
114
+ * @returns Actions response
115
+ * @throws {NordError} If the request fails
116
+ */
117
+ queryRecentActions(query: {
118
+ from: number;
119
+ to: number;
120
+ }): Promise<ActionResponse[]>;
121
+ /**
122
+ * Get the last action ID
123
+ *
124
+ * @returns Last action ID
125
+ * @throws {NordError} If the request fails
126
+ */
127
+ getLastActionId(): Promise<number>;
128
+ /**
129
+ * Fetch aggregate metrics from the Nord API
130
+ *
131
+ * @param txPeakTpsPeriod - Period for peak TPS calculation
132
+ * @param txPeakTpsPeriodUnit - Unit for peak TPS period
133
+ * @returns Aggregate metrics
134
+ * @throws {NordError} If the request fails
135
+ */
136
+ aggregateMetrics(txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
137
+ /**
138
+ * Get current transactions per second
139
+ *
140
+ * @param period - Time period for the query
141
+ * @returns Current TPS value
142
+ * @throws {NordError} If the request fails
143
+ */
144
+ getCurrentTps(period?: string): Promise<number>;
145
+ /**
146
+ * Get peak transactions per second
147
+ *
148
+ * @param period - Time period for the query
149
+ * @returns Peak TPS value
150
+ * @throws {NordError} If the request fails
151
+ */
152
+ getPeakTps(period?: string): Promise<number>;
153
+ /**
154
+ * Get median transaction latency
155
+ *
156
+ * @param period - Time period for the query
157
+ * @returns Median latency in milliseconds
158
+ * @throws {NordError} If the request fails
159
+ */
160
+ getMedianLatency(period?: string): Promise<number>;
161
+ /**
162
+ * Get total transaction count
163
+ *
164
+ * @returns Total transaction count
165
+ * @throws {NordError} If the request fails
166
+ */
167
+ getTotalTransactions(): Promise<number>;
168
+ /**
169
+ * Query Prometheus metrics
170
+ *
171
+ * @param params - Prometheus query parameters
172
+ * @returns Query result as a number
173
+ * @throws {NordError} If the request fails
174
+ */
175
+ queryPrometheus(params: string): Promise<number>;
176
+ /**
177
+ * Subscribe to orderbook updates for a market
178
+ *
179
+ * @param symbol - Market symbol
180
+ * @returns Orderbook subscription
181
+ * @throws {NordError} If symbol is invalid
182
+ */
183
+ subscribeOrderbook(symbol: string): OrderbookSubscription;
184
+ /**
185
+ * Subscribe to trade updates for a market
186
+ *
187
+ * @param symbol - Market symbol
188
+ * @returns Trade subscription
189
+ * @throws {NordError} If symbol is invalid
190
+ */
191
+ subscribeTrades(symbol: string): TradeSubscription;
192
+ /**
193
+ * Subscribe to account updates
194
+ *
195
+ * @param accountId - Account ID to subscribe to
196
+ * @returns User subscription
197
+ * @throws {NordError} If accountId is invalid
198
+ */
199
+ subscribeAccount(accountId: number): EventEmitter<[never]> & {
200
+ close: () => void;
201
+ };
202
+ /**
203
+ * Get trades for a market
204
+ *
205
+ * @param query - Trades query parameters
206
+ * @returns Trades response
207
+ * @throws {NordError} If the request fails
208
+ */
209
+ getTrades(query: Readonly<{
210
+ marketId?: number;
211
+ takerId?: number;
212
+ makerId?: number;
213
+ takerSide?: "bid" | "ask";
214
+ pageSize?: number;
215
+ sinceRcf3339?: string;
216
+ untilRfc3339?: string;
217
+ pageId?: string;
218
+ }>): Promise<TradesResponse>;
219
+ /**
220
+ * Get user account IDs
221
+ *
222
+ * @param query - User account IDs query parameters
223
+ * @returns User account IDs response
224
+ * @throws {NordError} If the request fails
225
+ */
226
+ getUser(query: {
227
+ pubkey: string | PublicKey;
228
+ }): Promise<User | null>;
229
+ /**
230
+ * Get orderbook for a market
231
+ *
232
+ * @param query - Orderbook query parameters (either market_id or symbol must be provided)
233
+ * @returns Orderbook response
234
+ * @throws {NordError} If the request fails or if the market symbol is unknown
235
+ * @remarks It's recommended to initialize the Nord client using the static `initNord` method
236
+ * to ensure market information is properly loaded before calling this method.
237
+ */
238
+ getOrderbook(query: OrderbookQuery): Promise<OrderbookResponse>;
239
+ /**
240
+ * Get information about the Nord server
241
+ *
242
+ * @returns Information about markets and tokens
243
+ * @throws {NordError} If the request fails
244
+ */
245
+ getInfo(): Promise<MarketsInfo>;
246
+ /**
247
+ * Fetch the current fee tier brackets configured on Nord.
248
+ *
249
+ * @returns Array of fee tier identifiers paired with their configuration
250
+ * @throws {NordError} If the request fails
251
+ */
252
+ getFeeBrackets(): Promise<Array<[FeeTierId, FeeTierConfig]>>;
253
+ /**
254
+ * Retrieve the fee tier assigned to a specific account.
255
+ *
256
+ * @param accountId - Account identifier to query
257
+ * @returns Fee tier details for the requested account
258
+ * @throws {NordError} If the request fails
259
+ */
260
+ getAccountFeeTier(accountId: number): Promise<FeeTierId>;
261
+ /**
262
+ * Get account information
263
+ *
264
+ * @param accountId - Account ID to get information for
265
+ * @returns Account information
266
+ * @throws {NordError} If the request fails
267
+ */
268
+ getAccount(accountId: number): Promise<Account>;
269
+ /**
270
+ * Get the public key associated with an account id.
271
+ *
272
+ * @param accountId - Account id to query
273
+ * @returns Base58-encoded account public key
274
+ * @throws {NordError} If the request fails
275
+ */
276
+ getAccountPubkey(accountId: number): Promise<string>;
277
+ /**
278
+ * Get the withdrawal fee charged for an account.
279
+ *
280
+ * @param accountId - Account id to query
281
+ * @returns Withdrawal fee quoted in quote token units
282
+ * @throws {NordError} If the request fails
283
+ */
284
+ getAccountWithdrawalFee(accountId: number): Promise<number>;
285
+ /**
286
+ * Get open orders for an account.
287
+ *
288
+ * @param accountId - Account id to query
289
+ * @param query - Optional pagination parameters
290
+ * @returns Page of orders keyed by client order id
291
+ * @throws {NordError} If the request fails
292
+ */
293
+ getAccountOrders(accountId: number, query?: {
294
+ startInclusive?: string | null;
295
+ pageSize?: number | null;
296
+ }): Promise<PageResultStringOrderInfo>;
297
+ /**
298
+ * List account fee tiers with pagination support.
299
+ */
300
+ getAccountsFeeTiers(query?: {
301
+ startInclusive?: number | null;
302
+ pageSize?: number | null;
303
+ }): Promise<AccountFeeTierPage>;
304
+ /**
305
+ * Get profit and loss history for an account
306
+ *
307
+ * @param accountId - Account ID to query
308
+ * @param query - Optional time and pagination filters
309
+ * @returns Page of PnL entries ordered from latest to oldest
310
+ * @throws {NordError} If the request fails
311
+ */
312
+ getAccountPnl(accountId: number, query?: Partial<AccountPnlQuery>): Promise<AccountPnlPage>;
313
+ /**
314
+ * Get market statistics (alias for marketsStats for backward compatibility)
315
+ *
316
+ * @returns Market statistics response
317
+ */
318
+ getMarketStats({ marketId, }: {
319
+ marketId: number;
320
+ }): Promise<MarketStats>;
321
+ /**
322
+ * Fetch the per-market fee quote for an account.
323
+ *
324
+ * @param params - Market id, fee kind, and account id to quote
325
+ * @returns Fee in quote token units (negative means fee is charged)
326
+ * @throws {NordError} If the request fails
327
+ */
328
+ getMarketFee({ marketId, feeKind, accountId, }: {
329
+ marketId: number;
330
+ feeKind: FillRole;
331
+ accountId: number;
332
+ }): Promise<number>;
333
+ /**
334
+ * Fetch token statistics such as index price and oracle metadata.
335
+ *
336
+ * @param tokenId - Token identifier
337
+ * @returns Token stats
338
+ * @throws {NordError} If the request fails
339
+ */
340
+ getTokenStats(tokenId: number): Promise<TokenStats>;
341
+ /**
342
+ * Get order summary by order id.
343
+ *
344
+ * @param orderId - Order identifier
345
+ * @returns Order information
346
+ * @throws {NordError} If the request fails
347
+ */
348
+ getOrder(orderId: string): Promise<OrderInfoFromApi>;
349
+ /**
350
+ * Get trade history for a specific order.
351
+ *
352
+ * @param orderId - Order identifier
353
+ * @param query - Optional pagination parameters
354
+ * @returns Page of trades associated with the order
355
+ * @throws {NordError} If the request fails
356
+ */
357
+ getOrderTrades(orderId: string, query?: {
358
+ startInclusive?: string | null;
359
+ pageSize?: number | null;
360
+ }): Promise<PageResultStringTrade>;
361
+ /**
362
+ * Check if an account exists for the given address
363
+ *
364
+ * @param address - The public key address to check
365
+ * @returns True if the account exists, false otherwise
366
+ * @deprecated use getUser instead
367
+ */
368
+ accountExists(pubkey: string | PublicKey): Promise<boolean>;
369
+ /**
370
+ * Fetch active triggers for an account.
371
+ *
372
+ * @param params Optional parameters containing an explicit account id.
373
+ * @throws {NordError} If no account can be resolved or the request fails.
374
+ */
375
+ getAccountTriggers(params?: {
376
+ accountId?: number;
377
+ }): Promise<AccountTriggerInfo[]>;
378
+ /**
379
+ * Fetch trigger history for an account.
380
+ *
381
+ * @param params Optional parameters with account id and history query filters.
382
+ * @throws {NordError} If no account can be resolved or the request fails.
383
+ */
384
+ getAccountTriggerHistory(params: HistoryTriggerQuery & {
385
+ accountId?: number;
386
+ }): Promise<TriggerHistoryPage>;
387
+ }