@pythnetwork/price-service-client 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,6 +70,17 @@ export declare class PriceServiceConnection {
70
70
  * @returns Tuple of VAA and publishTime.
71
71
  */
72
72
  getVaa(priceId: HexString, publishTime: EpochTimeStamp): Promise<[string, EpochTimeStamp]>;
73
+ /**
74
+ * Fetch the PriceFeed of the given price id that is published since the given publish time.
75
+ * This will throw an error if the given publish time is in the future, or if the publish time
76
+ * is old and the price service endpoint does not have a db backend for historical requests.
77
+ * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id)
78
+ *
79
+ * @param priceId Hex-encoded price id.
80
+ * @param publishTime Epoch timestamp in seconds.
81
+ * @returns PriceFeed
82
+ */
83
+ getPriceFeed(priceId: HexString, publishTime: EpochTimeStamp): Promise<PriceFeed>;
73
84
  /**
74
85
  * Fetch the list of available price feed ids.
75
86
  * This will throw an axios error if there is a network problem or the price service returns a non-ok response.
@@ -1 +1 @@
1
- {"version":3,"file":"PriceServiceConnection.d.ts","sourceRoot":"","sources":["../src/PriceServiceConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,MAAM,sBAAsB,GAAG;IAEnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IAEzC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,sBAAsB,CAA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ACV,OAAO,EAAE,SAAS,EAClB,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAUpC;;;;;;;;;OASG;IACG,YAAY,CAChB,OAAO,EAAE,SAAS,EAClB,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,SAAS,CAAC;IAarB;;;;;OAKG;IACG,eAAe,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK7C;;;;;;;;;;OAUG;IACG,yBAAyB,CAC7B,QAAQ,EAAE,SAAS,EAAE,EACrB,EAAE,EAAE,uBAAuB;IA6B7B;;;;;;;;;;OAUG;IACG,2BAA2B,CAC/B,QAAQ,EAAE,SAAS,EAAE,EACrB,EAAE,CAAC,EAAE,uBAAuB;IA4C9B;;;;OAIG;IACG,cAAc;IAwEpB;;;;;;OAMG;IACH,cAAc;CAKf"}
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.PriceServiceConnection = void 0;
4
7
  const price_service_sdk_1 = require("@pythnetwork/price-service-sdk");
5
- const axios_1 = require("axios");
6
- const axios_retry_1 = require("axios-retry");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const axios_retry_1 = __importDefault(require("axios-retry"));
7
10
  const ResillientWebSocket_1 = require("./ResillientWebSocket");
8
11
  const utils_1 = require("./utils");
9
12
  class PriceServiceConnection {
@@ -39,9 +42,25 @@ class PriceServiceConnection {
39
42
  verbose: config?.priceFeedRequestConfig?.verbose ?? config?.verbose,
40
43
  };
41
44
  this.priceFeedCallbacks = new Map();
42
- this.logger = config?.logger;
45
+ // Default logger is console for only warnings and errors.
46
+ this.logger = config?.logger || {
47
+ trace: () => { },
48
+ debug: () => { },
49
+ info: () => { },
50
+ warn: console.warn,
51
+ error: console.error,
52
+ };
43
53
  this.onWsError = (error) => {
44
- this.logger?.error(error);
54
+ this.logger.error(error);
55
+ // Exit the process if it is running in node.
56
+ if (typeof process !== "undefined" &&
57
+ typeof process.exit === "function") {
58
+ this.logger.error("Halting the process due to the websocket error");
59
+ process.exit(1);
60
+ }
61
+ else {
62
+ this.logger.error("Cannot halt process. Please handle the websocket error.");
63
+ }
45
64
  };
46
65
  this.wsEndpoint = (0, utils_1.makeWebsocketUrl)(endpoint);
47
66
  }
@@ -104,6 +123,27 @@ class PriceServiceConnection {
104
123
  });
105
124
  return [response.data.vaa, response.data.publishTime];
106
125
  }
126
+ /**
127
+ * Fetch the PriceFeed of the given price id that is published since the given publish time.
128
+ * This will throw an error if the given publish time is in the future, or if the publish time
129
+ * is old and the price service endpoint does not have a db backend for historical requests.
130
+ * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id)
131
+ *
132
+ * @param priceId Hex-encoded price id.
133
+ * @param publishTime Epoch timestamp in seconds.
134
+ * @returns PriceFeed
135
+ */
136
+ async getPriceFeed(priceId, publishTime) {
137
+ const response = await this.httpClient.get("/api/get_price_feed", {
138
+ params: {
139
+ id: priceId,
140
+ publish_time: publishTime,
141
+ verbose: this.priceFeedRequestConfig.verbose,
142
+ binary: this.priceFeedRequestConfig.binary,
143
+ },
144
+ });
145
+ return price_service_sdk_1.PriceFeed.fromJson(response.data);
146
+ }
107
147
  /**
108
148
  * Fetch the list of available price feed ids.
109
149
  * This will throw an axios error if there is a network problem or the price service returns a non-ok response.
@@ -210,25 +250,25 @@ class PriceServiceConnection {
210
250
  verbose: this.priceFeedRequestConfig.verbose,
211
251
  binary: this.priceFeedRequestConfig.binary,
212
252
  };
213
- this.logger?.info("Resubscribing to existing price feeds.");
253
+ this.logger.info("Resubscribing to existing price feeds.");
214
254
  this.wsClient?.send(JSON.stringify(message));
215
255
  }
216
256
  };
217
257
  this.wsClient.onMessage = (data) => {
218
- this.logger?.info(`Received message ${data.toString()}`);
258
+ this.logger.info(`Received message ${data.toString()}`);
219
259
  let message;
220
260
  try {
221
261
  message = JSON.parse(data.toString());
222
262
  }
223
263
  catch (e) {
224
- this.logger?.error(`Error parsing message ${data.toString()} as JSON.`);
225
- this.logger?.error(e);
264
+ this.logger.error(`Error parsing message ${data.toString()} as JSON.`);
265
+ this.logger.error(e);
226
266
  this.onWsError(e);
227
267
  return;
228
268
  }
229
269
  if (message.type === "response") {
230
270
  if (message.status === "error") {
231
- this.logger?.error(`Error response from the websocket server ${message.error}.`);
271
+ this.logger.error(`Error response from the websocket server ${message.error}.`);
232
272
  this.onWsError(new Error(message.error));
233
273
  }
234
274
  }
@@ -238,8 +278,8 @@ class PriceServiceConnection {
238
278
  priceFeed = price_service_sdk_1.PriceFeed.fromJson(message.price_feed);
239
279
  }
240
280
  catch (e) {
241
- this.logger?.error(`Error parsing price feeds from message ${data.toString()}.`);
242
- this.logger?.error(e);
281
+ this.logger.error(`Error parsing price feeds from message ${data.toString()}.`);
282
+ this.logger.error(e);
243
283
  this.onWsError(e);
244
284
  return;
245
285
  }
@@ -250,7 +290,7 @@ class PriceServiceConnection {
250
290
  }
251
291
  }
252
292
  else {
253
- this.logger?.warn(`Ignoring unsupported server response ${data.toString()}.`);
293
+ this.logger.warn(`Ignoring unsupported server response ${data.toString()}.`);
254
294
  }
255
295
  };
256
296
  await this.wsClient.startWebSocket();
@@ -1,4 +1,4 @@
1
- import * as WebSocket from "isomorphic-ws";
1
+ import WebSocket from "isomorphic-ws";
2
2
  import { Logger } from "ts-log";
3
3
  /**
4
4
  * This class wraps websocket to provide a resilient web socket client.
@@ -1 +1 @@
1
- {"version":3,"file":"ResillientWebSocket.d.ts","sourceRoot":"","sources":["../src/ResillientWebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC;;;;;;;;;GASG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OA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OAAO,CAAC,SAAS;YAcH,0BAA0B;YAgB1B,gCAAgC;IAkB9C,cAAc;CAQf"}
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.ResilientWebSocket = void 0;
4
- const WebSocket = require("isomorphic-ws");
7
+ const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
5
8
  const PING_TIMEOUT_DURATION = 30000 + 3000; // It is 30s on the server and 3s is added for delays
6
9
  /**
7
10
  * This class wraps websocket to provide a resilient web socket client.
@@ -49,7 +52,7 @@ class ResilientWebSocket {
49
52
  return;
50
53
  }
51
54
  this.logger?.info(`Creating Web Socket client`);
52
- this.wsClient = new WebSocket(this.endpoint);
55
+ this.wsClient = new isomorphic_ws_1.default(this.endpoint);
53
56
  this.wsUserClosed = false;
54
57
  this.wsClient.onopen = () => {
55
58
  this.wsFailedAttempts = 0;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const yargs_1 = require("yargs");
6
+ const yargs_1 = __importDefault(require("yargs"));
4
7
  const helpers_1 = require("yargs/helpers");
5
8
  const index_1 = require("../index");
6
9
  function sleep(ms) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/price-service-client",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "Pyth price service client",
5
5
  "author": {
6
6
  "name": "Pyth Data Association"
@@ -56,5 +56,5 @@
56
56
  "ts-log": "^2.2.4",
57
57
  "ws": "^8.6.0"
58
58
  },
59
- "gitHead": "6cdcf4dffd54017e19168be450df01acd68f07ab"
59
+ "gitHead": "2c334b6b9249914c1f88541cb55235388e404030"
60
60
  }