-
Notifications
You must be signed in to change notification settings - Fork 15
feat(perps): expose server time #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@polymarket/bindings': minor | ||
| '@polymarket/client': minor | ||
| --- | ||
|
|
||
| Exposes the public Perps server clock. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { | ||
| type EpochMilliseconds, | ||
| type PaginationCursor, | ||
| PaginationCursorSchema, | ||
| toPaginationCursor, | ||
|
|
@@ -12,6 +13,7 @@ import { | |
| FetchPerpsStatisticsResponseSchema, | ||
| FetchPerpsTickersResponseSchema, | ||
| FetchPerpsTradesResponseSchema, | ||
| GetServerTimeResponseSchema, | ||
| type PerpsBook, | ||
| PerpsBookSchema, | ||
| type PerpsCandle, | ||
|
|
@@ -793,6 +795,48 @@ export async function fetchPerpsFees( | |
| return response.feeSchedule; | ||
| } | ||
|
|
||
| /** | ||
| * @experimental This API may change in a breaking way in any release, including patch releases. | ||
| */ | ||
| export type GetServerTimeError = | ||
| | RateLimitError | ||
| | RequestRejectedError | ||
| | TransportError | ||
| | UnexpectedResponseError; | ||
| /** | ||
| * @experimental This API may change in a breaking way in any release, including patch releases. | ||
| */ | ||
| export const GetServerTimeError = makeErrorGuard( | ||
| RateLimitError, | ||
| RequestRejectedError, | ||
| TransportError, | ||
| UnexpectedResponseError, | ||
| ); | ||
|
|
||
| /** | ||
| * Gets the current Perps server time as a Unix timestamp in milliseconds. | ||
| * | ||
| * @remarks | ||
| * This is a low-level function. Most SDK consumers should prefer the client instance API. | ||
| * This read does not change how the SDK timestamps or signs Perps requests. | ||
| * | ||
| * @throws {@link GetServerTimeError} | ||
| * Thrown on failure. | ||
| * | ||
| * @experimental This API may change in a breaking way in any release, including patch releases. | ||
| */ | ||
| export async function getServerTime( | ||
|
kartojal marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What developer workflow is this standalone read intended to solve? DEV-466 starts by asking where server time is needed and whether the SDK should abstract clock synchronization, but this PR leaves signed requests on
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Checked both claims against head
My read: the raw endpoint read is a reasonable primitive, but as merged it is a probe nobody in the SDK consumes, and the TSDoc's "does not change how the SDK timestamps or signs" is documenting the gap rather than closing it. Either land the offset alongside it or state the standalone use case in the TSDoc. |
||
| client: BaseClient, | ||
| ): Promise<EpochMilliseconds> { | ||
| const response = await unwrap( | ||
| client.perps | ||
| .get('/v1/info/time') | ||
| .andThen(validateWith(GetServerTimeResponseSchema)), | ||
| ); | ||
|
|
||
| return response.time; | ||
| } | ||
|
|
||
| const PerpsCandlesCursorStateSchema = z.object({ | ||
| kind: z.literal('perpsCandles'), | ||
| instrumentId: PerpsInstrumentIdSchema, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.