@chainstream-io/sdk 0.2.8 → 0.2.9

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.
package/dist/index.cjs CHANGED
@@ -871,6 +871,35 @@ var StreamApi = class {
871
871
  "subscribePairCandles"
872
872
  );
873
873
  }
874
+ /**
875
+ * Parse token stat data for a specific time window
876
+ * @param data - Raw WebSocket data
877
+ * @param suffix - Time window suffix (e.g., "1m", "5m", "1h", "1W", "1M")
878
+ */
879
+ parseTokenStatWindow(data, suffix) {
880
+ return {
881
+ [`buys${suffix}`]: data[`b${suffix}`],
882
+ [`sells${suffix}`]: data[`s${suffix}`],
883
+ [`buyers${suffix}`]: data[`be${suffix}`],
884
+ [`sellers${suffix}`]: data[`se${suffix}`],
885
+ [`buyVolumeInUsd${suffix}`]: this.formatScientificNotation(data[`bviu${suffix}`]),
886
+ [`sellVolumeInUsd${suffix}`]: this.formatScientificNotation(data[`sviu${suffix}`]),
887
+ [`price${suffix}`]: this.formatScientificNotation(data[`p${suffix}`]),
888
+ [`openInUsd${suffix}`]: this.formatScientificNotation(data[`oiu${suffix}`]),
889
+ [`closeInUsd${suffix}`]: this.formatScientificNotation(data[`ciu${suffix}`]),
890
+ [`volumeChangeRatio${suffix}`]: this.formatScientificNotation(data[`vpc${suffix}`]),
891
+ [`trades${suffix}`]: data[`tr${suffix}`],
892
+ [`dappProgramCount${suffix}`]: data[`dpc${suffix}`],
893
+ [`poolCount${suffix}`]: data[`pc${suffix}`],
894
+ [`liquidityInUsd${suffix}`]: this.formatScientificNotation(data[`liq${suffix}`]),
895
+ [`liquidityChangeRatio${suffix}`]: this.formatScientificNotation(data[`lpc${suffix}`])
896
+ };
897
+ }
898
+ /**
899
+ * Subscribe to token trade statistics
900
+ * Channel: dex-token-stats:{chain}_{tokenAddress}
901
+ * Time windows: 1m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 24h, 1W, 1M
902
+ */
874
903
  subscribeTokenStats({
875
904
  chain,
876
905
  tokenAddress,
@@ -878,76 +907,24 @@ var StreamApi = class {
878
907
  filter
879
908
  }) {
880
909
  const channel = `dex-token-stats:${chain}_${tokenAddress}`;
910
+ const timeWindows = ["1m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "24h", "1W", "1M"];
881
911
  return this.subscribe(
882
912
  channel,
883
- (data) => callback({
884
- address: data.a,
885
- timestamp: data.t,
886
- buys1m: data.b1m,
887
- sells1m: data.s1m,
888
- buyers1m: data.be1m,
889
- sellers1m: data.se1m,
890
- buyVolumeInUsd1m: this.formatScientificNotation(data.bviu1m),
891
- sellVolumeInUsd1m: this.formatScientificNotation(data.sviu1m),
892
- price1m: this.formatScientificNotation(data.p1m),
893
- openInUsd1m: this.formatScientificNotation(data.oiu1m),
894
- closeInUsd1m: this.formatScientificNotation(data.ciu1m),
895
- buys5m: data.b5m,
896
- sells5m: data.s5m,
897
- buyers5m: data.be5m,
898
- sellers5m: data.se5m,
899
- buyVolumeInUsd5m: this.formatScientificNotation(data.bviu5m),
900
- sellVolumeInUsd5m: this.formatScientificNotation(data.sviu5m),
901
- price5m: this.formatScientificNotation(data.p5m),
902
- openInUsd5m: this.formatScientificNotation(data.oiu5m),
903
- closeInUsd5m: this.formatScientificNotation(data.ciu5m),
904
- buys15m: data.b15m,
905
- sells15m: data.s15m,
906
- buyers15m: data.be15m,
907
- sellers15m: data.se15m,
908
- buyVolumeInUsd15m: this.formatScientificNotation(data.bviu15m),
909
- sellVolumeInUsd15m: this.formatScientificNotation(data.sviu15m),
910
- price15m: this.formatScientificNotation(data.p15m),
911
- openInUsd15m: this.formatScientificNotation(data.oiu15m),
912
- closeInUsd15m: this.formatScientificNotation(data.ciu15m),
913
- buys30m: data.b30m,
914
- sells30m: data.s30m,
915
- buyers30m: data.be30m,
916
- sellers30m: data.se30m,
917
- buyVolumeInUsd30m: this.formatScientificNotation(data.bviu30m),
918
- sellVolumeInUsd30m: this.formatScientificNotation(data.sviu30m),
919
- price30m: this.formatScientificNotation(data.p30m),
920
- openInUsd30m: this.formatScientificNotation(data.oiu30m),
921
- closeInUsd30m: this.formatScientificNotation(data.ciu30m),
922
- buys1h: data.b1h,
923
- sells1h: data.s1h,
924
- buyers1h: data.be1h,
925
- sellers1h: data.se1h,
926
- buyVolumeInUsd1h: this.formatScientificNotation(data.bviu1h),
927
- sellVolumeInUsd1h: this.formatScientificNotation(data.sviu1h),
928
- price1h: this.formatScientificNotation(data.p1h),
929
- openInUsd1h: this.formatScientificNotation(data.oiu1h),
930
- closeInUsd1h: this.formatScientificNotation(data.ciu1h),
931
- buys4h: data.b4h,
932
- sells4h: data.s4h,
933
- buyers4h: data.be4h,
934
- sellers4h: data.se4h,
935
- buyVolumeInUsd4h: this.formatScientificNotation(data.bviu4h),
936
- sellVolumeInUsd4h: this.formatScientificNotation(data.sviu4h),
937
- price4h: this.formatScientificNotation(data.p4h),
938
- openInUsd4h: this.formatScientificNotation(data.oiu4h),
939
- closeInUsd4h: this.formatScientificNotation(data.ciu4h),
940
- buys24h: data.b24h,
941
- sells24h: data.s24h,
942
- buyers24h: data.be24h,
943
- sellers24h: data.se24h,
944
- buyVolumeInUsd24h: this.formatScientificNotation(data.bviu24h),
945
- sellVolumeInUsd24h: this.formatScientificNotation(data.sviu24h),
946
- price24h: this.formatScientificNotation(data.p24h),
947
- openInUsd24h: this.formatScientificNotation(data.oiu24h),
948
- closeInUsd24h: this.formatScientificNotation(data.ciu24h),
949
- price: this.formatScientificNotation(data.p)
950
- }),
913
+ (data) => {
914
+ const windowData = timeWindows.reduce(
915
+ (acc, suffix) => ({
916
+ ...acc,
917
+ ...this.parseTokenStatWindow(data, suffix)
918
+ }),
919
+ {}
920
+ );
921
+ callback({
922
+ address: data.a,
923
+ timestamp: data.t,
924
+ price: this.formatScientificNotation(data.p),
925
+ ...windowData
926
+ });
927
+ },
951
928
  filter,
952
929
  "subscribeTokenStats"
953
930
  );