ソースを参照

[price_service] js client: getPriceFeed() (#922)

* [price_service] js client: getPriceFeed()

* Fix pre-commit

* Bump package versions

---------

Co-authored-by: Ali Behjati <bahjatia@gmail.com>
Ryu 2 年 前
コミット
5e44fa4c95

+ 5 - 5
package-lock.json

@@ -55889,7 +55889,7 @@
     },
     "price_pusher": {
       "name": "@pythnetwork/price-pusher",
-      "version": "5.3.1",
+      "version": "5.4.1",
       "license": "Apache-2.0",
       "dependencies": {
         "@injectivelabs/sdk-ts": "1.10.72",
@@ -57320,7 +57320,7 @@
     },
     "price_service/client/js": {
       "name": "@pythnetwork/price-service-client",
-      "version": "1.5.0",
+      "version": "1.6.0",
       "license": "Apache-2.0",
       "dependencies": {
         "@pythnetwork/price-service-sdk": "*",
@@ -57846,7 +57846,7 @@
     },
     "target_chains/aptos/sdk/js": {
       "name": "@pythnetwork/pyth-aptos-js",
-      "version": "1.1.0",
+      "version": "1.2.0",
       "license": "Apache-2.0",
       "dependencies": {
         "@pythnetwork/price-service-client": "*",
@@ -57937,7 +57937,7 @@
     },
     "target_chains/cosmwasm/sdk/js": {
       "name": "@pythnetwork/pyth-terra-js",
-      "version": "1.2.0",
+      "version": "1.3.0",
       "license": "Apache-2.0",
       "dependencies": {
         "@pythnetwork/price-service-client": "*",
@@ -58980,7 +58980,7 @@
     },
     "target_chains/ethereum/sdk/js": {
       "name": "@pythnetwork/pyth-evm-js",
-      "version": "1.18.0",
+      "version": "1.19.0",
       "license": "Apache-2.0",
       "dependencies": {
         "@pythnetwork/price-service-client": "*",

+ 1 - 1
price_service/client/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/price-service-client",
-  "version": "1.5.0",
+  "version": "1.6.0",
   "description": "Pyth price service client",
   "author": {
     "name": "Pyth Data Association"

+ 26 - 0
price_service/client/js/src/PriceServiceConnection.ts

@@ -174,6 +174,32 @@ export class PriceServiceConnection {
     return [response.data.vaa, response.data.publishTime];
   }
 
+  /**
+   * Fetch the PriceFeed of the given price id that is published since the given publish time.
+   * This will throw an error if the given publish time is in the future, or if the publish time
+   * is old and the price service endpoint does not have a db backend for historical requests.
+   * 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)
+   *
+   * @param priceId Hex-encoded price id.
+   * @param publishTime Epoch timestamp in seconds.
+   * @returns PriceFeed
+   */
+  async getPriceFeed(
+    priceId: HexString,
+    publishTime: EpochTimeStamp
+  ): Promise<PriceFeed> {
+    const response = await this.httpClient.get("/api/get_price_feed", {
+      params: {
+        id: priceId,
+        publish_time: publishTime,
+        verbose: this.priceFeedRequestConfig.verbose,
+        binary: this.priceFeedRequestConfig.binary,
+      },
+    });
+
+    return PriceFeed.fromJson(response.data);
+  }
+
   /**
    * Fetch the list of available price feed ids.
    * This will throw an axios error if there is a network problem or the price service returns a non-ok response.

+ 1 - 1
target_chains/aptos/sdk/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/pyth-aptos-js",
-  "version": "1.1.0",
+  "version": "1.2.0",
   "description": "Pyth Network Aptos Utilities",
   "homepage": "https://pyth.network",
   "author": {

+ 1 - 1
target_chains/cosmwasm/sdk/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/pyth-terra-js",
-  "version": "1.2.0",
+  "version": "1.3.0",
   "description": "Pyth Network Terra Utils in JS",
   "homepage": "https://pyth.network",
   "author": {

+ 1 - 1
target_chains/ethereum/sdk/js/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/pyth-evm-js",
-  "version": "1.18.0",
+  "version": "1.19.0",
   "description": "Pyth Network EVM Utils in JS",
   "homepage": "https://pyth.network",
   "author": {