-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
optionSeries/quotes
message support (#62)
* feat: Add optionSeries/quotes message support * update readme
- Loading branch information
Showing
9 changed files
with
134 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import WebSocketApiMessageHandler, { | ||
newPayload, | ||
} from "./webSocketApiMessageHandler"; | ||
import { RawPayloadRequest, RawPayloadResponse } from "../tdaWsJsonTypes"; | ||
import { ApiService } from "./apiService"; | ||
|
||
export type OptionSeriesQuote = { | ||
name: string; | ||
values: { | ||
IMPLIED_VOLATILITY: number; | ||
SERIES_EXPECTED_MOVE: number; | ||
}; | ||
}; | ||
|
||
export type OptionSeriesQuotesPatchResponse = { | ||
patches: { | ||
op: string; | ||
path: string; | ||
value: any; | ||
Check warning on line 19 in src/client/services/optionSeriesQuotesMessageHandler.ts GitHub Actions / build (16.x)
Check warning on line 19 in src/client/services/optionSeriesQuotesMessageHandler.ts GitHub Actions / build (18.x)
|
||
}; | ||
service: "optionSeries/quotes"; | ||
}; | ||
|
||
export type OptionSeriesQuotesSnapshotResponse = { | ||
series: OptionSeriesQuote[]; | ||
service: "optionSeries/quotes"; | ||
}; | ||
|
||
export type OptionSeriesQuotesResponse = | ||
| OptionSeriesQuotesSnapshotResponse | ||
| OptionSeriesQuotesPatchResponse; | ||
|
||
export default class OptionSeriesQuotesMessageHandler | ||
implements WebSocketApiMessageHandler<string, OptionSeriesQuotesResponse> | ||
{ | ||
buildRequest(symbol: string): RawPayloadRequest { | ||
return newPayload({ | ||
header: { | ||
service: "optionSeries/quotes", | ||
id: "optionSeriesQuotes", | ||
ver: 0, | ||
}, | ||
params: { | ||
underlying: symbol, | ||
exchange: "BEST", | ||
fields: ["IMPLIED_VOLATILITY", "SERIES_EXPECTED_MOVE"], | ||
}, | ||
}); | ||
} | ||
|
||
parseResponse(message: RawPayloadResponse): OptionSeriesQuotesResponse { | ||
const { payload } = message; | ||
const [{ body }] = payload; | ||
if ("series" in body) { | ||
// snapshot response | ||
const { series } = body as unknown as { series: OptionSeriesQuote[] }; | ||
return { series, service: "optionSeries/quotes" }; | ||
} else { | ||
// patch response | ||
const { patches } = body as unknown as { | ||
patches: OptionSeriesQuotesPatchResponse["patches"]; | ||
}; | ||
return { patches, service: "optionSeries/quotes" }; | ||
} | ||
} | ||
|
||
service: ApiService = "optionSeries/quotes"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters