@pythnetwork/hermes-client 2.0.0 → 3.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 +209 -0
- package/{lib/HermesClient.d.ts → dist/cjs/hermes-client.d.ts} +20 -34
- 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 +293 -0
- package/{lib → dist/cjs}/zodSchemas.d.ts +20 -827
- package/dist/esm/hermes-client.d.ts +145 -0
- package/dist/esm/hermes-client.mjs +199 -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 +4146 -0
- package/dist/esm/zodSchemas.mjs +272 -0
- 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
- package/lib/zodSchemas.js +0 -322
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@ This library is a client for interacting with Hermes, allowing your application
|
|
|
9
9
|
### npm
|
|
10
10
|
|
|
11
11
|
```
|
|
12
|
-
|
|
12
|
+
npm install --save @pythnetwork/hermes-client
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Yarn
|
|
16
16
|
|
|
17
17
|
```
|
|
18
|
-
|
|
18
|
+
yarn add @pythnetwork/hermes-client
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Quickstart
|
|
@@ -76,11 +76,12 @@ The [HermesClient](./src/examples/HermesClient.ts) example demonstrates both the
|
|
|
76
76
|
examples above. To run the example:
|
|
77
77
|
|
|
78
78
|
1. Clone [the Pyth monorepo](https://github.com/pyth-network/pyth-crosschain)
|
|
79
|
-
2. In the root of the monorepo, run `pnpm
|
|
80
|
-
example, to print BTC and
|
|
79
|
+
2. In the root of the monorepo, run `pnpm turbo --filter
|
|
80
|
+
@pythnetwork/hermes-client example -- <args>`. For example, to print BTC and
|
|
81
|
+
ETH price feeds in the testnet network, run:
|
|
81
82
|
|
|
82
83
|
```bash
|
|
83
|
-
pnpm
|
|
84
|
+
pnpm turbo --filter @pythnetwork/hermes-client example -- \
|
|
84
85
|
--endpoint https://hermes.pyth.network \
|
|
85
86
|
--price-ids \
|
|
86
87
|
0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 \
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-misused-spread */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ "use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "HermesClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return HermesClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _eventsource = require("eventsource");
|
|
12
|
+
const _utils = require("./utils.cjs");
|
|
13
|
+
const _zodSchemas = require("./zodSchemas.cjs");
|
|
14
|
+
const DEFAULT_TIMEOUT = 5000;
|
|
15
|
+
const DEFAULT_HTTP_RETRIES = 3;
|
|
16
|
+
class HermesClient {
|
|
17
|
+
baseURL;
|
|
18
|
+
timeout;
|
|
19
|
+
httpRetries;
|
|
20
|
+
headers;
|
|
21
|
+
accessToken;
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a new Connection.
|
|
24
|
+
*
|
|
25
|
+
* @param endpoint - endpoint URL to the price service. Example: https://website/example/
|
|
26
|
+
* @param config - Optional HermesClientConfig for custom configurations.
|
|
27
|
+
*/ constructor(endpoint, config){
|
|
28
|
+
this.baseURL = endpoint;
|
|
29
|
+
this.timeout = config?.timeout ?? DEFAULT_TIMEOUT;
|
|
30
|
+
this.httpRetries = config?.httpRetries ?? DEFAULT_HTTP_RETRIES;
|
|
31
|
+
this.headers = config?.headers ?? {};
|
|
32
|
+
this.accessToken = config?.accessToken;
|
|
33
|
+
}
|
|
34
|
+
async httpRequest(url, schema, options, retries = this.httpRetries, backoff = 100 + Math.floor(Math.random() * 100)) {
|
|
35
|
+
try {
|
|
36
|
+
// Build auth headers if access token is provided
|
|
37
|
+
const authHeaders = {};
|
|
38
|
+
if (this.accessToken !== undefined) {
|
|
39
|
+
authHeaders.Authorization = `Bearer ${this.accessToken}`;
|
|
40
|
+
}
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
...options,
|
|
43
|
+
signal: AbortSignal.any([
|
|
44
|
+
...options?.signal ? [
|
|
45
|
+
options.signal
|
|
46
|
+
] : [],
|
|
47
|
+
AbortSignal.timeout(this.timeout)
|
|
48
|
+
]),
|
|
49
|
+
headers: {
|
|
50
|
+
...authHeaders,
|
|
51
|
+
...this.headers,
|
|
52
|
+
...options?.headers
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const errorBody = await response.text();
|
|
57
|
+
throw new Error(`HTTP error! status: ${response.status.toString()}${errorBody ? `, body: ${errorBody}` : ""}`);
|
|
58
|
+
}
|
|
59
|
+
const data = await response.json();
|
|
60
|
+
return schema.parse(data);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (retries > 0 && !(error instanceof Error && error.name === "AbortError")) {
|
|
63
|
+
// Wait for a backoff period before retrying
|
|
64
|
+
await new Promise((resolve)=>setTimeout(resolve, backoff));
|
|
65
|
+
return this.httpRequest(url, schema, options, retries - 1, backoff * 2); // Exponential backoff
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Fetch the set of available price feeds.
|
|
72
|
+
* This endpoint can be filtered by asset type and query string.
|
|
73
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
74
|
+
*
|
|
75
|
+
* @param options - Optional parameters:
|
|
76
|
+
* - 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".
|
|
77
|
+
* - 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.
|
|
78
|
+
*
|
|
79
|
+
* @returns Array of PriceFeedMetadata objects.
|
|
80
|
+
*/ async getPriceFeeds({ fetchOptions, ...options } = {}) {
|
|
81
|
+
const url = this.buildURL("price_feeds");
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
83
|
+
if (options) {
|
|
84
|
+
const transformedOptions = (0, _utils.camelToSnakeCaseObject)(options);
|
|
85
|
+
this.appendUrlSearchParams(url, transformedOptions);
|
|
86
|
+
}
|
|
87
|
+
return await this.httpRequest(url.toString(), _zodSchemas.schemas.PriceFeedMetadata.array(), fetchOptions);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetch the latest publisher stake caps.
|
|
91
|
+
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed publisher caps.
|
|
92
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
93
|
+
*
|
|
94
|
+
* @param options - Optional parameters:
|
|
95
|
+
* - encoding: Encoding type. If specified, return the publisher caps in the encoding specified by the encoding parameter. Default is hex.
|
|
96
|
+
* - parsed: Boolean to specify if the parsed publisher caps should be included in the response. Default is false.
|
|
97
|
+
*
|
|
98
|
+
* @returns PublisherCaps object containing the latest publisher stake caps.
|
|
99
|
+
*/ async getLatestPublisherCaps({ fetchOptions, ...options } = {}) {
|
|
100
|
+
const url = this.buildURL("updates/publisher_stake_caps/latest");
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
102
|
+
if (options) {
|
|
103
|
+
this.appendUrlSearchParams(url, options);
|
|
104
|
+
}
|
|
105
|
+
return await this.httpRequest(url.toString(), _zodSchemas.schemas.LatestPublisherStakeCapsUpdateDataResponse, fetchOptions);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Fetch the latest price updates for a set of price feed IDs.
|
|
109
|
+
* 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.
|
|
110
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
111
|
+
*
|
|
112
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
113
|
+
* @param options - Optional parameters:
|
|
114
|
+
* - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
|
|
115
|
+
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
116
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
117
|
+
*
|
|
118
|
+
* @returns PriceUpdate object containing the latest updates.
|
|
119
|
+
*/ async getLatestPriceUpdates(ids, options, fetchOptions) {
|
|
120
|
+
const url = this.buildURL("updates/price/latest");
|
|
121
|
+
for (const id of ids){
|
|
122
|
+
url.searchParams.append("ids[]", id);
|
|
123
|
+
}
|
|
124
|
+
if (options) {
|
|
125
|
+
const transformedOptions = (0, _utils.camelToSnakeCaseObject)(options);
|
|
126
|
+
this.appendUrlSearchParams(url, transformedOptions);
|
|
127
|
+
}
|
|
128
|
+
return this.httpRequest(url.toString(), _zodSchemas.schemas.PriceUpdate, fetchOptions);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Fetch the price updates for a set of price feed IDs at a given timestamp.
|
|
132
|
+
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed price update.
|
|
133
|
+
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
134
|
+
*
|
|
135
|
+
* @param publishTime - Unix timestamp in seconds.
|
|
136
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
137
|
+
* @param options - Optional parameters:
|
|
138
|
+
* - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
|
|
139
|
+
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
140
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
141
|
+
*
|
|
142
|
+
* @returns PriceUpdate object containing the updates at the specified timestamp.
|
|
143
|
+
*/ async getPriceUpdatesAtTimestamp(publishTime, ids, options, fetchOptions) {
|
|
144
|
+
const url = this.buildURL(`updates/price/${publishTime.toString()}`);
|
|
145
|
+
for (const id of ids){
|
|
146
|
+
url.searchParams.append("ids[]", id);
|
|
147
|
+
}
|
|
148
|
+
if (options) {
|
|
149
|
+
const transformedOptions = (0, _utils.camelToSnakeCaseObject)(options);
|
|
150
|
+
this.appendUrlSearchParams(url, transformedOptions);
|
|
151
|
+
}
|
|
152
|
+
return this.httpRequest(url.toString(), _zodSchemas.schemas.PriceUpdate, fetchOptions);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Fetch streaming price updates for a set of price feed IDs.
|
|
156
|
+
* This endpoint can be customized by specifying the encoding type, whether the results should include parsed updates,
|
|
157
|
+
* and if unordered updates or only benchmark updates are allowed.
|
|
158
|
+
* This will return an EventSource that can be used to listen to streaming updates.
|
|
159
|
+
* If an invalid hex-encoded ID is passed, it will throw an error.
|
|
160
|
+
*
|
|
161
|
+
* @param ids - Array of hex-encoded price feed IDs for which streaming updates are requested.
|
|
162
|
+
* @param options - Optional parameters:
|
|
163
|
+
* - encoding: Encoding type. If specified, updates are returned in the specified encoding. Default is hex.
|
|
164
|
+
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
165
|
+
* - allowUnordered: Boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
|
|
166
|
+
* - benchmarksOnly: Boolean to specify if only benchmark prices should be returned. Default is false.
|
|
167
|
+
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
168
|
+
*
|
|
169
|
+
* @returns An EventSource instance for receiving streaming updates.
|
|
170
|
+
*/ async getPriceUpdatesStream(ids, options) {
|
|
171
|
+
const url = this.buildURL("updates/price/stream");
|
|
172
|
+
for (const id of ids){
|
|
173
|
+
url.searchParams.append("ids[]", id);
|
|
174
|
+
}
|
|
175
|
+
if (options) {
|
|
176
|
+
const transformedOptions = (0, _utils.camelToSnakeCaseObject)(options);
|
|
177
|
+
this.appendUrlSearchParams(url, transformedOptions);
|
|
178
|
+
}
|
|
179
|
+
// Build auth headers for SSE fetch
|
|
180
|
+
const authHeaders = {};
|
|
181
|
+
if (this.accessToken !== undefined) {
|
|
182
|
+
authHeaders.Authorization = `Bearer ${this.accessToken}`;
|
|
183
|
+
}
|
|
184
|
+
return new _eventsource.EventSource(url.toString(), {
|
|
185
|
+
fetch: (input, init)=>fetch(input, {
|
|
186
|
+
...init,
|
|
187
|
+
headers: {
|
|
188
|
+
...init?.headers,
|
|
189
|
+
...authHeaders,
|
|
190
|
+
...this.headers
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
appendUrlSearchParams(url, params) {
|
|
196
|
+
for (const [key, value] of Object.entries(params)){
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
198
|
+
if (value !== undefined) {
|
|
199
|
+
url.searchParams.append(key, String(value));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
buildURL(endpoint) {
|
|
204
|
+
return new URL(// eslint-disable-next-line unicorn/relative-url-style
|
|
205
|
+
`./v2/${endpoint}`, // We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
|
|
206
|
+
// path relative to the parent.
|
|
207
|
+
`${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { EventSource } from "eventsource";
|
|
2
|
-
import { schemas } from "./zodSchemas";
|
|
3
2
|
import { z } from "zod";
|
|
3
|
+
import { schemas } from "./zodSchemas.js";
|
|
4
4
|
export type AssetType = z.infer<typeof schemas.AssetType>;
|
|
5
5
|
export type BinaryPriceUpdate = z.infer<typeof schemas.BinaryUpdate>;
|
|
6
6
|
export type EncodingType = z.infer<typeof schemas.EncodingType>;
|
|
7
7
|
export type PriceFeedMetadata = z.infer<typeof schemas.PriceFeedMetadata>;
|
|
8
8
|
export type PriceIdInput = z.infer<typeof schemas.PriceIdInput>;
|
|
9
9
|
export type PriceUpdate = z.infer<typeof schemas.PriceUpdate>;
|
|
10
|
-
export type TwapsResponse = z.infer<typeof schemas.TwapsResponse>;
|
|
11
10
|
export type PublisherCaps = z.infer<typeof schemas.LatestPublisherStakeCapsUpdateDataResponse>;
|
|
12
11
|
export type UnixTimestamp = number;
|
|
13
12
|
export type DurationInSeconds = number;
|
|
@@ -26,17 +25,25 @@ export type HermesClientConfig = {
|
|
|
26
25
|
* Optional headers to be included in every request.
|
|
27
26
|
*/
|
|
28
27
|
headers?: HeadersInit;
|
|
28
|
+
/**
|
|
29
|
+
* Optional API access token for authentication.
|
|
30
|
+
* When provided, this token will be included in all requests either:
|
|
31
|
+
* - As a Bearer token in the Authorization header (for HTTP requests)
|
|
32
|
+
* - As an ACCESS_TOKEN query parameter (for WebSocket/SSE connections)
|
|
33
|
+
*/
|
|
34
|
+
accessToken?: string;
|
|
29
35
|
};
|
|
30
36
|
export declare class HermesClient {
|
|
31
37
|
private baseURL;
|
|
32
38
|
private timeout;
|
|
33
39
|
private httpRetries;
|
|
34
40
|
private headers;
|
|
41
|
+
private accessToken;
|
|
35
42
|
/**
|
|
36
43
|
* Constructs a new Connection.
|
|
37
44
|
*
|
|
38
|
-
* @param endpoint endpoint URL to the price service. Example: https://website/example/
|
|
39
|
-
* @param config Optional HermesClientConfig for custom configurations.
|
|
45
|
+
* @param endpoint - endpoint URL to the price service. Example: https://website/example/
|
|
46
|
+
* @param config - Optional HermesClientConfig for custom configurations.
|
|
40
47
|
*/
|
|
41
48
|
constructor(endpoint: string, config?: HermesClientConfig);
|
|
42
49
|
private httpRequest;
|
|
@@ -45,7 +52,7 @@ export declare class HermesClient {
|
|
|
45
52
|
* This endpoint can be filtered by asset type and query string.
|
|
46
53
|
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
47
54
|
*
|
|
48
|
-
* @param options Optional parameters:
|
|
55
|
+
* @param options - Optional parameters:
|
|
49
56
|
* - 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
57
|
* - 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
58
|
*
|
|
@@ -61,7 +68,7 @@ export declare class HermesClient {
|
|
|
61
68
|
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed publisher caps.
|
|
62
69
|
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
63
70
|
*
|
|
64
|
-
* @param options Optional parameters:
|
|
71
|
+
* @param options - Optional parameters:
|
|
65
72
|
* - encoding: Encoding type. If specified, return the publisher caps in the encoding specified by the encoding parameter. Default is hex.
|
|
66
73
|
* - parsed: Boolean to specify if the parsed publisher caps should be included in the response. Default is false.
|
|
67
74
|
*
|
|
@@ -77,8 +84,8 @@ export declare class HermesClient {
|
|
|
77
84
|
* 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
85
|
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
79
86
|
*
|
|
80
|
-
* @param ids Array of hex-encoded price feed IDs for which updates are requested.
|
|
81
|
-
* @param options Optional parameters:
|
|
87
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
88
|
+
* @param options - Optional parameters:
|
|
82
89
|
* - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
|
|
83
90
|
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
84
91
|
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
@@ -95,9 +102,9 @@ export declare class HermesClient {
|
|
|
95
102
|
* This endpoint can be customized by specifying the encoding type and whether the results should also return the parsed price update.
|
|
96
103
|
* This will throw an error if there is a network problem or the price service returns a non-ok response.
|
|
97
104
|
*
|
|
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:
|
|
105
|
+
* @param publishTime - Unix timestamp in seconds.
|
|
106
|
+
* @param ids - Array of hex-encoded price feed IDs for which updates are requested.
|
|
107
|
+
* @param options - Optional parameters:
|
|
101
108
|
* - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
|
|
102
109
|
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
103
110
|
* - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
|
|
@@ -116,8 +123,8 @@ export declare class HermesClient {
|
|
|
116
123
|
* This will return an EventSource that can be used to listen to streaming updates.
|
|
117
124
|
* If an invalid hex-encoded ID is passed, it will throw an error.
|
|
118
125
|
*
|
|
119
|
-
* @param ids Array of hex-encoded price feed IDs for which streaming updates are requested.
|
|
120
|
-
* @param options Optional parameters:
|
|
126
|
+
* @param ids - Array of hex-encoded price feed IDs for which streaming updates are requested.
|
|
127
|
+
* @param options - Optional parameters:
|
|
121
128
|
* - encoding: Encoding type. If specified, updates are returned in the specified encoding. Default is hex.
|
|
122
129
|
* - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
|
|
123
130
|
* - allowUnordered: Boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
|
|
@@ -133,27 +140,6 @@ export declare class HermesClient {
|
|
|
133
140
|
benchmarksOnly?: boolean;
|
|
134
141
|
ignoreInvalidPriceIds?: boolean;
|
|
135
142
|
}): 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
143
|
private appendUrlSearchParams;
|
|
157
144
|
private buildURL;
|
|
158
145
|
}
|
|
159
|
-
//# sourceMappingURL=HermesClient.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./hermes-client.cjs"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./hermes-client.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "camelToSnakeCaseObject", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return camelToSnakeCaseObject;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ function camelToSnakeCase(str) {
|
|
12
|
+
return str.replaceAll(/[A-Z]/g, (letter)=>`_${letter.toLowerCase()}`);
|
|
13
|
+
}
|
|
14
|
+
function camelToSnakeCaseObject(obj) {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const key of Object.keys(obj)){
|
|
17
|
+
const newKey = camelToSnakeCase(key);
|
|
18
|
+
const val = obj[key];
|
|
19
|
+
result[newKey] = val;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|