index.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { PythLazerClient } from "../src/index.js";
  2. /* eslint-disable no-console */
  3. const client = new PythLazerClient("ws://127.0.0.1:1234/v1/stream", "ctoken1");
  4. client.addMessageListener((message) => {
  5. console.log("got message:", message);
  6. switch (message.type) {
  7. case "json": {
  8. if (message.value.type == "streamUpdated") {
  9. console.log(
  10. "stream updated for subscription",
  11. message.value.subscriptionId,
  12. ":",
  13. message.value.parsed?.priceFeeds
  14. );
  15. }
  16. break;
  17. }
  18. case "binary": {
  19. if ("solana" in message.value) {
  20. console.log("solana message:", message.value.solana?.toString("hex"));
  21. }
  22. if ("evm" in message.value) {
  23. console.log("evm message:", message.value.evm?.toString("hex"));
  24. }
  25. break;
  26. }
  27. }
  28. });
  29. client.ws.addEventListener("open", () => {
  30. client.send({
  31. type: "subscribe",
  32. subscriptionId: 1,
  33. priceFeedIds: [1, 2],
  34. properties: ["price"],
  35. chains: ["solana"],
  36. deliveryFormat: "json",
  37. channel: "fixed_rate@200ms",
  38. jsonBinaryEncoding: "hex",
  39. });
  40. });