@chainstream-io/sdk 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -663,6 +663,35 @@ var StreamApi = class {
663
663
  "subscribePairCandles"
664
664
  );
665
665
  }
666
+ /**
667
+ * Parse token stat data for a specific time window
668
+ * @param data - Raw WebSocket data
669
+ * @param suffix - Time window suffix (e.g., "1m", "5m", "1h", "1W", "1M")
670
+ */
671
+ parseTokenStatWindow(data, suffix) {
672
+ return {
673
+ [`buys${suffix}`]: data[`b${suffix}`],
674
+ [`sells${suffix}`]: data[`s${suffix}`],
675
+ [`buyers${suffix}`]: data[`be${suffix}`],
676
+ [`sellers${suffix}`]: data[`se${suffix}`],
677
+ [`buyVolumeInUsd${suffix}`]: this.formatScientificNotation(data[`bviu${suffix}`]),
678
+ [`sellVolumeInUsd${suffix}`]: this.formatScientificNotation(data[`sviu${suffix}`]),
679
+ [`price${suffix}`]: this.formatScientificNotation(data[`p${suffix}`]),
680
+ [`openInUsd${suffix}`]: this.formatScientificNotation(data[`oiu${suffix}`]),
681
+ [`closeInUsd${suffix}`]: this.formatScientificNotation(data[`ciu${suffix}`]),
682
+ [`volumeChangeRatio${suffix}`]: this.formatScientificNotation(data[`vpc${suffix}`]),
683
+ [`trades${suffix}`]: data[`tr${suffix}`],
684
+ [`dappProgramCount${suffix}`]: data[`dpc${suffix}`],
685
+ [`poolCount${suffix}`]: data[`pc${suffix}`],
686
+ [`liquidityInUsd${suffix}`]: this.formatScientificNotation(data[`liq${suffix}`]),
687
+ [`liquidityChangeRatio${suffix}`]: this.formatScientificNotation(data[`lpc${suffix}`])
688
+ };
689
+ }
690
+ /**
691
+ * Subscribe to token trade statistics
692
+ * Channel: dex-token-stats:{chain}_{tokenAddress}
693
+ * Time windows: 1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 24h, 1W, 1M
694
+ */
666
695
  subscribeTokenStats({
667
696
  chain,
668
697
  tokenAddress,
@@ -670,76 +699,24 @@ var StreamApi = class {
670
699
  filter
671
700
  }) {
672
701
  const channel = `dex-token-stats:${chain}_${tokenAddress}`;
702
+ const timeWindows = ["1m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "24h", "1W", "1M"];
673
703
  return this.subscribe(
674
704
  channel,
675
- (data) => callback({
676
- address: data.a,
677
- timestamp: data.t,
678
- buys1m: data.b1m,
679
- sells1m: data.s1m,
680
- buyers1m: data.be1m,
681
- sellers1m: data.se1m,
682
- buyVolumeInUsd1m: this.formatScientificNotation(data.bviu1m),
683
- sellVolumeInUsd1m: this.formatScientificNotation(data.sviu1m),
684
- price1m: this.formatScientificNotation(data.p1m),
685
- openInUsd1m: this.formatScientificNotation(data.oiu1m),
686
- closeInUsd1m: this.formatScientificNotation(data.ciu1m),
687
- buys5m: data.b5m,
688
- sells5m: data.s5m,
689
- buyers5m: data.be5m,
690
- sellers5m: data.se5m,
691
- buyVolumeInUsd5m: this.formatScientificNotation(data.bviu5m),
692
- sellVolumeInUsd5m: this.formatScientificNotation(data.sviu5m),
693
- price5m: this.formatScientificNotation(data.p5m),
694
- openInUsd5m: this.formatScientificNotation(data.oiu5m),
695
- closeInUsd5m: this.formatScientificNotation(data.ciu5m),
696
- buys15m: data.b15m,
697
- sells15m: data.s15m,
698
- buyers15m: data.be15m,
699
- sellers15m: data.se15m,
700
- buyVolumeInUsd15m: this.formatScientificNotation(data.bviu15m),
701
- sellVolumeInUsd15m: this.formatScientificNotation(data.sviu15m),
702
- price15m: this.formatScientificNotation(data.p15m),
703
- openInUsd15m: this.formatScientificNotation(data.oiu15m),
704
- closeInUsd15m: this.formatScientificNotation(data.ciu15m),
705
- buys30m: data.b30m,
706
- sells30m: data.s30m,
707
- buyers30m: data.be30m,
708
- sellers30m: data.se30m,
709
- buyVolumeInUsd30m: this.formatScientificNotation(data.bviu30m),
710
- sellVolumeInUsd30m: this.formatScientificNotation(data.sviu30m),
711
- price30m: this.formatScientificNotation(data.p30m),
712
- openInUsd30m: this.formatScientificNotation(data.oiu30m),
713
- closeInUsd30m: this.formatScientificNotation(data.ciu30m),
714
- buys1h: data.b1h,
715
- sells1h: data.s1h,
716
- buyers1h: data.be1h,
717
- sellers1h: data.se1h,
718
- buyVolumeInUsd1h: this.formatScientificNotation(data.bviu1h),
719
- sellVolumeInUsd1h: this.formatScientificNotation(data.sviu1h),
720
- price1h: this.formatScientificNotation(data.p1h),
721
- openInUsd1h: this.formatScientificNotation(data.oiu1h),
722
- closeInUsd1h: this.formatScientificNotation(data.ciu1h),
723
- buys4h: data.b4h,
724
- sells4h: data.s4h,
725
- buyers4h: data.be4h,
726
- sellers4h: data.se4h,
727
- buyVolumeInUsd4h: this.formatScientificNotation(data.bviu4h),
728
- sellVolumeInUsd4h: this.formatScientificNotation(data.sviu4h),
729
- price4h: this.formatScientificNotation(data.p4h),
730
- openInUsd4h: this.formatScientificNotation(data.oiu4h),
731
- closeInUsd4h: this.formatScientificNotation(data.ciu4h),
732
- buys24h: data.b24h,
733
- sells24h: data.s24h,
734
- buyers24h: data.be24h,
735
- sellers24h: data.se24h,
736
- buyVolumeInUsd24h: this.formatScientificNotation(data.bviu24h),
737
- sellVolumeInUsd24h: this.formatScientificNotation(data.sviu24h),
738
- price24h: this.formatScientificNotation(data.p24h),
739
- openInUsd24h: this.formatScientificNotation(data.oiu24h),
740
- closeInUsd24h: this.formatScientificNotation(data.ciu24h),
741
- price: this.formatScientificNotation(data.p)
742
- }),
705
+ (data) => {
706
+ const windowData = timeWindows.reduce(
707
+ (acc, suffix) => ({
708
+ ...acc,
709
+ ...this.parseTokenStatWindow(data, suffix)
710
+ }),
711
+ {}
712
+ );
713
+ callback({
714
+ address: data.a,
715
+ timestamp: data.t,
716
+ price: this.formatScientificNotation(data.p),
717
+ ...windowData
718
+ });
719
+ },
743
720
  filter,
744
721
  "subscribeTokenStats"
745
722
  );