File tree 5 files changed +27
-7
lines changed
5 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @pythnetwork/hermes-client" ,
3
- "version" : " 1.0.0 " ,
3
+ "version" : " 1.0.1 " ,
4
4
"description" : " Pyth Hermes Client" ,
5
5
"author" : {
6
6
"name" : " Pyth Data Association"
Original file line number Diff line number Diff line change 1
1
import EventSource from "eventsource" ;
2
2
import { schemas } from "./zodSchemas" ;
3
3
import { z } from "zod" ;
4
+ import { camelToSnakeCaseObject } from "./utils" ;
4
5
5
6
// Accessing schema objects
6
7
export type AssetType = z . infer < typeof schemas . AssetType > ;
@@ -193,8 +194,8 @@ export class HermesClient {
193
194
options ?: {
194
195
encoding ?: EncodingType ;
195
196
parsed ?: boolean ;
196
- allow_unordered ?: boolean ;
197
- benchmarks_only ?: boolean ;
197
+ allowUnordered ?: boolean ;
198
+ benchmarksOnly ?: boolean ;
198
199
}
199
200
) : Promise < EventSource > {
200
201
const url = new URL ( "/v2/updates/price/stream" , this . baseURL ) ;
@@ -203,7 +204,8 @@ export class HermesClient {
203
204
} ) ;
204
205
205
206
if ( options ) {
206
- this . appendUrlSearchParams ( url , options ) ;
207
+ const transformedOptions = camelToSnakeCaseObject ( options ) ;
208
+ this . appendUrlSearchParams ( url , transformedOptions ) ;
207
209
}
208
210
209
211
return new EventSource ( url . toString ( ) ) ;
Original file line number Diff line number Diff line change @@ -45,7 +45,12 @@ async function run() {
45
45
console . log ( priceUpdates ) ;
46
46
47
47
// 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
+ } ) ;
49
54
50
55
eventSource . onmessage = ( event ) => {
51
56
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