@pythnetwork/hermes-client 1.1.0 → 1.3.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 CHANGED
@@ -69,12 +69,15 @@ By default, these updates are returned as binary data and is serialized as eithe
69
69
 
70
70
  ### Examples
71
71
 
72
- The [HermesClient](./src/examples/HermesClient.ts) example demonstrates both the examples above.
73
- You can run it with `npm run example`.
74
- A full command that prints BTC and ETH price feeds, in the testnet network, looks like so:
72
+ The [HermesClient](./src/examples/HermesClient.ts) example demonstrates both the
73
+ examples above. To run the example:
74
+
75
+ 1. Clone [the Pyth monorepo](https://github.com/pyth-network/pyth-crosschain)
76
+ 2. In the root of the monorepo, run `pnpm example:hermes-client -- <args>`. For
77
+ example, to print BTC and ETH price feeds in the testnet network, run:
75
78
 
76
79
  ```bash
77
- npm run example -- \
80
+ pnpm example:hermes-client -- \
78
81
  --endpoint https://hermes.pyth.network \
79
82
  --price-ids \
80
83
  0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 \
@@ -7,6 +7,7 @@ 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>;
10
11
  export type PublisherCaps = z.infer<typeof schemas.LatestPublisherStakeCapsUpdateDataResponse>;
11
12
  export type UnixTimestamp = number;
12
13
  export type DurationInSeconds = number;
@@ -78,12 +79,14 @@ export declare class HermesClient {
78
79
  * @param options Optional parameters:
79
80
  * - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
80
81
  * - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
82
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
81
83
  *
82
84
  * @returns PriceUpdate object containing the latest updates.
83
85
  */
84
86
  getLatestPriceUpdates(ids: HexString[], options?: {
85
87
  encoding?: EncodingType;
86
88
  parsed?: boolean;
89
+ ignoreInvalidPriceIds?: boolean;
87
90
  }): Promise<PriceUpdate>;
88
91
  /**
89
92
  * Fetch the price updates for a set of price feed IDs at a given timestamp.
@@ -95,12 +98,14 @@ export declare class HermesClient {
95
98
  * @param options Optional parameters:
96
99
  * - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
97
100
  * - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
101
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
98
102
  *
99
103
  * @returns PriceUpdate object containing the updates at the specified timestamp.
100
104
  */
101
105
  getPriceUpdatesAtTimestamp(publishTime: UnixTimestamp, ids: HexString[], options?: {
102
106
  encoding?: EncodingType;
103
107
  parsed?: boolean;
108
+ ignoreInvalidPriceIds?: boolean;
104
109
  }): Promise<PriceUpdate>;
105
110
  /**
106
111
  * Fetch streaming price updates for a set of price feed IDs.
@@ -109,12 +114,14 @@ export declare class HermesClient {
109
114
  * This will return an EventSource that can be used to listen to streaming updates.
110
115
  * If an invalid hex-encoded ID is passed, it will throw an error.
111
116
  *
112
- *
113
117
  * @param ids Array of hex-encoded price feed IDs for which streaming updates are requested.
114
- * @param encoding Optional encoding type. If specified, updates are returned in the specified encoding. Default is hex.
115
- * @param parsed Optional boolean to specify if the parsed price update should be included in the response. Default is false.
116
- * @param allow_unordered Optional boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
117
- * @param benchmarks_only Optional boolean to specify if only benchmark prices that are the initial price updates at a given timestamp (i.e., prevPubTime != pubTime) should be returned. Default is false.
118
+ * @param options Optional parameters:
119
+ * - encoding: Encoding type. If specified, updates are returned in the specified encoding. Default is hex.
120
+ * - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
121
+ * - allowUnordered: Boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
122
+ * - benchmarksOnly: Boolean to specify if only benchmark prices should be returned. Default is false.
123
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
124
+ *
118
125
  * @returns An EventSource instance for receiving streaming updates.
119
126
  */
120
127
  getPriceUpdatesStream(ids: HexString[], options?: {
@@ -122,7 +129,28 @@ export declare class HermesClient {
122
129
  parsed?: boolean;
123
130
  allowUnordered?: boolean;
124
131
  benchmarksOnly?: boolean;
132
+ ignoreInvalidPriceIds?: boolean;
125
133
  }): Promise<EventSource>;
134
+ /**
135
+ * Fetch the latest TWAP (time weighted average price) for a set of price feed IDs.
136
+ * This endpoint can be customized by specifying the encoding type and whether the results should also return the calculated TWAP using the options object.
137
+ * This will throw an error if there is a network problem or the price service returns a non-ok response.
138
+ *
139
+ * @param ids Array of hex-encoded price feed IDs for which updates are requested.
140
+ * @param window_seconds The time window in seconds over which to calculate the TWAP, ending at the current time.
141
+ * 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).
142
+ * @param options Optional parameters:
143
+ * - encoding: Encoding type. If specified, return the TWAP binary data in the encoding specified by the encoding parameter. Default is hex.
144
+ * - parsed: Boolean to specify if the calculated TWAP should be included in the response. Default is false.
145
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
146
+ *
147
+ * @returns TwapsResponse object containing the latest TWAPs.
148
+ */
149
+ getLatestTwaps(ids: HexString[], window_seconds: number, options?: {
150
+ encoding?: EncodingType;
151
+ parsed?: boolean;
152
+ ignoreInvalidPriceIds?: boolean;
153
+ }): Promise<TwapsResponse>;
126
154
  private appendUrlSearchParams;
127
155
  }
128
156
  //# sourceMappingURL=HermesClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HermesClient.d.ts","sourceRoot":"","sources":["../src/HermesClient.ts"],"names":[],"mappings":"AAAA,OAAO,W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AQ,CAAC,EAAE,YAAY,CAAC;QACxB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,GACA,OAAO,CAAC,WAAW,CAAC;IAcvB;;;;;;;;;;;;;;OAcG;IACG,cAAc,CAClB,GAAG,EAAE,SAAS,EAAE,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,YAAY,CAAC;QACxB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,GACA,OAAO,CAAC,aAAa,CAAC;IAiBzB,OAAO,CAAC,qBAAqB;CAU9B"}
@@ -41,7 +41,8 @@ class HermesClient {
41
41
  const response = await fetch(url, options);
42
42
  clearTimeout(timeout); // Clear the timeout if the request completes in time
43
43
  if (!response.ok) {
44
- throw new Error(`HTTP error! status: ${response.status}`);
44
+ const errorBody = await response.text();
45
+ throw new Error(`HTTP error! status: ${response.status}${errorBody ? `, body: ${errorBody}` : ""}`);
45
46
  }
46
47
  const data = await response.json();
47
48
  return schema.parse(data);
@@ -102,6 +103,7 @@ class HermesClient {
102
103
  * @param options Optional parameters:
103
104
  * - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
104
105
  * - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
106
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
105
107
  *
106
108
  * @returns PriceUpdate object containing the latest updates.
107
109
  */
@@ -111,7 +113,8 @@ class HermesClient {
111
113
  url.searchParams.append("ids[]", id);
112
114
  }
113
115
  if (options) {
114
- this.appendUrlSearchParams(url, options);
116
+ const transformedOptions = (0, utils_1.camelToSnakeCaseObject)(options);
117
+ this.appendUrlSearchParams(url, transformedOptions);
115
118
  }
116
119
  return this.httpRequest(url.toString(), zodSchemas_1.schemas.PriceUpdate);
117
120
  }
@@ -125,6 +128,7 @@ class HermesClient {
125
128
  * @param options Optional parameters:
126
129
  * - encoding: Encoding type. If specified, return the price update in the encoding specified by the encoding parameter. Default is hex.
127
130
  * - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
131
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
128
132
  *
129
133
  * @returns PriceUpdate object containing the updates at the specified timestamp.
130
134
  */
@@ -134,7 +138,8 @@ class HermesClient {
134
138
  url.searchParams.append("ids[]", id);
135
139
  }
136
140
  if (options) {
137
- this.appendUrlSearchParams(url, options);
141
+ const transformedOptions = (0, utils_1.camelToSnakeCaseObject)(options);
142
+ this.appendUrlSearchParams(url, transformedOptions);
138
143
  }
139
144
  return this.httpRequest(url.toString(), zodSchemas_1.schemas.PriceUpdate);
140
145
  }
@@ -145,12 +150,14 @@ class HermesClient {
145
150
  * This will return an EventSource that can be used to listen to streaming updates.
146
151
  * If an invalid hex-encoded ID is passed, it will throw an error.
147
152
  *
148
- *
149
153
  * @param ids Array of hex-encoded price feed IDs for which streaming updates are requested.
150
- * @param encoding Optional encoding type. If specified, updates are returned in the specified encoding. Default is hex.
151
- * @param parsed Optional boolean to specify if the parsed price update should be included in the response. Default is false.
152
- * @param allow_unordered Optional boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
153
- * @param benchmarks_only Optional boolean to specify if only benchmark prices that are the initial price updates at a given timestamp (i.e., prevPubTime != pubTime) should be returned. Default is false.
154
+ * @param options Optional parameters:
155
+ * - encoding: Encoding type. If specified, updates are returned in the specified encoding. Default is hex.
156
+ * - parsed: Boolean to specify if the parsed price update should be included in the response. Default is false.
157
+ * - allowUnordered: Boolean to specify if unordered updates are allowed to be included in the stream. Default is false.
158
+ * - benchmarksOnly: Boolean to specify if only benchmark prices should be returned. Default is false.
159
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
160
+ *
154
161
  * @returns An EventSource instance for receiving streaming updates.
155
162
  */
156
163
  async getPriceUpdatesStream(ids, options) {
@@ -164,6 +171,32 @@ class HermesClient {
164
171
  }
165
172
  return new eventsource_1.default(url.toString(), { headers: this.headers });
166
173
  }
174
+ /**
175
+ * Fetch the latest TWAP (time weighted average price) for a set of price feed IDs.
176
+ * This endpoint can be customized by specifying the encoding type and whether the results should also return the calculated TWAP using the options object.
177
+ * This will throw an error if there is a network problem or the price service returns a non-ok response.
178
+ *
179
+ * @param ids Array of hex-encoded price feed IDs for which updates are requested.
180
+ * @param window_seconds The time window in seconds over which to calculate the TWAP, ending at the current time.
181
+ * 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).
182
+ * @param options Optional parameters:
183
+ * - encoding: Encoding type. If specified, return the TWAP binary data in the encoding specified by the encoding parameter. Default is hex.
184
+ * - parsed: Boolean to specify if the calculated TWAP should be included in the response. Default is false.
185
+ * - ignoreInvalidPriceIds: Boolean to specify if invalid price IDs should be ignored instead of returning an error. Default is false.
186
+ *
187
+ * @returns TwapsResponse object containing the latest TWAPs.
188
+ */
189
+ async getLatestTwaps(ids, window_seconds, options) {
190
+ const url = new URL(`v2/updates/twap/${window_seconds}/latest`, this.baseURL);
191
+ for (const id of ids) {
192
+ url.searchParams.append("ids[]", id);
193
+ }
194
+ if (options) {
195
+ const transformedOptions = (0, utils_1.camelToSnakeCaseObject)(options);
196
+ this.appendUrlSearchParams(url, transformedOptions);
197
+ }
198
+ return this.httpRequest(url.toString(), zodSchemas_1.schemas.TwapsResponse);
199
+ }
167
200
  appendUrlSearchParams(url, params) {
168
201
  Object.entries(params).forEach(([key, value]) => {
169
202
  if (value !== undefined) {
@@ -48,15 +48,22 @@ async function run() {
48
48
  const connection = new HermesClient_1.HermesClient(endpoint, { headers });
49
49
  const priceIds = argv.priceIds;
50
50
  // Get price feeds
51
+ console.log(`Price feeds matching "btc" with asset type "crypto":`);
51
52
  const priceFeeds = await connection.getPriceFeeds({
52
53
  query: "btc",
53
54
  filter: "crypto",
54
55
  });
55
56
  console.log(priceFeeds);
56
57
  // Latest price updates
58
+ console.log(`Latest price updates for price IDs ${priceIds}:`);
57
59
  const priceUpdates = await connection.getLatestPriceUpdates(priceIds);
58
60
  console.log(priceUpdates);
61
+ // Get the latest 5 second TWAPs
62
+ console.log(`Latest 5 second TWAPs for price IDs ${priceIds}`);
63
+ const twapUpdates = await connection.getLatestTwaps(priceIds, 5);
64
+ console.log(twapUpdates);
59
65
  // Streaming price updates
66
+ console.log(`Streaming latest prices for price IDs ${priceIds}...`);
60
67
  const eventSource = await connection.getPriceUpdatesStream(priceIds, {
61
68
  encoding: "hex",
62
69
  parsed: true,
@@ -65,6 +72,7 @@ async function run() {
65
72
  });
66
73
  eventSource.onmessage = (event) => {
67
74
  console.log("Received price update:", event.data);
75
+ const _priceUpdate = JSON.parse(event.data);
68
76
  };
69
77
  eventSource.onerror = (error) => {
70
78
  console.error("Error receiving updates:", error);