-
Notifications
You must be signed in to change notification settings - Fork 298
feat(lazer/js/sdk): add REST endpoints and examples #3075
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
feat(lazer/js/sdk): add REST endpoints and examples #3075
Conversation
- Add LazerClientConfig type wrapping WebSocketPoolConfig with historyServiceUrl - Implement get_symbols() method to query /v1/symbols endpoint - Add TypeScript interfaces for SymbolResponse and query parameters - Update example to demonstrate BTC symbol search and subscription - Add cross-fetch dependency for Node.js compatibility - Bump version to 2.1.0 following semver for new feature Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
…ce endpoints - Add TypeScript interfaces for LatestPriceRequest, PriceRequest, and JsonUpdate - Update LazerClientConfig to include routerServiceUrl with default - Implement get_latest_price() and get_price() HTTP methods in PythLazerClient - Create router-example.ts demonstrating all Router endpoint use cases - Bump version to 2.2.0 to reflect new Router service functionality - Add router-example script to package.json for easy testing Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
…ithub.com:pyth-network/pyth-crosschain into devin/1758582450-expand-lazer-sdk-history-support
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Some nitpicks.
|
||
console.log(`\u001B[36m${(index + 1).toString()}. ${displayName}\u001B[0m`); | ||
console.log( | ||
` 💰 Price: \u001B[32m$${readablePrice.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 8 })}\u001B[0m`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I feel like if we want to commit to doing things like coloring our logs, it's better to add something like chalk. Seeing ANSI codes just feels weird to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeahh didn't wanna add a dependency just for this since its not really service logs or a core part of the package.
// Print out the binary hex messages if you want: | ||
// if ("solana" in message.value) { | ||
// console.info("solana message:", message.value.solana?.toString("hex")); | ||
// } | ||
// if ("evm" in message.value) { | ||
// console.info("evm message:", message.value.evm?.toString("hex")); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left it in as a hint for people who want to use the binary message
// Ignore debug messages | ||
console.debug = () => {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be doing this at a file level? I feel like we should respect the log level that is passed into the execution call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah there is no console.setLevel
unfortunately, this is a common workaround to set "log level" when using console
directly as a logger. Functionally its the same as passing in a ts-log
instance or something, but again its just an example so didn't want to prescribe things like which logger to pass in.
LE_ECDSA: 1_296_547_300, | ||
LE_UNSIGNED: 1_499_680_012, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully maintaining this isn't a big problem. I wonder if we should set up something where we define the types in Rust somewhere once, and then derive types from it for other languages. Maybe @cprussin has some ideas. This is probably fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's a good point, i don't have a strong opinion here -- in the Hermes client, we get the types from the hermes /docs OpenAPI json, which seems as good a place as any to consider the source of truth for types. We don't have OpenAPI support yet in router yet though. There's some interesting projects out there for this as well: https://github.com/Aleph-Alpha/ts-rs
Summary
Add Lazer REST API support to
PythLazerClient
. Previously, the client was only focused on the WS streaming API. This PR adds support for our other consumer endpoints and makes the SDK more useful.get_symbols()
-- fetch feed metadata, with optionalquery
andasset
filtersget_latest_price()
-- fetch latest prices by ID or symbolget_price()
-- fetch historical prices by ID or symbolUpdate config. Now that the client also handles REST endpoints and not just WS, expanded the configuration to account for these. The config is now:
Add more examples to showcase different APIs. Check it out: https://asciinema.org/a/T4rLhqb3EAt2tM7dB1JtrngNA
pnpm run example:streaming
: streams prices over WS, parses them to human-friendly format using the exponent, and renders them in-place on the terminal to showcase the fast update ratepnpm run example:symbols
: get all symbols, search by symbol name and/or asset typepnpm run example:history
: get latest price and timestamped priceHow has this been tested?