history.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* eslint-disable no-console */
  2. import { displayParsedPrices } from "./util.js";
  3. import { PythLazerClient } from "../src/index.js";
  4. const client = await PythLazerClient.create({
  5. token: "your-token-here",
  6. logger: console,
  7. });
  8. // Example 1: Get latest price for BTC using feed IDs
  9. console.log("\n=== Example 1: Latest BTC price (requested with feed ID) ===");
  10. const response1 = await client.get_latest_price({
  11. priceFeedIds: [1],
  12. properties: ["price", "confidence", "exponent"],
  13. formats: [],
  14. jsonBinaryEncoding: "hex",
  15. parsed: true,
  16. channel: "fixed_rate@200ms",
  17. });
  18. displayParsedPrices(response1);
  19. // Example 2: Get latest price using symbols
  20. console.log("\n=== Example 2: Latest ETH price (requested with symbols) ===");
  21. const response2 = await client.get_latest_price({
  22. priceFeedIds: [2],
  23. properties: ["price", "confidence", "exponent"],
  24. formats: [],
  25. parsed: true,
  26. channel: "real_time",
  27. });
  28. displayParsedPrices(response2);
  29. // Example 3: Get historical price at specific timestamp
  30. console.log("\n=== Example 3: Historical BTC price at timestamp ===");
  31. const timestamp = 1_754_348_458_565_000;
  32. console.log(
  33. `Requesting price from timestamp: ${timestamp.toString()} (${new Date(timestamp / 1000).toISOString()})`,
  34. );
  35. const response3 = await client.get_price({
  36. timestamp: timestamp,
  37. priceFeedIds: [1],
  38. properties: ["price", "confidence", "exponent"],
  39. formats: [],
  40. parsed: true,
  41. channel: "real_time",
  42. });
  43. displayParsedPrices(response3);