@polymarbot/shared 0.3.6 → 0.3.8
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/hash.cjs +38 -0
- package/hash.d.cts +5 -0
- package/hash.d.ts +5 -0
- package/hash.js +14 -0
- package/index.cjs +1 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/markets/utils.cjs +66 -6
- package/markets/utils.d.cts +9 -2
- package/markets/utils.d.ts +9 -2
- package/markets/utils.js +63 -4
- package/package.json +11 -1
package/hash.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/hash.ts
|
|
21
|
+
var hash_exports = {};
|
|
22
|
+
__export(hash_exports, {
|
|
23
|
+
md5: () => md5,
|
|
24
|
+
sha256: () => sha256
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(hash_exports);
|
|
27
|
+
var import_crypto = require("crypto");
|
|
28
|
+
function sha256(input) {
|
|
29
|
+
return (0, import_crypto.createHash)("sha256").update(input).digest("hex");
|
|
30
|
+
}
|
|
31
|
+
function md5(input) {
|
|
32
|
+
return (0, import_crypto.createHash)("md5").update(input).digest("hex");
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
md5,
|
|
37
|
+
sha256
|
|
38
|
+
});
|
package/hash.d.cts
ADDED
package/hash.d.ts
ADDED
package/hash.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./chunk-JSBRDJBE.js";
|
|
2
|
+
|
|
3
|
+
// src/utils/hash.ts
|
|
4
|
+
import { createHash } from "crypto";
|
|
5
|
+
function sha256(input) {
|
|
6
|
+
return createHash("sha256").update(input).digest("hex");
|
|
7
|
+
}
|
|
8
|
+
function md5(input) {
|
|
9
|
+
return createHash("md5").update(input).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
md5,
|
|
13
|
+
sha256
|
|
14
|
+
};
|
package/index.cjs
CHANGED
package/index.d.cts
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/markets/utils.cjs
CHANGED
|
@@ -603,8 +603,9 @@ __export(utils_exports, {
|
|
|
603
603
|
generateMarketUrl: () => generateMarketUrl,
|
|
604
604
|
getIntervalSeconds: () => getIntervalSeconds,
|
|
605
605
|
parseIntervalFromSlug: () => parseIntervalFromSlug,
|
|
606
|
-
|
|
607
|
-
parseSymbolFromSlug: () => parseSymbolFromSlug
|
|
606
|
+
parseSlug: () => parseSlug,
|
|
607
|
+
parseSymbolFromSlug: () => parseSymbolFromSlug,
|
|
608
|
+
parseTimeRangeFromSlug: () => parseTimeRangeFromSlug
|
|
608
609
|
});
|
|
609
610
|
module.exports = __toCommonJS(utils_exports);
|
|
610
611
|
|
|
@@ -733,10 +734,68 @@ function getIntervalSeconds(interval) {
|
|
|
733
734
|
};
|
|
734
735
|
return intervalSecondsMap[interval];
|
|
735
736
|
}
|
|
736
|
-
function
|
|
737
|
+
function parseTimeRangeFromSlug(slug, referenceYear) {
|
|
738
|
+
const interval = parseIntervalFromSlug(slug);
|
|
739
|
+
if (!interval) {
|
|
740
|
+
return { startTime: null, endTime: null };
|
|
741
|
+
}
|
|
742
|
+
const intervalSeconds = getIntervalSeconds(interval);
|
|
743
|
+
let startTime = null;
|
|
744
|
+
const lowerSlug = slug.toLowerCase();
|
|
745
|
+
if (interval === "15m" /* M15 */ || interval === "4h" /* H4 */) {
|
|
746
|
+
const match = lowerSlug.match(/-updown-(?:15m|4h)-(\d+)$/);
|
|
747
|
+
if (match) {
|
|
748
|
+
startTime = parseInt(match[1], 10);
|
|
749
|
+
}
|
|
750
|
+
} else if (interval === "1h" /* H1 */) {
|
|
751
|
+
const match = lowerSlug.match(/-up-or-down-(\w+)-(\d+)-(\d+)(am|pm)-et$/);
|
|
752
|
+
if (match) {
|
|
753
|
+
const [, monthName, day, hour, ampm] = match;
|
|
754
|
+
const monthIndex = MONTH_NAMES.indexOf(monthName);
|
|
755
|
+
if (monthIndex !== -1) {
|
|
756
|
+
const year = referenceYear ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
757
|
+
let hour24 = parseInt(hour, 10);
|
|
758
|
+
if (ampm === "pm" && hour24 !== 12) {
|
|
759
|
+
hour24 += 12;
|
|
760
|
+
} else if (ampm === "am" && hour24 === 12) {
|
|
761
|
+
hour24 = 0;
|
|
762
|
+
}
|
|
763
|
+
const etTime = dayjs_default.tz(
|
|
764
|
+
`${year}-${String(monthIndex + 1).padStart(2, "0")}-${String(day).padStart(2, "0")} ${String(hour24).padStart(2, "0")}:00:00`,
|
|
765
|
+
"America/New_York"
|
|
766
|
+
);
|
|
767
|
+
startTime = etTime.unix();
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
} else if (interval === "1d" /* D1 */) {
|
|
771
|
+
const match = lowerSlug.match(/-up-or-down-on-(\w+)-(\d+)$/);
|
|
772
|
+
if (match) {
|
|
773
|
+
const [, monthName, day] = match;
|
|
774
|
+
const monthIndex = MONTH_NAMES.indexOf(monthName);
|
|
775
|
+
if (monthIndex !== -1) {
|
|
776
|
+
const year = referenceYear ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
777
|
+
const utcTime = dayjs_default.utc(
|
|
778
|
+
`${year}-${String(monthIndex + 1).padStart(2, "0")}-${String(day).padStart(2, "0")} 00:00:00`
|
|
779
|
+
);
|
|
780
|
+
startTime = utcTime.unix();
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (startTime === null) {
|
|
785
|
+
return { startTime: null, endTime: null };
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
startTime,
|
|
789
|
+
endTime: startTime + intervalSeconds
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
function parseSlug(slug, referenceYear) {
|
|
793
|
+
const { startTime, endTime } = parseTimeRangeFromSlug(slug, referenceYear);
|
|
737
794
|
return {
|
|
738
795
|
symbol: parseSymbolFromSlug(slug),
|
|
739
|
-
interval: parseIntervalFromSlug(slug)
|
|
796
|
+
interval: parseIntervalFromSlug(slug),
|
|
797
|
+
startTime,
|
|
798
|
+
endTime
|
|
740
799
|
};
|
|
741
800
|
}
|
|
742
801
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -751,6 +810,7 @@ function parseSymbolAndIntervalFromSlug(slug) {
|
|
|
751
810
|
generateMarketUrl,
|
|
752
811
|
getIntervalSeconds,
|
|
753
812
|
parseIntervalFromSlug,
|
|
754
|
-
|
|
755
|
-
parseSymbolFromSlug
|
|
813
|
+
parseSlug,
|
|
814
|
+
parseSymbolFromSlug,
|
|
815
|
+
parseTimeRangeFromSlug
|
|
756
816
|
});
|
package/markets/utils.d.cts
CHANGED
|
@@ -21,9 +21,16 @@ declare function parseIntervalFromSlug(slug: string): SupportedInterval | null;
|
|
|
21
21
|
|
|
22
22
|
declare function getIntervalSeconds(interval: SupportedInterval): number;
|
|
23
23
|
|
|
24
|
-
declare function
|
|
24
|
+
declare function parseTimeRangeFromSlug(slug: string, referenceYear?: number): {
|
|
25
|
+
startTime: number | null;
|
|
26
|
+
endTime: number | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare function parseSlug(slug: string, referenceYear?: number): {
|
|
25
30
|
symbol: SupportedSymbol | null;
|
|
26
31
|
interval: SupportedInterval | null;
|
|
32
|
+
startTime: number | null;
|
|
33
|
+
endTime: number | null;
|
|
27
34
|
};
|
|
28
35
|
|
|
29
|
-
export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl, getIntervalSeconds, parseIntervalFromSlug,
|
|
36
|
+
export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl, getIntervalSeconds, parseIntervalFromSlug, parseSlug, parseSymbolFromSlug, parseTimeRangeFromSlug };
|
package/markets/utils.d.ts
CHANGED
|
@@ -21,9 +21,16 @@ declare function parseIntervalFromSlug(slug: string): SupportedInterval | null;
|
|
|
21
21
|
|
|
22
22
|
declare function getIntervalSeconds(interval: SupportedInterval): number;
|
|
23
23
|
|
|
24
|
-
declare function
|
|
24
|
+
declare function parseTimeRangeFromSlug(slug: string, referenceYear?: number): {
|
|
25
|
+
startTime: number | null;
|
|
26
|
+
endTime: number | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare function parseSlug(slug: string, referenceYear?: number): {
|
|
25
30
|
symbol: SupportedSymbol | null;
|
|
26
31
|
interval: SupportedInterval | null;
|
|
32
|
+
startTime: number | null;
|
|
33
|
+
endTime: number | null;
|
|
27
34
|
};
|
|
28
35
|
|
|
29
|
-
export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl, getIntervalSeconds, parseIntervalFromSlug,
|
|
36
|
+
export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl, getIntervalSeconds, parseIntervalFromSlug, parseSlug, parseSymbolFromSlug, parseTimeRangeFromSlug };
|
package/markets/utils.js
CHANGED
|
@@ -682,10 +682,68 @@ function getIntervalSeconds(interval) {
|
|
|
682
682
|
};
|
|
683
683
|
return intervalSecondsMap[interval];
|
|
684
684
|
}
|
|
685
|
-
function
|
|
685
|
+
function parseTimeRangeFromSlug(slug, referenceYear) {
|
|
686
|
+
const interval = parseIntervalFromSlug(slug);
|
|
687
|
+
if (!interval) {
|
|
688
|
+
return { startTime: null, endTime: null };
|
|
689
|
+
}
|
|
690
|
+
const intervalSeconds = getIntervalSeconds(interval);
|
|
691
|
+
let startTime = null;
|
|
692
|
+
const lowerSlug = slug.toLowerCase();
|
|
693
|
+
if (interval === "15m" /* M15 */ || interval === "4h" /* H4 */) {
|
|
694
|
+
const match = lowerSlug.match(/-updown-(?:15m|4h)-(\d+)$/);
|
|
695
|
+
if (match) {
|
|
696
|
+
startTime = parseInt(match[1], 10);
|
|
697
|
+
}
|
|
698
|
+
} else if (interval === "1h" /* H1 */) {
|
|
699
|
+
const match = lowerSlug.match(/-up-or-down-(\w+)-(\d+)-(\d+)(am|pm)-et$/);
|
|
700
|
+
if (match) {
|
|
701
|
+
const [, monthName, day, hour, ampm] = match;
|
|
702
|
+
const monthIndex = MONTH_NAMES.indexOf(monthName);
|
|
703
|
+
if (monthIndex !== -1) {
|
|
704
|
+
const year = referenceYear ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
705
|
+
let hour24 = parseInt(hour, 10);
|
|
706
|
+
if (ampm === "pm" && hour24 !== 12) {
|
|
707
|
+
hour24 += 12;
|
|
708
|
+
} else if (ampm === "am" && hour24 === 12) {
|
|
709
|
+
hour24 = 0;
|
|
710
|
+
}
|
|
711
|
+
const etTime = dayjs_default.tz(
|
|
712
|
+
`${year}-${String(monthIndex + 1).padStart(2, "0")}-${String(day).padStart(2, "0")} ${String(hour24).padStart(2, "0")}:00:00`,
|
|
713
|
+
"America/New_York"
|
|
714
|
+
);
|
|
715
|
+
startTime = etTime.unix();
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
} else if (interval === "1d" /* D1 */) {
|
|
719
|
+
const match = lowerSlug.match(/-up-or-down-on-(\w+)-(\d+)$/);
|
|
720
|
+
if (match) {
|
|
721
|
+
const [, monthName, day] = match;
|
|
722
|
+
const monthIndex = MONTH_NAMES.indexOf(monthName);
|
|
723
|
+
if (monthIndex !== -1) {
|
|
724
|
+
const year = referenceYear ?? (/* @__PURE__ */ new Date()).getFullYear();
|
|
725
|
+
const utcTime = dayjs_default.utc(
|
|
726
|
+
`${year}-${String(monthIndex + 1).padStart(2, "0")}-${String(day).padStart(2, "0")} 00:00:00`
|
|
727
|
+
);
|
|
728
|
+
startTime = utcTime.unix();
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (startTime === null) {
|
|
733
|
+
return { startTime: null, endTime: null };
|
|
734
|
+
}
|
|
735
|
+
return {
|
|
736
|
+
startTime,
|
|
737
|
+
endTime: startTime + intervalSeconds
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function parseSlug(slug, referenceYear) {
|
|
741
|
+
const { startTime, endTime } = parseTimeRangeFromSlug(slug, referenceYear);
|
|
686
742
|
return {
|
|
687
743
|
symbol: parseSymbolFromSlug(slug),
|
|
688
|
-
interval: parseIntervalFromSlug(slug)
|
|
744
|
+
interval: parseIntervalFromSlug(slug),
|
|
745
|
+
startTime,
|
|
746
|
+
endTime
|
|
689
747
|
};
|
|
690
748
|
}
|
|
691
749
|
export {
|
|
@@ -699,6 +757,7 @@ export {
|
|
|
699
757
|
generateMarketUrl,
|
|
700
758
|
getIntervalSeconds,
|
|
701
759
|
parseIntervalFromSlug,
|
|
702
|
-
|
|
703
|
-
parseSymbolFromSlug
|
|
760
|
+
parseSlug,
|
|
761
|
+
parseSymbolFromSlug,
|
|
762
|
+
parseTimeRangeFromSlug
|
|
704
763
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymarbot/shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -36,6 +36,16 @@
|
|
|
36
36
|
"default": "./crypto.cjs"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
+
"./hash": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./hash.d.ts",
|
|
42
|
+
"default": "./hash.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./hash.d.cts",
|
|
46
|
+
"default": "./hash.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
39
49
|
"./loadEnv": {
|
|
40
50
|
"import": {
|
|
41
51
|
"types": "./loadEnv.d.ts",
|