File tree 3 files changed +18
-4
lines changed
3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " tda-wsjson-client" ,
3
- "version" : " 0.10.1 " ,
3
+ "version" : " 0.10.2 " ,
4
4
"description" : " WebSocket client for the TD Ameritrade wsjson API" ,
5
5
"main" : " dist/web.bundle.js" ,
6
6
"types" : " dist/web.d.ts" ,
Original file line number Diff line number Diff line change @@ -98,7 +98,9 @@ export default class WsJsonClientProxy implements WsJsonClient {
98
98
const { buffer, socket } = this ;
99
99
return new Promise ( ( resolve , reject ) => {
100
100
socket . onmessage = ( { data } ) => {
101
- buffer . emit ( JSON . parse ( data as string ) as ProxiedResponse ) ;
101
+ // make sure date objects are reconstructed across the wire
102
+ const parsedMsg = JSON . parse ( data as string , dateReviver ) ;
103
+ buffer . emit ( parsedMsg as ProxiedResponse ) ;
102
104
} ;
103
105
socket . onopen = ( ) => {
104
106
logger ( "proxy ws connection opened" ) ;
@@ -271,3 +273,14 @@ export default class WsJsonClientProxy implements WsJsonClient {
271
273
. map ( ( { response } ) => response as T ) ;
272
274
}
273
275
}
276
+
277
+ function dateReviver ( _ : string , value : any ) : any {
278
+ if ( typeof value === "string" ) {
279
+ // Regular expression to check if the string matches ISO 8601 date format
280
+ const isoDateRegex = / ^ \d { 4 } - \d { 2 } - \d { 2 } T \d { 2 } : \d { 2 } : \d { 2 } .\d { 3 } Z $ / ;
281
+ if ( isoDateRegex . test ( value ) ) {
282
+ return new Date ( value ) ;
283
+ }
284
+ }
285
+ return value ; // return the value unchanged if not a date string
286
+ }
Original file line number Diff line number Diff line change @@ -177,9 +177,10 @@ async function run() {
177
177
const { client } = await authClient . authenticateWithRetry ( token ) ;
178
178
const app = new TestApp ( client ) ;
179
179
await Promise . all ( [
180
- app . quotes ( [ "ABNB" , "UBER" ] ) ,
181
- app . accountPositions ( ) ,
180
+ // app.quotes(["ABNB", "UBER"]),
181
+ // app.accountPositions(),
182
182
app . optionChain ( "TSLA" ) ,
183
+ // app.optionChainQuotes("AAPL"),
183
184
] ) ;
184
185
}
185
186
You can’t perform that action at this time.
0 commit comments