Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit d7aacb3

Browse files
authored
Add verbose for latestPriceFeed queries + priceFeedIds endpoint (#55)
* Add verbose as config to the connection * Add getPriceFeedIds method
1 parent 97cd14f commit d7aacb3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pyth-common-js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyth-common-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-common-js",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Pyth Network Common Utils in JS",
55
"author": {
66
"name": "Pyth Data Association"

pyth-common-js/src/PriceServiceConnection.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ export type PriceServiceConnectionConfig = {
2020
httpRetries?: number;
2121
/* Optional logger (e.g: console or any logging library) to log internal events */
2222
logger?: Logger;
23+
/* Optional verbose to request for verbose information from the service */
24+
verbose?: boolean;
2325
};
2426

2527
type ClientMessage = {
2628
type: "subscribe" | "unsubscribe";
2729
ids: HexString[];
30+
verbose?: boolean;
2831
};
2932

3033
type ServerResponse = {
@@ -51,6 +54,8 @@ export class PriceServiceConnection {
5154

5255
private logger: undefined | Logger;
5356

57+
private verbose: boolean;
58+
5459
/**
5560
* Custom handler for web socket errors (connection and message parsing).
5661
*
@@ -74,6 +79,8 @@ export class PriceServiceConnection {
7479
retryDelay: axiosRetry.exponentialDelay,
7580
});
7681

82+
this.verbose = config?.verbose || false;
83+
7784
this.priceFeedCallbacks = new Map();
7885
this.logger = config?.logger;
7986
this.onWsError = (error: Error) => {
@@ -100,6 +107,7 @@ export class PriceServiceConnection {
100107
const response = await this.httpClient.get("/api/latest_price_feeds", {
101108
params: {
102109
ids: priceIds,
110+
verbose: this.verbose,
103111
},
104112
});
105113
const priceFeedsJson = response.data as any[];
@@ -128,6 +136,17 @@ export class PriceServiceConnection {
128136
return response.data;
129137
}
130138

139+
/**
140+
* Fetch the list of available price feed ids.
141+
* This will throw an axios error if there is a network problem or the price service returns a non-ok response.
142+
*
143+
* @returns Array of hex-encoded price ids.
144+
*/
145+
async getPriceFeedIds(): Promise<HexString[]> {
146+
const response = await this.httpClient.get("/api/price_feed_ids");
147+
return response.data;
148+
}
149+
131150
/**
132151
* Subscribe to updates for given price ids.
133152
*
@@ -163,6 +182,7 @@ export class PriceServiceConnection {
163182
const message: ClientMessage = {
164183
ids: newPriceIds,
165184
type: "subscribe",
185+
verbose: this.verbose,
166186
};
167187

168188
await this.wsClient?.send(JSON.stringify(message));

0 commit comments

Comments
 (0)