@n1xyz/nord-ts 0.0.1 → 0.0.4

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.
Files changed (237) hide show
  1. package/.eslintrc.js +11 -0
  2. package/README.md +148 -65
  3. package/dist/bridge/NordUser.d.ts +78 -0
  4. package/dist/bridge/NordUser.js +196 -0
  5. package/dist/bridge/client.d.ts +150 -0
  6. package/dist/bridge/client.js +394 -0
  7. package/dist/bridge/const.d.ts +23 -0
  8. package/dist/bridge/const.js +47 -0
  9. package/dist/bridge/index.d.ts +5 -0
  10. package/dist/bridge/index.js +23 -0
  11. package/dist/bridge/types.d.ts +118 -0
  12. package/dist/bridge/types.js +16 -0
  13. package/dist/bridge/utils.d.ts +64 -0
  14. package/dist/bridge/utils.js +131 -0
  15. package/dist/client.d.ts +70 -0
  16. package/dist/client.js +129 -0
  17. package/dist/const.d.ts +2 -5
  18. package/dist/const.js +18 -22
  19. package/dist/constants/endpoints.d.ts +65 -0
  20. package/dist/constants/endpoints.js +68 -0
  21. package/dist/gen/common.d.ts +6 -1
  22. package/dist/gen/common.js +19 -9
  23. package/dist/gen/nord.d.ts +75 -17
  24. package/dist/gen/nord.js +987 -423
  25. package/dist/idl/bridge.d.ts +2 -0
  26. package/dist/idl/bridge.js +703 -0
  27. package/dist/index.d.ts +8 -5
  28. package/dist/index.js +18 -2
  29. package/dist/models/account.d.ts +58 -0
  30. package/dist/models/account.js +6 -0
  31. package/dist/models/index.d.ts +8 -0
  32. package/dist/models/index.js +28 -0
  33. package/dist/models/market.d.ts +137 -0
  34. package/dist/models/market.js +6 -0
  35. package/dist/models/order.d.ts +211 -0
  36. package/dist/models/order.js +6 -0
  37. package/dist/models/token.d.ts +50 -0
  38. package/dist/models/token.js +6 -0
  39. package/dist/nord/Nord.d.ts +222 -49
  40. package/dist/nord/Nord.js +290 -278
  41. package/dist/nord/NordError.d.ts +23 -0
  42. package/dist/nord/NordError.js +48 -0
  43. package/dist/nord/NordImpl.d.ts +6 -2
  44. package/dist/nord/NordImpl.js +21 -1
  45. package/dist/nord/NordUser.d.ts +208 -42
  46. package/dist/nord/NordUser.js +389 -157
  47. package/dist/nord/Subscriber.d.ts +37 -0
  48. package/dist/nord/Subscriber.js +29 -0
  49. package/dist/nord/api/actions.d.ts +101 -0
  50. package/dist/nord/api/actions.js +250 -0
  51. package/dist/nord/api/core.d.ts +49 -0
  52. package/dist/nord/api/core.js +121 -0
  53. package/dist/nord/api/index.d.ts +1 -0
  54. package/dist/nord/api/index.js +17 -0
  55. package/dist/nord/api/market.d.ts +36 -0
  56. package/dist/nord/api/market.js +98 -0
  57. package/dist/nord/api/metrics.d.ts +67 -0
  58. package/dist/nord/api/metrics.js +132 -0
  59. package/dist/nord/api/orderFunctions.d.ts +168 -0
  60. package/dist/nord/api/orderFunctions.js +133 -0
  61. package/dist/nord/api/queries.d.ts +81 -0
  62. package/dist/nord/api/queries.js +187 -0
  63. package/dist/nord/client/Nord.d.ts +335 -0
  64. package/dist/nord/client/Nord.js +532 -0
  65. package/dist/nord/client/NordUser.d.ts +320 -0
  66. package/dist/nord/client/NordUser.js +701 -0
  67. package/dist/nord/core.d.ts +48 -0
  68. package/dist/nord/core.js +97 -0
  69. package/dist/nord/index.d.ts +9 -2
  70. package/dist/nord/index.js +30 -6
  71. package/dist/nord/market.d.ts +36 -0
  72. package/dist/nord/market.js +90 -0
  73. package/dist/nord/metrics.d.ts +67 -0
  74. package/dist/nord/metrics.js +124 -0
  75. package/dist/nord/models/Subscriber.d.ts +37 -0
  76. package/dist/nord/models/Subscriber.js +29 -0
  77. package/dist/nord/queries.d.ts +81 -0
  78. package/dist/nord/queries.js +181 -0
  79. package/dist/nord/types.d.ts +88 -0
  80. package/dist/nord/types.js +2 -0
  81. package/dist/nord/utils/NordError.d.ts +35 -0
  82. package/dist/nord/utils/NordError.js +46 -0
  83. package/dist/nord/websocket.d.ts +49 -0
  84. package/dist/nord/websocket.js +107 -0
  85. package/dist/operations/account.d.ts +58 -0
  86. package/dist/operations/account.js +112 -0
  87. package/dist/operations/market.d.ts +65 -0
  88. package/dist/operations/market.js +131 -0
  89. package/dist/operations/orders.d.ts +57 -0
  90. package/dist/operations/orders.js +129 -0
  91. package/dist/solana/NordUser.d.ts +78 -0
  92. package/dist/solana/NordUser.js +196 -0
  93. package/dist/solana/client.d.ts +139 -0
  94. package/dist/solana/client.js +360 -0
  95. package/dist/solana/const.d.ts +23 -0
  96. package/dist/solana/const.js +47 -0
  97. package/dist/solana/index.d.ts +5 -0
  98. package/dist/solana/index.js +23 -0
  99. package/dist/solana/types.d.ts +118 -0
  100. package/dist/solana/types.js +16 -0
  101. package/dist/solana/utils.d.ts +64 -0
  102. package/dist/solana/utils.js +131 -0
  103. package/dist/types/api.d.ts +152 -0
  104. package/dist/types/api.js +6 -0
  105. package/dist/types/config.d.ts +34 -0
  106. package/dist/types/config.js +6 -0
  107. package/dist/types.d.ts +144 -87
  108. package/dist/types.js +13 -2
  109. package/dist/utils/errors.d.ts +96 -0
  110. package/dist/utils/errors.js +132 -0
  111. package/dist/utils/http.d.ts +35 -0
  112. package/dist/utils/http.js +105 -0
  113. package/dist/utils.d.ts +14 -5
  114. package/dist/utils.js +26 -7
  115. package/dist/websocket/NordWebSocketClient.d.ts +71 -0
  116. package/dist/websocket/NordWebSocketClient.js +343 -0
  117. package/dist/websocket/client.d.ts +93 -0
  118. package/dist/websocket/client.js +222 -0
  119. package/dist/websocket/events.d.ts +19 -0
  120. package/dist/websocket/events.js +2 -0
  121. package/dist/websocket/index.d.ts +2 -0
  122. package/dist/websocket/index.js +5 -0
  123. package/dist/websocket.d.ts +55 -0
  124. package/dist/websocket.js +211 -0
  125. package/docs/assets/navigation.js +1 -1
  126. package/docs/assets/search.js +1 -1
  127. package/docs/classes/Nord.html +2 -15
  128. package/docs/classes/NordUser.html +4 -4
  129. package/docs/enums/FillMode.html +2 -2
  130. package/docs/enums/KeyType.html +2 -2
  131. package/docs/enums/PeakTpsPeriodUnit.html +2 -2
  132. package/docs/enums/Side.html +2 -2
  133. package/docs/functions/assert.html +1 -1
  134. package/docs/functions/bigIntToProtoU128.html +1 -1
  135. package/docs/functions/checkPubKeyLength.html +1 -1
  136. package/docs/functions/checkedFetch.html +1 -1
  137. package/docs/functions/decodeLengthDelimited.html +1 -1
  138. package/docs/functions/encodeLengthDelimited.html +1 -1
  139. package/docs/functions/fillModeToProtoFillMode.html +1 -1
  140. package/docs/functions/findMarket.html +1 -1
  141. package/docs/functions/findToken.html +1 -1
  142. package/docs/functions/makeWalletSignFn.html +1 -1
  143. package/docs/functions/optExpect.html +1 -1
  144. package/docs/functions/optMap.html +1 -1
  145. package/docs/functions/optUnwrap.html +1 -1
  146. package/docs/functions/panic.html +1 -1
  147. package/docs/functions/signAction.html +1 -1
  148. package/docs/functions/toScaledU128.html +1 -1
  149. package/docs/functions/toScaledU64.html +1 -1
  150. package/docs/interfaces/Account.html +2 -2
  151. package/docs/interfaces/ActionInfo.html +2 -2
  152. package/docs/interfaces/ActionQuery.html +2 -2
  153. package/docs/interfaces/ActionResponse.html +2 -2
  154. package/docs/interfaces/ActionsExtendedInfo.html +2 -2
  155. package/docs/interfaces/ActionsQuery.html +2 -2
  156. package/docs/interfaces/ActionsResponse.html +2 -2
  157. package/docs/interfaces/AggregateMetrics.html +2 -2
  158. package/docs/interfaces/BlockQuery.html +2 -2
  159. package/docs/interfaces/BlockResponse.html +2 -2
  160. package/docs/interfaces/BlockSummary.html +2 -2
  161. package/docs/interfaces/BlockSummaryResponse.html +2 -2
  162. package/docs/interfaces/DeltaEvent.html +2 -2
  163. package/docs/interfaces/ERC20TokenInfo.html +2 -2
  164. package/docs/interfaces/Info.html +2 -2
  165. package/docs/interfaces/Market.html +2 -2
  166. package/docs/interfaces/MarketStats.html +2 -2
  167. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  168. package/docs/interfaces/NordConfig.html +2 -2
  169. package/docs/interfaces/Order.html +2 -2
  170. package/docs/interfaces/OrderInfo.html +2 -2
  171. package/docs/interfaces/PerpMarketStats.html +2 -2
  172. package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
  173. package/docs/interfaces/RollmanActionInfo.html +2 -2
  174. package/docs/interfaces/RollmanActionResponse.html +2 -2
  175. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  176. package/docs/interfaces/RollmanBlockResponse.html +2 -2
  177. package/docs/interfaces/SubscriberConfig.html +2 -2
  178. package/docs/interfaces/Token.html +2 -2
  179. package/docs/interfaces/Trade.html +2 -2
  180. package/docs/interfaces/Trades.html +2 -2
  181. package/docs/modules.html +0 -7
  182. package/docs/types/BigIntValue.html +1 -1
  183. package/docs/variables/DEBUG_KEYS.html +1 -1
  184. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  185. package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -1
  186. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  187. package/docs/variables/DEV_URL.html +1 -1
  188. package/docs/variables/ERC20_ABI.html +1 -1
  189. package/docs/variables/EVM_DEV_URL.html +1 -1
  190. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -1
  191. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  192. package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -1
  193. package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -1
  194. package/docs/variables/SESSION_TTL.html +1 -1
  195. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  196. package/docs/variables/ZERO_DECIMAL.html +1 -1
  197. package/package.json +10 -12
  198. package/src/bridge/client.ts +487 -0
  199. package/src/bridge/const.ts +53 -0
  200. package/src/bridge/index.ts +7 -0
  201. package/src/bridge/types.ts +127 -0
  202. package/src/bridge/utils.ts +140 -0
  203. package/src/const.ts +20 -25
  204. package/src/gen/common.ts +27 -10
  205. package/src/gen/nord.ts +1044 -483
  206. package/src/idl/bridge.ts +702 -0
  207. package/src/index.ts +24 -5
  208. package/src/nord/{actions.ts → api/actions.ts} +33 -37
  209. package/src/nord/api/core.ts +130 -0
  210. package/src/nord/api/market.ts +125 -0
  211. package/src/nord/api/metrics.ts +154 -0
  212. package/src/nord/api/queries.ts +236 -0
  213. package/src/nord/client/Nord.ts +652 -0
  214. package/src/nord/client/NordUser.ts +1105 -0
  215. package/src/nord/index.ts +16 -2
  216. package/src/nord/models/Subscriber.ts +57 -0
  217. package/src/nord/utils/NordError.ts +72 -0
  218. package/src/types.ts +170 -99
  219. package/src/utils.ts +40 -19
  220. package/src/websocket/NordWebSocketClient.ts +432 -0
  221. package/src/websocket/events.ts +31 -0
  222. package/src/websocket/index.ts +2 -0
  223. package/tests/utils.spec.ts +24 -24
  224. package/docs/classes/Subscriber.html +0 -6
  225. package/docs/functions/createWebSocketSubscription.html +0 -12
  226. package/docs/interfaces/OrderbookOrder.html +0 -6
  227. package/docs/interfaces/OrderbookResponse.html +0 -10
  228. package/docs/interfaces/TradeInfo.html +0 -20
  229. package/docs/interfaces/TradesQueryParams.html +0 -10
  230. package/docs/interfaces/TradesResponse.html +0 -12
  231. package/src/abis/ERC20_ABI.ts +0 -310
  232. package/src/abis/NORD_GETTERS_FACET_ABI.ts +0 -192
  233. package/src/abis/NORD_RAMP_FACET_ABI.ts +0 -141
  234. package/src/abis/index.ts +0 -3
  235. package/src/nord/Nord.ts +0 -504
  236. package/src/nord/NordImpl.ts +0 -8
  237. package/src/nord/NordUser.ts +0 -469
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.marketsStats = marketsStats;
4
+ exports.getTrades = getTrades;
5
+ exports.getUserAccountIds = getUserAccountIds;
6
+ exports.getOrderbook = getOrderbook;
7
+ const utils_1 = require("../../utils");
8
+ const NordError_1 = require("../utils/NordError");
9
+ /**
10
+ * Get market statistics
11
+ *
12
+ * @param webServerUrl - Base URL for the Nord web server
13
+ * @returns Market statistics response
14
+ * @throws {NordError} If the request fails
15
+ */
16
+ async function marketsStats(webServerUrl) {
17
+ try {
18
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/stats`);
19
+ return await response.json();
20
+ }
21
+ catch (error) {
22
+ throw new NordError_1.NordError('Failed to fetch markets stats', { cause: error });
23
+ }
24
+ }
25
+ /**
26
+ * Get trades for a market
27
+ *
28
+ * @param webServerUrl - Base URL for the Nord web server
29
+ * @param query - Trades query parameters
30
+ * @returns Trades response
31
+ * @throws {NordError} If the request fails
32
+ */
33
+ async function getTrades(webServerUrl, query) {
34
+ try {
35
+ const params = new URLSearchParams();
36
+ params.append('accountId', query.accountId.toString());
37
+ if (query.since) {
38
+ params.append('since', query.since);
39
+ }
40
+ if (query.until) {
41
+ params.append('until', query.until);
42
+ }
43
+ if (query.pageId) {
44
+ params.append('pageId', query.pageId);
45
+ }
46
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/trades?${params.toString()}`);
47
+ return await response.json();
48
+ }
49
+ catch (error) {
50
+ throw new NordError_1.NordError('Failed to get trades', { cause: error });
51
+ }
52
+ }
53
+ /**
54
+ * Get user account IDs
55
+ *
56
+ * @param webServerUrl - Base URL for the Nord web server
57
+ * @param query - User account IDs query parameters
58
+ * @returns User account IDs response
59
+ * @throws {NordError} If the request fails
60
+ */
61
+ async function getUserAccountIds(webServerUrl, query) {
62
+ try {
63
+ const params = new URLSearchParams();
64
+ params.append('pubkey', query.pubkey);
65
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/user?${params.toString()}`);
66
+ return await response.json();
67
+ }
68
+ catch (error) {
69
+ throw new NordError_1.NordError('Failed to get user account IDs', { cause: error });
70
+ }
71
+ }
72
+ /**
73
+ * Get orderbook for a market
74
+ *
75
+ * @param webServerUrl - Base URL for the Nord web server
76
+ * @param query - Orderbook query parameters
77
+ * @returns Orderbook response
78
+ * @throws {NordError} If the request fails
79
+ */
80
+ async function getOrderbook(webServerUrl, query) {
81
+ try {
82
+ const params = new URLSearchParams();
83
+ if (query.symbol) {
84
+ params.append('symbol', query.symbol);
85
+ }
86
+ else if (query.market_id !== undefined) {
87
+ params.append('market_id', query.market_id.toString());
88
+ }
89
+ else {
90
+ throw new NordError_1.NordError('Either symbol or market_id must be provided for orderbook query');
91
+ }
92
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/orderbook?${params.toString()}`);
93
+ return await response.json();
94
+ }
95
+ catch (error) {
96
+ throw new NordError_1.NordError('Failed to get orderbook', { cause: error });
97
+ }
98
+ }
@@ -0,0 +1,67 @@
1
+ import { AggregateMetrics, PeakTpsPeriodUnit } from '../../types';
2
+ /**
3
+ * Time periods for metrics queries
4
+ */
5
+ export declare enum MetricPeriod {
6
+ ONE_MINUTE = "1m",
7
+ FIVE_MINUTES = "5m",
8
+ FIFTEEN_MINUTES = "15m",
9
+ ONE_HOUR = "1h",
10
+ FOUR_HOURS = "4h",
11
+ ONE_DAY = "24h",
12
+ ONE_WEEK = "7d"
13
+ }
14
+ /**
15
+ * Fetch aggregate metrics from the Nord API
16
+ *
17
+ * @param webServerUrl - Base URL for the Nord web server
18
+ * @param txPeakTpsPeriod - Period for peak TPS calculation
19
+ * @param txPeakTpsPeriodUnit - Unit for peak TPS period
20
+ * @returns Aggregate metrics
21
+ * @throws {NordError} If the request fails
22
+ */
23
+ export declare function aggregateMetrics(webServerUrl: string, txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
24
+ /**
25
+ * Get current transactions per second
26
+ *
27
+ * @param webServerUrl - Base URL for the Nord web server
28
+ * @param period - Time period for the query
29
+ * @returns Current TPS value
30
+ * @throws {NordError} If the request fails
31
+ */
32
+ export declare function getCurrentTps(webServerUrl: string, period?: string): Promise<number>;
33
+ /**
34
+ * Get peak transactions per second
35
+ *
36
+ * @param webServerUrl - Base URL for the Nord web server
37
+ * @param period - Time period for the query
38
+ * @returns Peak TPS value
39
+ * @throws {NordError} If the request fails
40
+ */
41
+ export declare function getPeakTps(webServerUrl: string, period?: string): Promise<number>;
42
+ /**
43
+ * Get median transaction latency
44
+ *
45
+ * @param webServerUrl - Base URL for the Nord web server
46
+ * @param period - Time period for the query
47
+ * @returns Median latency in milliseconds
48
+ * @throws {NordError} If the request fails
49
+ */
50
+ export declare function getMedianLatency(webServerUrl: string, period?: string): Promise<number>;
51
+ /**
52
+ * Get total transaction count
53
+ *
54
+ * @param webServerUrl - Base URL for the Nord web server
55
+ * @returns Total transaction count
56
+ * @throws {NordError} If the request fails
57
+ */
58
+ export declare function getTotalTransactions(webServerUrl: string): Promise<number>;
59
+ /**
60
+ * Query Prometheus metrics
61
+ *
62
+ * @param webServerUrl - Base URL for the Nord web server
63
+ * @param params - Prometheus query parameters
64
+ * @returns Query result as a number
65
+ * @throws {NordError} If the request fails
66
+ */
67
+ export declare function queryPrometheus(webServerUrl: string, params: string): Promise<number>;
@@ -0,0 +1,132 @@
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
+ return await response.json();
39
+ }
40
+ catch (error) {
41
+ throw new NordError_1.NordError('Failed to fetch aggregate metrics', { cause: error });
42
+ }
43
+ }
44
+ /**
45
+ * Get current transactions per second
46
+ *
47
+ * @param webServerUrl - Base URL for the Nord web server
48
+ * @param period - Time period for the query
49
+ * @returns Current TPS value
50
+ * @throws {NordError} If the request fails
51
+ */
52
+ async function getCurrentTps(webServerUrl, period = '1m') {
53
+ try {
54
+ return await queryPrometheus(webServerUrl, `sum(rate(nord_tx_count[${period}]))`);
55
+ }
56
+ catch (error) {
57
+ throw new NordError_1.NordError(`Failed to get current TPS for period ${period}`, {
58
+ cause: error,
59
+ });
60
+ }
61
+ }
62
+ /**
63
+ * Get peak transactions per second
64
+ *
65
+ * @param webServerUrl - Base URL for the Nord web server
66
+ * @param period - Time period for the query
67
+ * @returns Peak TPS value
68
+ * @throws {NordError} If the request fails
69
+ */
70
+ async function getPeakTps(webServerUrl, period = '24h') {
71
+ try {
72
+ return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_tx_count[1m]))[${period}:])`);
73
+ }
74
+ catch (error) {
75
+ throw new NordError_1.NordError(`Failed to get peak TPS for period ${period}`, {
76
+ cause: error,
77
+ });
78
+ }
79
+ }
80
+ /**
81
+ * Get median transaction latency
82
+ *
83
+ * @param webServerUrl - Base URL for the Nord web server
84
+ * @param period - Time period for the query
85
+ * @returns Median latency in milliseconds
86
+ * @throws {NordError} If the request fails
87
+ */
88
+ async function getMedianLatency(webServerUrl, period = '1m') {
89
+ try {
90
+ return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_tx_latency_ms[${period}])`);
91
+ }
92
+ catch (error) {
93
+ throw new NordError_1.NordError(`Failed to get median latency for period ${period}`, {
94
+ cause: error,
95
+ });
96
+ }
97
+ }
98
+ /**
99
+ * Get total transaction count
100
+ *
101
+ * @param webServerUrl - Base URL for the Nord web server
102
+ * @returns Total transaction count
103
+ * @throws {NordError} If the request fails
104
+ */
105
+ async function getTotalTransactions(webServerUrl) {
106
+ try {
107
+ return await queryPrometheus(webServerUrl, 'sum(nord_tx_count)');
108
+ }
109
+ catch (error) {
110
+ throw new NordError_1.NordError('Failed to get total transactions', { cause: error });
111
+ }
112
+ }
113
+ /**
114
+ * Query Prometheus metrics
115
+ *
116
+ * @param webServerUrl - Base URL for the Nord web server
117
+ * @param params - Prometheus query parameters
118
+ * @returns Query result as a number
119
+ * @throws {NordError} If the request fails
120
+ */
121
+ async function queryPrometheus(webServerUrl, params) {
122
+ try {
123
+ const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/prometheus?query=${encodeURIComponent(params)}`);
124
+ const data = await response.json();
125
+ return data.data.result[0]?.value[1] || 0;
126
+ }
127
+ catch (error) {
128
+ throw new NordError_1.NordError(`Failed to query Prometheus: ${params}`, {
129
+ cause: error,
130
+ });
131
+ }
132
+ }
@@ -0,0 +1,168 @@
1
+ import { FillMode, Side } from "../../types";
2
+ import { BigIntValue } from "../../utils";
3
+ /**
4
+ * Interface for placing a new order
5
+ */
6
+ export interface PlaceOrderParams {
7
+ /**
8
+ * Server URL for the Nord API
9
+ */
10
+ serverUrl: string;
11
+ /**
12
+ * Function to sign messages
13
+ */
14
+ signFn: (message: Uint8Array) => Promise<Uint8Array>;
15
+ /**
16
+ * Current timestamp as bigint
17
+ */
18
+ currentTimestamp: bigint;
19
+ /**
20
+ * Nonce for the transaction
21
+ */
22
+ nonce: number;
23
+ /**
24
+ * Session ID
25
+ */
26
+ sessionId: BigIntValue;
27
+ /**
28
+ * Sender account ID (optional)
29
+ */
30
+ senderId?: number;
31
+ /**
32
+ * Market ID
33
+ */
34
+ marketId: number;
35
+ /**
36
+ * Number of decimals for size
37
+ */
38
+ sizeDecimals: number;
39
+ /**
40
+ * Number of decimals for price
41
+ */
42
+ priceDecimals: number;
43
+ /**
44
+ * Order side (Bid = buy, Ask = sell)
45
+ */
46
+ side: Side;
47
+ /**
48
+ * Order size
49
+ */
50
+ size: number | string;
51
+ /**
52
+ * Order price
53
+ */
54
+ price: number | string;
55
+ /**
56
+ * Fill mode for the order
57
+ */
58
+ fillMode?: FillMode;
59
+ /**
60
+ * Whether the order is reduce-only
61
+ */
62
+ isReduceOnly?: boolean;
63
+ /**
64
+ * Quote size (optional)
65
+ */
66
+ quoteSize?: number | string;
67
+ /**
68
+ * Liquidatee ID (optional)
69
+ */
70
+ liquidateeId?: number;
71
+ /**
72
+ * Client order ID (optional)
73
+ */
74
+ clientOrderId?: BigIntValue;
75
+ }
76
+ /**
77
+ * Interface for canceling an existing order
78
+ */
79
+ export interface CancelOrderParams {
80
+ /**
81
+ * Server URL for the Nord API
82
+ */
83
+ serverUrl: string;
84
+ /**
85
+ * Function to sign messages
86
+ */
87
+ signFn: (message: Uint8Array) => Promise<Uint8Array>;
88
+ /**
89
+ * Current timestamp as bigint
90
+ */
91
+ currentTimestamp: bigint;
92
+ /**
93
+ * Nonce for the transaction
94
+ */
95
+ nonce: number;
96
+ /**
97
+ * Session ID
98
+ */
99
+ sessionId: BigIntValue;
100
+ /**
101
+ * Sender account ID (optional)
102
+ */
103
+ senderId?: number;
104
+ /**
105
+ * Order ID to cancel
106
+ */
107
+ orderId: BigIntValue;
108
+ /**
109
+ * Liquidatee ID (optional)
110
+ */
111
+ liquidateeId?: number;
112
+ }
113
+ /**
114
+ * Places a new order
115
+ *
116
+ * @param params - Parameters for placing an order
117
+ * @returns The order ID if successful, undefined otherwise
118
+ */
119
+ export declare function placeNewOrder(params: PlaceOrderParams): Promise<bigint | undefined>;
120
+ /**
121
+ * Cancels an existing order
122
+ *
123
+ * @param params - Parameters for canceling an order
124
+ * @returns The canceled order ID if successful
125
+ */
126
+ export declare function cancelExistingOrder(params: CancelOrderParams): Promise<bigint>;
127
+ /**
128
+ * Places a market buy order
129
+ *
130
+ * @param params - Parameters for placing an order (without price)
131
+ * @returns The order ID if successful, undefined otherwise
132
+ */
133
+ export declare function placeMarketBuyOrder(params: Omit<PlaceOrderParams, 'side' | 'fillMode' | 'price'>): Promise<bigint | undefined>;
134
+ /**
135
+ * Places a market sell order
136
+ *
137
+ * @param params - Parameters for placing an order (without price)
138
+ * @returns The order ID if successful, undefined otherwise
139
+ */
140
+ export declare function placeMarketSellOrder(params: Omit<PlaceOrderParams, 'side' | 'fillMode' | 'price'>): Promise<bigint | undefined>;
141
+ /**
142
+ * Places a limit buy order
143
+ *
144
+ * @param params - Parameters for placing an order
145
+ * @returns The order ID if successful, undefined otherwise
146
+ */
147
+ export declare function placeLimitBuyOrder(params: Omit<PlaceOrderParams, 'side' | 'fillMode'>): Promise<bigint | undefined>;
148
+ /**
149
+ * Places a limit sell order
150
+ *
151
+ * @param params - Parameters for placing an order
152
+ * @returns The order ID if successful, undefined otherwise
153
+ */
154
+ export declare function placeLimitSellOrder(params: Omit<PlaceOrderParams, 'side' | 'fillMode'>): Promise<bigint | undefined>;
155
+ /**
156
+ * Places a post-only buy order
157
+ *
158
+ * @param params - Parameters for placing an order
159
+ * @returns The order ID if successful, undefined otherwise
160
+ */
161
+ export declare function placePostOnlyBuyOrder(params: Omit<PlaceOrderParams, 'side' | 'fillMode'>): Promise<bigint | undefined>;
162
+ /**
163
+ * Places a post-only sell order
164
+ *
165
+ * @param params - Parameters for placing an order
166
+ * @returns The order ID if successful, undefined otherwise
167
+ */
168
+ export declare function placePostOnlySellOrder(params: Omit<PlaceOrderParams, 'side' | 'fillMode'>): Promise<bigint | undefined>;
@@ -0,0 +1,133 @@
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.placeNewOrder = placeNewOrder;
7
+ exports.cancelExistingOrder = cancelExistingOrder;
8
+ exports.placeMarketBuyOrder = placeMarketBuyOrder;
9
+ exports.placeMarketSellOrder = placeMarketSellOrder;
10
+ exports.placeLimitBuyOrder = placeLimitBuyOrder;
11
+ exports.placeLimitSellOrder = placeLimitSellOrder;
12
+ exports.placePostOnlyBuyOrder = placePostOnlyBuyOrder;
13
+ exports.placePostOnlySellOrder = placePostOnlySellOrder;
14
+ const decimal_js_1 = __importDefault(require("decimal.js"));
15
+ const actions_1 = require("./actions");
16
+ const types_1 = require("../../types");
17
+ /**
18
+ * Places a new order
19
+ *
20
+ * @param params - Parameters for placing an order
21
+ * @returns The order ID if successful, undefined otherwise
22
+ */
23
+ async function placeNewOrder(params) {
24
+ return (0, actions_1.placeOrder)(params.serverUrl, params.signFn, params.currentTimestamp, params.nonce, {
25
+ sessionId: params.sessionId,
26
+ senderId: params.senderId,
27
+ sizeDecimals: params.sizeDecimals,
28
+ priceDecimals: params.priceDecimals,
29
+ marketId: params.marketId,
30
+ side: params.side,
31
+ fillMode: params.fillMode || types_1.FillMode.Limit,
32
+ isReduceOnly: params.isReduceOnly || false,
33
+ size: new decimal_js_1.default(params.size),
34
+ price: new decimal_js_1.default(params.price),
35
+ quoteSize: params.quoteSize ? new decimal_js_1.default(params.quoteSize) : undefined,
36
+ liquidateeId: params.liquidateeId,
37
+ clientOrderId: params.clientOrderId,
38
+ });
39
+ }
40
+ /**
41
+ * Cancels an existing order
42
+ *
43
+ * @param params - Parameters for canceling an order
44
+ * @returns The canceled order ID if successful
45
+ */
46
+ async function cancelExistingOrder(params) {
47
+ return (0, actions_1.cancelOrder)(params.serverUrl, params.signFn, params.currentTimestamp, params.nonce, {
48
+ sessionId: params.sessionId,
49
+ senderId: params.senderId,
50
+ orderId: params.orderId,
51
+ liquidateeId: params.liquidateeId,
52
+ });
53
+ }
54
+ /**
55
+ * Places a market buy order
56
+ *
57
+ * @param params - Parameters for placing an order (without price)
58
+ * @returns The order ID if successful, undefined otherwise
59
+ */
60
+ async function placeMarketBuyOrder(params) {
61
+ return placeNewOrder({
62
+ ...params,
63
+ side: types_1.Side.Bid,
64
+ fillMode: types_1.FillMode.ImmediateOrCancel,
65
+ price: '999999999', // Use a very high price to ensure it executes as a market order
66
+ });
67
+ }
68
+ /**
69
+ * Places a market sell order
70
+ *
71
+ * @param params - Parameters for placing an order (without price)
72
+ * @returns The order ID if successful, undefined otherwise
73
+ */
74
+ async function placeMarketSellOrder(params) {
75
+ return placeNewOrder({
76
+ ...params,
77
+ side: types_1.Side.Ask,
78
+ fillMode: types_1.FillMode.ImmediateOrCancel,
79
+ price: '0.000001', // Use a very low price to ensure it executes as a market order
80
+ });
81
+ }
82
+ /**
83
+ * Places a limit buy order
84
+ *
85
+ * @param params - Parameters for placing an order
86
+ * @returns The order ID if successful, undefined otherwise
87
+ */
88
+ async function placeLimitBuyOrder(params) {
89
+ return placeNewOrder({
90
+ ...params,
91
+ side: types_1.Side.Bid,
92
+ fillMode: types_1.FillMode.Limit,
93
+ });
94
+ }
95
+ /**
96
+ * Places a limit sell order
97
+ *
98
+ * @param params - Parameters for placing an order
99
+ * @returns The order ID if successful, undefined otherwise
100
+ */
101
+ async function placeLimitSellOrder(params) {
102
+ return placeNewOrder({
103
+ ...params,
104
+ side: types_1.Side.Ask,
105
+ fillMode: types_1.FillMode.Limit,
106
+ });
107
+ }
108
+ /**
109
+ * Places a post-only buy order
110
+ *
111
+ * @param params - Parameters for placing an order
112
+ * @returns The order ID if successful, undefined otherwise
113
+ */
114
+ async function placePostOnlyBuyOrder(params) {
115
+ return placeNewOrder({
116
+ ...params,
117
+ side: types_1.Side.Bid,
118
+ fillMode: types_1.FillMode.PostOnly,
119
+ });
120
+ }
121
+ /**
122
+ * Places a post-only sell order
123
+ *
124
+ * @param params - Parameters for placing an order
125
+ * @returns The order ID if successful, undefined otherwise
126
+ */
127
+ async function placePostOnlySellOrder(params) {
128
+ return placeNewOrder({
129
+ ...params,
130
+ side: types_1.Side.Ask,
131
+ fillMode: types_1.FillMode.PostOnly,
132
+ });
133
+ }
@@ -0,0 +1,81 @@
1
+ import { ActionQuery, ActionResponse, ActionsResponse, BlockQuery, BlockResponse, BlockSummaryResponse, RollmanActionResponse, RollmanActionsResponse, RollmanBlockResponse } from '../../types';
2
+ /**
3
+ * Query a specific block
4
+ *
5
+ * @param webServerUrl - Base URL for the Nord web server
6
+ * @param query - Block query parameters
7
+ * @returns Block response
8
+ * @throws {NordError} If the request fails
9
+ */
10
+ export declare function queryBlock(webServerUrl: string, query: BlockQuery): Promise<BlockResponse>;
11
+ /**
12
+ * Query the last N blocks
13
+ *
14
+ * @param webServerUrl - Base URL for the Nord web server
15
+ * @returns Block response for the last N blocks
16
+ * @throws {NordError} If the request fails
17
+ */
18
+ export declare function queryLastNBlocks(webServerUrl: string): Promise<BlockResponse>;
19
+ /**
20
+ * Query recent blocks
21
+ *
22
+ * @param webServerUrl - Base URL for the Nord web server
23
+ * @param last_n - Number of recent blocks to query
24
+ * @returns Block summary response
25
+ * @throws {NordError} If the request fails
26
+ */
27
+ export declare function queryRecentBlocks(webServerUrl: string, last_n: number): Promise<BlockSummaryResponse>;
28
+ /**
29
+ * Query a specific action
30
+ *
31
+ * @param webServerUrl - Base URL for the Nord web server
32
+ * @param query - Action query parameters
33
+ * @returns Action response
34
+ * @throws {NordError} If the request fails
35
+ */
36
+ export declare function queryAction(webServerUrl: string, query: ActionQuery): Promise<ActionResponse>;
37
+ /**
38
+ * Query recent actions
39
+ *
40
+ * @param webServerUrl - Base URL for the Nord web server
41
+ * @param last_n - Number of recent actions to query
42
+ * @returns Actions response
43
+ * @throws {NordError} If the request fails
44
+ */
45
+ export declare function queryRecentActions(webServerUrl: string, last_n: number): Promise<ActionsResponse>;
46
+ /**
47
+ * Query a block from Rollman
48
+ *
49
+ * @param webServerUrl - Base URL for the Nord web server
50
+ * @param query - Block query parameters
51
+ * @returns Rollman block response
52
+ * @throws {NordError} If the request fails
53
+ */
54
+ export declare function blockQueryRollman(webServerUrl: string, query: BlockQuery): Promise<RollmanBlockResponse>;
55
+ /**
56
+ * Query block summaries from Rollman
57
+ *
58
+ * @param webServerUrl - Base URL for the Nord web server
59
+ * @param last_n - Number of recent blocks to query
60
+ * @returns Block summary response
61
+ * @throws {NordError} If the request fails
62
+ */
63
+ export declare function blockSummaryQueryRollman(webServerUrl: string, last_n: number): Promise<BlockSummaryResponse>;
64
+ /**
65
+ * Query an action from Rollman
66
+ *
67
+ * @param webServerUrl - Base URL for the Nord web server
68
+ * @param query - Action query parameters
69
+ * @returns Rollman action response
70
+ * @throws {NordError} If the request fails
71
+ */
72
+ export declare function actionQueryRollman(webServerUrl: string, query: ActionQuery): Promise<RollmanActionResponse>;
73
+ /**
74
+ * Query actions from Rollman
75
+ *
76
+ * @param webServerUrl - Base URL for the Nord web server
77
+ * @param last_n - Number of recent actions to query
78
+ * @returns Rollman actions response
79
+ * @throws {NordError} If the request fails
80
+ */
81
+ export declare function actionsQueryRollman(webServerUrl: string, last_n: number): Promise<RollmanActionsResponse>;