Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/hermes/client/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/hermes-client",
"version": "1.0.0",
"version": "1.0.1",
"description": "Pyth Hermes Client",
"author": {
"name": "Pyth Data Association"
Expand Down
8 changes: 5 additions & 3 deletions apps/hermes/client/js/src/HermesClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import EventSource from "eventsource";
import { schemas } from "./zodSchemas";
import { z } from "zod";
import { camelToSnakeCaseObject } from "./utils";

// Accessing schema objects
export type AssetType = z.infer<typeof schemas.AssetType>;
Expand Down Expand Up @@ -193,8 +194,8 @@ export class HermesClient {
options?: {
encoding?: EncodingType;
parsed?: boolean;
allow_unordered?: boolean;
benchmarks_only?: boolean;
allowUnordered?: boolean;
benchmarksOnly?: boolean;
}
): Promise<EventSource> {
const url = new URL("/v2/updates/price/stream", this.baseURL);
Expand All @@ -203,7 +204,8 @@ export class HermesClient {
});

if (options) {
this.appendUrlSearchParams(url, options);
const transformedOptions = camelToSnakeCaseObject(options);
this.appendUrlSearchParams(url, transformedOptions);
}

return new EventSource(url.toString());
Expand Down
7 changes: 6 additions & 1 deletion apps/hermes/client/js/src/examples/HermesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ async function run() {
console.log(priceUpdates);

// Streaming price updates
const eventSource = await connection.getPriceUpdatesStream(priceIds);
const eventSource = await connection.getPriceUpdatesStream(priceIds, {
encoding: "hex",
parsed: true,
allowUnordered: true,
benchmarksOnly: true,
});

eventSource.onmessage = (event) => {
console.log("Received price update:", event.data);
Expand Down
13 changes: 13 additions & 0 deletions apps/hermes/client/js/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function camelToSnakeCase(str: string): string {
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
}

export function camelToSnakeCaseObject(
obj: Record<string, string | boolean>
): Record<string, string | boolean> {
const result: Record<string, string | boolean> = {};
Object.keys(obj).forEach((key) => {
result[camelToSnakeCase(key)] = obj[key];
});
return result;
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.