File tree Expand file tree Collapse file tree 5 files changed +27
-7
lines changed Expand file tree Collapse file tree 5 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @pythnetwork/hermes-client" ,
3- "version" : " 1.0.0 " ,
3+ "version" : " 1.0.1 " ,
44 "description" : " Pyth Hermes Client" ,
55 "author" : {
66 "name" : " Pyth Data Association"
Original file line number Diff line number Diff line change 11import EventSource from "eventsource" ;
22import { schemas } from "./zodSchemas" ;
33import { z } from "zod" ;
4+ import { camelToSnakeCaseObject } from "./utils" ;
45
56// Accessing schema objects
67export type AssetType = z . infer < typeof schemas . AssetType > ;
@@ -193,8 +194,8 @@ export class HermesClient {
193194 options ?: {
194195 encoding ?: EncodingType ;
195196 parsed ?: boolean ;
196- allow_unordered ?: boolean ;
197- benchmarks_only ?: boolean ;
197+ allowUnordered ?: boolean ;
198+ benchmarksOnly ?: boolean ;
198199 }
199200 ) : Promise < EventSource > {
200201 const url = new URL ( "/v2/updates/price/stream" , this . baseURL ) ;
@@ -203,7 +204,8 @@ export class HermesClient {
203204 } ) ;
204205
205206 if ( options ) {
206- this . appendUrlSearchParams ( url , options ) ;
207+ const transformedOptions = camelToSnakeCaseObject ( options ) ;
208+ this . appendUrlSearchParams ( url , transformedOptions ) ;
207209 }
208210
209211 return new EventSource ( url . toString ( ) ) ;
Original file line number Diff line number Diff line change @@ -45,7 +45,12 @@ async function run() {
4545 console . log ( priceUpdates ) ;
4646
4747 // Streaming price updates
48- const eventSource = await connection . getPriceUpdatesStream ( priceIds ) ;
48+ const eventSource = await connection . getPriceUpdatesStream ( priceIds , {
49+ encoding : "hex" ,
50+ parsed : true ,
51+ allowUnordered : true ,
52+ benchmarksOnly : true ,
53+ } ) ;
4954
5055 eventSource . onmessage = ( event ) => {
5156 console . log ( "Received price update:" , event . data ) ;
Original file line number Diff line number Diff line change 1+ function camelToSnakeCase ( str : string ) : string {
2+ return str . replace ( / [ A - Z ] / g, ( letter ) => `_${ letter . toLowerCase ( ) } ` ) ;
3+ }
4+
5+ export function camelToSnakeCaseObject (
6+ obj : Record < string , string | boolean >
7+ ) : Record < string , string | boolean > {
8+ const result : Record < string , string | boolean > = { } ;
9+ Object . keys ( obj ) . forEach ( ( key ) => {
10+ result [ camelToSnakeCase ( key ) ] = obj [ key ] ;
11+ } ) ;
12+ return result ;
13+ }
You can’t perform that action at this time.
0 commit comments