@pythnetwork/hermes-client 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/cjs/hermes-client.cjs +220 -0
- package/{lib/HermesClient.d.ts → dist/cjs/hermes-client.d.ts} +15 -16
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/utils.cjs +22 -0
- package/{lib → dist/cjs}/utils.d.ts +0 -1
- package/dist/cjs/zodSchemas.cjs +351 -0
- package/{lib → dist/cjs}/zodSchemas.d.ts +6 -7
- package/dist/esm/hermes-client.d.ts +158 -0
- package/dist/esm/hermes-client.mjs +210 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.mjs +12 -0
- package/dist/esm/zodSchemas.d.ts +4952 -0
- package/{lib/zodSchemas.js → dist/esm/zodSchemas.mjs} +126 -118
- package/package.json +70 -23
- package/lib/HermesClient.d.ts.map +0 -1
- package/lib/HermesClient.js +0 -216
- package/lib/examples/HermesClient.d.ts +0 -2
- package/lib/examples/HermesClient.d.ts.map +0 -1
- package/lib/examples/HermesClient.js +0 -86
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -13
- package/lib/zodSchemas.d.ts.map +0 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get api () {
|
|
13
|
+
return api;
|
|
14
|
+
},
|
|
15
|
+
get createApiClient () {
|
|
16
|
+
return createApiClient;
|
|
17
|
+
},
|
|
18
|
+
get schemas () {
|
|
19
|
+
return schemas;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _core = require("@zodios/core");
|
|
23
|
+
const _zod = require("zod");
|
|
24
|
+
const AssetType = _zod.z.enum([
|
|
25
|
+
"crypto",
|
|
26
|
+
"fx",
|
|
27
|
+
"equity",
|
|
28
|
+
"metal",
|
|
29
|
+
"rates",
|
|
30
|
+
"crypto_redemption_rate",
|
|
31
|
+
"commodities",
|
|
32
|
+
"crypto_index",
|
|
33
|
+
"crypto_nav"
|
|
34
|
+
]);
|
|
35
|
+
const asset_type = AssetType.nullish();
|
|
36
|
+
const RpcPriceIdentifier = _zod.z.string();
|
|
37
|
+
const PriceFeedMetadata = _zod.z.object({
|
|
38
|
+
attributes: _zod.z.record(_zod.z.string()),
|
|
39
|
+
id: RpcPriceIdentifier
|
|
40
|
+
}).passthrough();
|
|
41
|
+
const PriceIdInput = _zod.z.string();
|
|
42
|
+
const EncodingType = _zod.z.enum([
|
|
43
|
+
"hex",
|
|
44
|
+
"base64"
|
|
45
|
+
]);
|
|
46
|
+
const BinaryUpdate = _zod.z.object({
|
|
47
|
+
data: _zod.z.array(_zod.z.string()),
|
|
48
|
+
encoding: EncodingType
|
|
49
|
+
}).passthrough();
|
|
50
|
+
const RpcPrice = _zod.z.object({
|
|
51
|
+
conf: _zod.z.string(),
|
|
52
|
+
expo: _zod.z.number().int(),
|
|
53
|
+
price: _zod.z.string(),
|
|
54
|
+
publish_time: _zod.z.number().int()
|
|
55
|
+
}).passthrough();
|
|
56
|
+
const RpcPriceFeedMetadataV2 = _zod.z.object({
|
|
57
|
+
prev_publish_time: _zod.z.number().int().nullable(),
|
|
58
|
+
proof_available_time: _zod.z.number().int().nullable(),
|
|
59
|
+
slot: _zod.z.number().int().gte(0).nullable()
|
|
60
|
+
}).partial().passthrough();
|
|
61
|
+
const ParsedPriceUpdate = _zod.z.object({
|
|
62
|
+
ema_price: RpcPrice,
|
|
63
|
+
id: RpcPriceIdentifier,
|
|
64
|
+
metadata: RpcPriceFeedMetadataV2,
|
|
65
|
+
price: RpcPrice
|
|
66
|
+
}).passthrough();
|
|
67
|
+
const PriceUpdate = _zod.z.object({
|
|
68
|
+
binary: BinaryUpdate,
|
|
69
|
+
parsed: _zod.z.array(ParsedPriceUpdate).nullish()
|
|
70
|
+
}).passthrough();
|
|
71
|
+
const ParsedPublisherStakeCap = _zod.z.object({
|
|
72
|
+
cap: _zod.z.number().int().gte(0),
|
|
73
|
+
publisher: _zod.z.string()
|
|
74
|
+
}).passthrough();
|
|
75
|
+
const ParsedPublisherStakeCapsUpdate = _zod.z.object({
|
|
76
|
+
publisher_stake_caps: _zod.z.array(ParsedPublisherStakeCap)
|
|
77
|
+
}).passthrough();
|
|
78
|
+
const LatestPublisherStakeCapsUpdateDataResponse = _zod.z.object({
|
|
79
|
+
binary: BinaryUpdate,
|
|
80
|
+
parsed: _zod.z.array(ParsedPublisherStakeCapsUpdate).nullish()
|
|
81
|
+
}).passthrough();
|
|
82
|
+
const ParsedPriceFeedTwap = _zod.z.object({
|
|
83
|
+
down_slots_ratio: _zod.z.string(),
|
|
84
|
+
end_timestamp: _zod.z.number().int(),
|
|
85
|
+
id: RpcPriceIdentifier,
|
|
86
|
+
start_timestamp: _zod.z.number().int(),
|
|
87
|
+
twap: RpcPrice
|
|
88
|
+
}).passthrough();
|
|
89
|
+
const TwapsResponse = _zod.z.object({
|
|
90
|
+
binary: BinaryUpdate,
|
|
91
|
+
parsed: _zod.z.array(ParsedPriceFeedTwap).nullish()
|
|
92
|
+
}).passthrough();
|
|
93
|
+
const schemas = {
|
|
94
|
+
AssetType,
|
|
95
|
+
asset_type,
|
|
96
|
+
RpcPriceIdentifier,
|
|
97
|
+
PriceFeedMetadata,
|
|
98
|
+
PriceIdInput,
|
|
99
|
+
EncodingType,
|
|
100
|
+
BinaryUpdate,
|
|
101
|
+
RpcPrice,
|
|
102
|
+
RpcPriceFeedMetadataV2,
|
|
103
|
+
ParsedPriceUpdate,
|
|
104
|
+
PriceUpdate,
|
|
105
|
+
ParsedPublisherStakeCap,
|
|
106
|
+
ParsedPublisherStakeCapsUpdate,
|
|
107
|
+
LatestPublisherStakeCapsUpdateDataResponse,
|
|
108
|
+
ParsedPriceFeedTwap,
|
|
109
|
+
TwapsResponse
|
|
110
|
+
};
|
|
111
|
+
const endpoints = (0, _core.makeApi)([
|
|
112
|
+
{
|
|
113
|
+
method: "get",
|
|
114
|
+
path: "/v2/price_feeds",
|
|
115
|
+
alias: "price_feeds_metadata",
|
|
116
|
+
description: `Get the set of price feeds.
|
|
117
|
+
|
|
118
|
+
This endpoint fetches all price feeds from the Pyth network. It can be filtered by asset type
|
|
119
|
+
and query string.`,
|
|
120
|
+
requestFormat: "json",
|
|
121
|
+
parameters: [
|
|
122
|
+
{
|
|
123
|
+
name: "query",
|
|
124
|
+
type: "Query",
|
|
125
|
+
schema: _zod.z.string().nullish()
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "asset_type",
|
|
129
|
+
type: "Query",
|
|
130
|
+
schema: asset_type
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
response: _zod.z.array(PriceFeedMetadata)
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
method: "get",
|
|
137
|
+
path: "/v2/updates/price/:publish_time",
|
|
138
|
+
alias: "timestamp_price_updates",
|
|
139
|
+
description: `Get the latest price updates by price feed id.
|
|
140
|
+
|
|
141
|
+
Given a collection of price feed ids, retrieve the latest Pyth price for each price feed.`,
|
|
142
|
+
requestFormat: "json",
|
|
143
|
+
parameters: [
|
|
144
|
+
{
|
|
145
|
+
name: "publish_time",
|
|
146
|
+
type: "Path",
|
|
147
|
+
schema: _zod.z.number().int()
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "ids[]",
|
|
151
|
+
type: "Query",
|
|
152
|
+
schema: _zod.z.array(PriceIdInput)
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "encoding",
|
|
156
|
+
type: "Query",
|
|
157
|
+
schema: _zod.z.enum([
|
|
158
|
+
"hex",
|
|
159
|
+
"base64"
|
|
160
|
+
]).optional()
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "parsed",
|
|
164
|
+
type: "Query",
|
|
165
|
+
schema: _zod.z.boolean().optional()
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "ignore_invalid_price_ids",
|
|
169
|
+
type: "Query",
|
|
170
|
+
schema: _zod.z.boolean().optional()
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
response: PriceUpdate,
|
|
174
|
+
errors: [
|
|
175
|
+
{
|
|
176
|
+
status: 404,
|
|
177
|
+
description: `Price ids not found`,
|
|
178
|
+
schema: _zod.z.void()
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
method: "get",
|
|
184
|
+
path: "/v2/updates/price/latest",
|
|
185
|
+
alias: "latest_price_updates",
|
|
186
|
+
description: `Get the latest price updates by price feed id.
|
|
187
|
+
|
|
188
|
+
Given a collection of price feed ids, retrieve the latest Pyth price for each price feed.`,
|
|
189
|
+
requestFormat: "json",
|
|
190
|
+
parameters: [
|
|
191
|
+
{
|
|
192
|
+
name: "ids[]",
|
|
193
|
+
type: "Query",
|
|
194
|
+
schema: _zod.z.array(PriceIdInput)
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "encoding",
|
|
198
|
+
type: "Query",
|
|
199
|
+
schema: _zod.z.enum([
|
|
200
|
+
"hex",
|
|
201
|
+
"base64"
|
|
202
|
+
]).optional()
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "parsed",
|
|
206
|
+
type: "Query",
|
|
207
|
+
schema: _zod.z.boolean().optional()
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "ignore_invalid_price_ids",
|
|
211
|
+
type: "Query",
|
|
212
|
+
schema: _zod.z.boolean().optional()
|
|
213
|
+
}
|
|
214
|
+
],
|
|
215
|
+
response: PriceUpdate,
|
|
216
|
+
errors: [
|
|
217
|
+
{
|
|
218
|
+
status: 404,
|
|
219
|
+
description: `Price ids not found`,
|
|
220
|
+
schema: _zod.z.void()
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
method: "get",
|
|
226
|
+
path: "/v2/updates/price/stream",
|
|
227
|
+
alias: "price_stream_sse_handler",
|
|
228
|
+
description: `SSE route handler for streaming price updates.
|
|
229
|
+
|
|
230
|
+
The connection will automatically close after 24 hours to prevent resource leaks.
|
|
231
|
+
Clients should implement reconnection logic to maintain continuous price updates.`,
|
|
232
|
+
requestFormat: "json",
|
|
233
|
+
parameters: [
|
|
234
|
+
{
|
|
235
|
+
name: "ids[]",
|
|
236
|
+
type: "Query",
|
|
237
|
+
schema: _zod.z.array(PriceIdInput)
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "encoding",
|
|
241
|
+
type: "Query",
|
|
242
|
+
schema: _zod.z.enum([
|
|
243
|
+
"hex",
|
|
244
|
+
"base64"
|
|
245
|
+
]).optional()
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: "parsed",
|
|
249
|
+
type: "Query",
|
|
250
|
+
schema: _zod.z.boolean().optional()
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: "allow_unordered",
|
|
254
|
+
type: "Query",
|
|
255
|
+
schema: _zod.z.boolean().optional()
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "benchmarks_only",
|
|
259
|
+
type: "Query",
|
|
260
|
+
schema: _zod.z.boolean().optional()
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: "ignore_invalid_price_ids",
|
|
264
|
+
type: "Query",
|
|
265
|
+
schema: _zod.z.boolean().optional()
|
|
266
|
+
}
|
|
267
|
+
],
|
|
268
|
+
response: PriceUpdate,
|
|
269
|
+
errors: [
|
|
270
|
+
{
|
|
271
|
+
status: 404,
|
|
272
|
+
description: `Price ids not found`,
|
|
273
|
+
schema: _zod.z.void()
|
|
274
|
+
}
|
|
275
|
+
]
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
method: "get",
|
|
279
|
+
path: "/v2/updates/publisher_stake_caps/latest",
|
|
280
|
+
alias: "latest_publisher_stake_caps",
|
|
281
|
+
description: `Get the most recent publisher stake caps update data.`,
|
|
282
|
+
requestFormat: "json",
|
|
283
|
+
parameters: [
|
|
284
|
+
{
|
|
285
|
+
name: "encoding",
|
|
286
|
+
type: "Query",
|
|
287
|
+
schema: _zod.z.enum([
|
|
288
|
+
"hex",
|
|
289
|
+
"base64"
|
|
290
|
+
]).optional()
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "parsed",
|
|
294
|
+
type: "Query",
|
|
295
|
+
schema: _zod.z.boolean().optional()
|
|
296
|
+
}
|
|
297
|
+
],
|
|
298
|
+
response: LatestPublisherStakeCapsUpdateDataResponse
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
method: "get",
|
|
302
|
+
path: "/v2/updates/twap/:window_seconds/latest",
|
|
303
|
+
alias: "latest_twaps",
|
|
304
|
+
description: `Get the latest TWAP by price feed id with a custom time window.
|
|
305
|
+
|
|
306
|
+
Given a collection of price feed ids, retrieve the latest Pyth TWAP price for each price feed.`,
|
|
307
|
+
requestFormat: "json",
|
|
308
|
+
parameters: [
|
|
309
|
+
{
|
|
310
|
+
name: "window_seconds",
|
|
311
|
+
type: "Path",
|
|
312
|
+
schema: _zod.z.number().int().gte(0)
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "ids[]",
|
|
316
|
+
type: "Query",
|
|
317
|
+
schema: _zod.z.array(PriceIdInput)
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "encoding",
|
|
321
|
+
type: "Query",
|
|
322
|
+
schema: _zod.z.enum([
|
|
323
|
+
"hex",
|
|
324
|
+
"base64"
|
|
325
|
+
]).optional()
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
name: "parsed",
|
|
329
|
+
type: "Query",
|
|
330
|
+
schema: _zod.z.boolean().optional()
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
name: "ignore_invalid_price_ids",
|
|
334
|
+
type: "Query",
|
|
335
|
+
schema: _zod.z.boolean().optional()
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
response: TwapsResponse,
|
|
339
|
+
errors: [
|
|
340
|
+
{
|
|
341
|
+
status: 404,
|
|
342
|
+
description: `Price ids not found`,
|
|
343
|
+
schema: _zod.z.void()
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
}
|
|
347
|
+
]);
|
|
348
|
+
const api = new _core.Zodios(endpoints);
|
|
349
|
+
function createApiClient(baseUrl, options) {
|
|
350
|
+
return new _core.Zodios(baseUrl, endpoints, options);
|
|
351
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ZodiosOptions } from "@zodios/core";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
export declare const schemas: {
|
|
4
|
-
AssetType: z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate"]>;
|
|
5
|
-
asset_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate"]>>>;
|
|
4
|
+
AssetType: z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate", "commodities", "crypto_index", "crypto_nav"]>;
|
|
5
|
+
asset_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate", "commodities", "crypto_index", "crypto_nav"]>>>;
|
|
6
6
|
RpcPriceIdentifier: z.ZodString;
|
|
7
7
|
PriceFeedMetadata: z.ZodObject<{
|
|
8
8
|
attributes: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
@@ -1141,7 +1141,7 @@ export declare const api: import("@zodios/core").ZodiosInstance<[{
|
|
|
1141
1141
|
}, {
|
|
1142
1142
|
name: "asset_type";
|
|
1143
1143
|
type: "Query";
|
|
1144
|
-
schema: z.ZodOptional<z.ZodNullable<z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate"]>>>;
|
|
1144
|
+
schema: z.ZodOptional<z.ZodNullable<z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate", "commodities", "crypto_index", "crypto_nav"]>>>;
|
|
1145
1145
|
}];
|
|
1146
1146
|
response: z.ZodArray<z.ZodObject<{
|
|
1147
1147
|
attributes: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
@@ -2137,7 +2137,7 @@ export declare const api: import("@zodios/core").ZodiosInstance<[{
|
|
|
2137
2137
|
method: "get";
|
|
2138
2138
|
path: "/v2/updates/price/stream";
|
|
2139
2139
|
alias: "price_stream_sse_handler";
|
|
2140
|
-
description: "SSE route handler for streaming price updates.";
|
|
2140
|
+
description: "SSE route handler for streaming price updates.\n\nThe connection will automatically close after 24 hours to prevent resource leaks.\nClients should implement reconnection logic to maintain continuous price updates.";
|
|
2141
2141
|
requestFormat: "json";
|
|
2142
2142
|
parameters: [{
|
|
2143
2143
|
name: "ids[]";
|
|
@@ -3052,7 +3052,7 @@ export declare function createApiClient(baseUrl: string, options?: ZodiosOptions
|
|
|
3052
3052
|
}, {
|
|
3053
3053
|
name: "asset_type";
|
|
3054
3054
|
type: "Query";
|
|
3055
|
-
schema: z.ZodOptional<z.ZodNullable<z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate"]>>>;
|
|
3055
|
+
schema: z.ZodOptional<z.ZodNullable<z.ZodEnum<["crypto", "fx", "equity", "metal", "rates", "crypto_redemption_rate", "commodities", "crypto_index", "crypto_nav"]>>>;
|
|
3056
3056
|
}];
|
|
3057
3057
|
response: z.ZodArray<z.ZodObject<{
|
|
3058
3058
|
attributes: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
@@ -4048,7 +4048,7 @@ export declare function createApiClient(baseUrl: string, options?: ZodiosOptions
|
|
|
4048
4048
|
method: "get";
|
|
4049
4049
|
path: "/v2/updates/price/stream";
|
|
4050
4050
|
alias: "price_stream_sse_handler";
|
|
4051
|
-
description: "SSE route handler for streaming price updates.";
|
|
4051
|
+
description: "SSE route handler for streaming price updates.\n\nThe connection will automatically close after 24 hours to prevent resource leaks.\nClients should implement reconnection logic to maintain continuous price updates.";
|
|
4052
4052
|
requestFormat: "json";
|
|
4053
4053
|
parameters: [{
|
|
4054
4054
|
name: "ids[]";
|
|
@@ -4950,4 +4950,3 @@ export declare function createApiClient(baseUrl: string, options?: ZodiosOptions
|
|
|
4950
4950
|
schema: z.ZodVoid;
|
|
4951
4951
|
}];
|
|
4952
4952
|
}]>;
|
|
4953
|
-
//# sourceMappingURL=zodSchemas.d.ts.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { EventSource } from "eventsource";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { schemas } from "./zodSchemas.js";
|
|
4
|
+
export type AssetType = z.infer<typeof schemas.AssetType>;
|
|
5
|
+
export type BinaryPriceUpdate = z.infer<typeof schemas.BinaryUpdate>;
|
|
6
|
+
export type EncodingType = z.infer<typeof schemas.EncodingType>;
|
|
7
|
+
export type PriceFeedMetadata = z.infer<typeof schemas.PriceFeedMetadata>;
|
|
8
|
+
export type PriceIdInput = z.infer<typeof schemas.PriceIdInput>;
|
|
9
|
+
export type PriceUpdate = z.infer<typeof schemas.PriceUpdate>;
|
|
10
|
+
export type TwapsResponse = z.infer<typeof schemas.TwapsResponse>;
|
|
11
|
+
export type PublisherCaps = z.infer<typeof schemas.LatestPublisherStakeCapsUpdateDataResponse>;
|
|
12
|
+
export type UnixTimestamp = number;
|
|
13
|
+
export type DurationInSeconds = number;
|
|
14
|
+
export type HexString = string;
|
|
15
|
+
export type DurationInMs = number;
|
|
16
|
+
export type HermesClientConfig = {
|
|
17
|
+
timeout?: DurationInMs;
|
|
18
|
+
/**
|
|
19
|
+
* Number of times a HTTP request will be retried before the API returns a failure. Default: 3.
|
|
20
|
+
*
|
|
21
|
+
* The connection uses exponential back-off for the delay between retries. However,
|
|
22
|
+
* it will timeout regardless of the retries at the configured `timeout` time.
|
|
23
|
+
*/
|
|
24
|
+
httpRetries?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Optional headers to be included in every request.
|
|
27
|
+
*/
|
|
28
|
+
headers?: HeadersInit;
|
|
29
|
+
};
|
|
30
|
+
export declare class HermesClient {
|
|
31
|
+
private baseURL;
|
|
32
|
+
private timeout;
|
|
33
|
+
private httpRetries;
|
|
34
|
+
private headers;
|
|
35
|
+
/**
|
|
36
|
+
* Constructs a new Connection.
|
|
37
|
+
*
|
|
38
|
+
* @param endpoint - endpoint URL to the price service. Example: https://website/example/
|
|
39
|
+
* @param config - Optional HermesClientConfig for custom configurations.
|
|
40
|
+
*/
|
|
41
|
+
constructor(endpoint: string, config?: HermesClientConfig);
|
|
42
|
+
private httpRequest;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch the set of available price feeds.
|
|
45
|
+
* This endpoint can be filtered by asset type and query string.
|
|
46
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
47
|
+
*
|
|
48
|
+
* @param options - Optional parameters:
|
|
49
|
+
* - query: String to filter the price feeds. If provided, the results will be filtered to all price feeds whose symbol contains the query string. Query string is case insensitive. Example: "bitcoin".
|
|
50
|
+
* - assetType: String to filter the price feeds by asset type. Possible values are "crypto", "equity", "fx", "metal", "rates", "crypto_redemption_rate". Filter string is case insensitive.
|
|
51
|
+
*
|
|
52
|
+
* @returns Array of PriceFeedMetadata objects.
|
|
53
|
+
*/
|
|
54
|
+
getPriceFeeds({ fetchOptions, ...options }?: {
|
|
55
|
+
query?: string;
|
|
56
|
+
assetType?: AssetType;
|
|
57
|
+
fetchOptions?: RequestInit;
|
|
58
|
+
}): Promise<PriceFeedMetadata[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Fetch the latest publisher stake caps.
|
|
61
|
+
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed publisher caps.
|
|
62
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
63
|
+
*
|
|
64
|
+
* @param options - Optional parameters:
|
|
65
|
+
* - encoding: Encoding type. If specified, return the publisher caps in the encoding specified by the encoding parameter. Default is hex.
|
|
66
|
+
* - parsed: Boolean to specify if the parsed publisher caps should be included in the response. Default is false.
|
|
67
|
+
*
|
|
68
|
+
* @returns PublisherCaps object containing the latest publisher stake caps.
|
|
69
|
+
*/
|
|
70
|
+
getLatestPublisherCaps({ fetchOptions, ...options }?: {
|
|
71
|
+
encoding?: EncodingType;
|
|
72
|
+
parsed?: boolean;
|
|
73
|
+
fetchOptions?: RequestInit;
|
|
74
|
+
}): Promise<PublisherCaps>;
|
|
75
|
+
/**
|
|
76
|
+
* Fetch the latest price updates for a set of price feed IDs.
|
|
77
|
+
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed price update using the options object.
|
|
78
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
79
|
+
*
|
|
80
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
81
|
+
* @param options - Optional parameters:
|
|
82
|
+
* - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
|
|
83
|
+
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
84
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
85
|
+
*
|
|
86
|
+
* @returns PriceUpdate object containing the latest updates.
|
|
87
|
+
*/
|
|
88
|
+
getLatestPriceUpdates(ids: HexString[], options?: {
|
|
89
|
+
encoding?: EncodingType;
|
|
90
|
+
parsed?: boolean;
|
|
91
|
+
ignoreInvalidPriceIds?: boolean;
|
|
92
|
+
}, fetchOptions?: RequestInit): Promise<PriceUpdate>;
|
|
93
|
+
/**
|
|
94
|
+
* Fetch the price updates for a set of price feed IDs at a given timestamp.
|
|
95
|
+
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed price update.
|
|
96
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
97
|
+
*
|
|
98
|
+
* @param publishTime - Unix timestamp in seconds.
|
|
99
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
100
|
+
* @param options - Optional parameters:
|
|
101
|
+
* - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
|
|
102
|
+
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
103
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
104
|
+
*
|
|
105
|
+
* @returns PriceUpdate object containing the updates at the specified timestamp.
|
|
106
|
+
*/
|
|
107
|
+
getPriceUpdatesAtTimestamp(publishTime: UnixTimestamp, ids: HexString[], options?: {
|
|
108
|
+
encoding?: EncodingType;
|
|
109
|
+
parsed?: boolean;
|
|
110
|
+
ignoreInvalidPriceIds?: boolean;
|
|
111
|
+
}, fetchOptions?: RequestInit): Promise<PriceUpdate>;
|
|
112
|
+
/**
|
|
113
|
+
* Fetch streaming price updates for a set of price feed IDs.
|
|
114
|
+
* This endpoint can be customized by specifying the encoding type, whether the results should include parsed updates,
|
|
115
|
+
* and if unordered updates or only benchmark updates are allowed.
|
|
116
|
+
* This will return an EventSource that can be used to listen to streaming updates.
|
|
117
|
+
* If an invalid hex-encoded ID is passed, it will throw an error.
|
|
118
|
+
*
|
|
119
|
+
* @param ids - Array of hex-encoded price feed IDs for which streaming updates are requested.
|
|
120
|
+
* @param options - Optional parameters:
|
|
121
|
+
* - encoding: Encoding type. If specified, updates are returned in the specified encoding. Default is hex.
|
|
122
|
+
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
123
|
+
* - allowUnordered: Boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
|
|
124
|
+
* - benchmarksOnly: Boolean to specify if only benchmark prices should be returned. Default is false.
|
|
125
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
126
|
+
*
|
|
127
|
+
* @returns An EventSource instance for receiving streaming updates.
|
|
128
|
+
*/
|
|
129
|
+
getPriceUpdatesStream(ids: HexString[], options?: {
|
|
130
|
+
encoding?: EncodingType;
|
|
131
|
+
parsed?: boolean;
|
|
132
|
+
allowUnordered?: boolean;
|
|
133
|
+
benchmarksOnly?: boolean;
|
|
134
|
+
ignoreInvalidPriceIds?: boolean;
|
|
135
|
+
}): Promise<EventSource>;
|
|
136
|
+
/**
|
|
137
|
+
* Fetch the latest TWAP (time weighted average price) for a set of price feed IDs.
|
|
138
|
+
* This endpoint can be customized by specifying the encoding type and whether the results should also return the calculated TWAP using the options object.
|
|
139
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
140
|
+
*
|
|
141
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
142
|
+
* @param window_seconds - The time window in seconds over which to calculate the TWAP, ending at the current time.
|
|
143
|
+
* For example, a value of 300 would return the most recent 5 minute TWAP. Must be greater than 0 and less than or equal to 600 seconds (10 minutes).
|
|
144
|
+
* @param options - Optional parameters:
|
|
145
|
+
* - encoding: Encoding type. If specified, return the TWAP binary data in the encoding specified by the encoding parameter. Default is hex.
|
|
146
|
+
* - parsed: Boolean to specify if the calculated TWAP should be included in the response. Default is false.
|
|
147
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
148
|
+
*
|
|
149
|
+
* @returns TwapsResponse object containing the latest TWAPs.
|
|
150
|
+
*/
|
|
151
|
+
getLatestTwaps(ids: HexString[], window_seconds: number, options?: {
|
|
152
|
+
encoding?: EncodingType;
|
|
153
|
+
parsed?: boolean;
|
|
154
|
+
ignoreInvalidPriceIds?: boolean;
|
|
155
|
+
}, fetchOptions?: RequestInit): Promise<TwapsResponse>;
|
|
156
|
+
private appendUrlSearchParams;
|
|
157
|
+
private buildURL;
|
|
158
|
+
}
|