@polymarbot/shared 0.3.5 → 0.3.6
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/markets/utils.cjs +65 -2
- package/markets/utils.d.cts +13 -2
- package/markets/utils.d.ts +13 -2
- package/markets/utils.js +60 -1
- package/package.json +1 -1
package/markets/utils.cjs
CHANGED
|
@@ -600,7 +600,11 @@ __export(utils_exports, {
|
|
|
600
600
|
generate1dSlug: () => generate1dSlug,
|
|
601
601
|
generate1hSlug: () => generate1hSlug,
|
|
602
602
|
generate4hSlug: () => generate4hSlug,
|
|
603
|
-
generateMarketUrl: () => generateMarketUrl
|
|
603
|
+
generateMarketUrl: () => generateMarketUrl,
|
|
604
|
+
getIntervalSeconds: () => getIntervalSeconds,
|
|
605
|
+
parseIntervalFromSlug: () => parseIntervalFromSlug,
|
|
606
|
+
parseSymbolAndIntervalFromSlug: () => parseSymbolAndIntervalFromSlug,
|
|
607
|
+
parseSymbolFromSlug: () => parseSymbolFromSlug
|
|
604
608
|
});
|
|
605
609
|
module.exports = __toCommonJS(utils_exports);
|
|
606
610
|
|
|
@@ -680,6 +684,61 @@ function calculatePeriodStartInET(intervalSeconds) {
|
|
|
680
684
|
const periodStartInET = Math.floor(nowInET / intervalSeconds) * intervalSeconds;
|
|
681
685
|
return periodStartInET + offset;
|
|
682
686
|
}
|
|
687
|
+
function parseSymbolFromSlug(slug) {
|
|
688
|
+
const lowerSlug = slug.toLowerCase();
|
|
689
|
+
for (const sym of SUPPORTED_SYMBOLS) {
|
|
690
|
+
const shortForm = sym.toLowerCase();
|
|
691
|
+
if (lowerSlug.startsWith(`${shortForm}-updown-`)) {
|
|
692
|
+
return sym;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
for (const sym of SUPPORTED_SYMBOLS) {
|
|
696
|
+
const fullName = SYMBOL_FULL_NAME_MAP[sym];
|
|
697
|
+
if (fullName && lowerSlug.startsWith(`${fullName}-up-or-down-`)) {
|
|
698
|
+
return sym;
|
|
699
|
+
}
|
|
700
|
+
const shortForm = sym.toLowerCase();
|
|
701
|
+
if (lowerSlug.startsWith(`${shortForm}-up-or-down-`)) {
|
|
702
|
+
return sym;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
function parseIntervalFromSlug(slug) {
|
|
708
|
+
const lowerSlug = slug.toLowerCase();
|
|
709
|
+
if (lowerSlug.includes("-updown-15m-")) {
|
|
710
|
+
return "15m" /* M15 */;
|
|
711
|
+
}
|
|
712
|
+
if (lowerSlug.includes("-updown-4h-")) {
|
|
713
|
+
return "4h" /* H4 */;
|
|
714
|
+
}
|
|
715
|
+
if (lowerSlug.match(/-up-or-down-\w+-\d+-\d+(am|pm)-et$/)) {
|
|
716
|
+
return "1h" /* H1 */;
|
|
717
|
+
}
|
|
718
|
+
if (lowerSlug.match(/-up-or-down-on-\w+-\d+$/)) {
|
|
719
|
+
return "1d" /* D1 */;
|
|
720
|
+
}
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
function getIntervalSeconds(interval) {
|
|
724
|
+
const intervalSecondsMap = {
|
|
725
|
+
["15m" /* M15 */]: 15 * 60,
|
|
726
|
+
// 900秒
|
|
727
|
+
["1h" /* H1 */]: 60 * 60,
|
|
728
|
+
// 3600秒
|
|
729
|
+
["4h" /* H4 */]: 4 * 60 * 60,
|
|
730
|
+
// 14400秒
|
|
731
|
+
["1d" /* D1 */]: 24 * 60 * 60
|
|
732
|
+
// 86400秒
|
|
733
|
+
};
|
|
734
|
+
return intervalSecondsMap[interval];
|
|
735
|
+
}
|
|
736
|
+
function parseSymbolAndIntervalFromSlug(slug) {
|
|
737
|
+
return {
|
|
738
|
+
symbol: parseSymbolFromSlug(slug),
|
|
739
|
+
interval: parseIntervalFromSlug(slug)
|
|
740
|
+
};
|
|
741
|
+
}
|
|
683
742
|
// Annotate the CommonJS export names for ESM import in node:
|
|
684
743
|
0 && (module.exports = {
|
|
685
744
|
SUPPORTED_SYMBOLS,
|
|
@@ -689,5 +748,9 @@ function calculatePeriodStartInET(intervalSeconds) {
|
|
|
689
748
|
generate1dSlug,
|
|
690
749
|
generate1hSlug,
|
|
691
750
|
generate4hSlug,
|
|
692
|
-
generateMarketUrl
|
|
751
|
+
generateMarketUrl,
|
|
752
|
+
getIntervalSeconds,
|
|
753
|
+
parseIntervalFromSlug,
|
|
754
|
+
parseSymbolAndIntervalFromSlug,
|
|
755
|
+
parseSymbolFromSlug
|
|
693
756
|
});
|
package/markets/utils.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedSymbol, SymbolFullNameMap } from './types.cjs';
|
|
1
|
+
import { SupportedSymbol, SymbolFullNameMap, SupportedInterval } from './types.cjs';
|
|
2
2
|
|
|
3
3
|
declare const SUPPORTED_SYMBOLS: SupportedSymbol[];
|
|
4
4
|
declare const SYMBOL_FULL_NAME_MAP: SymbolFullNameMap;
|
|
@@ -15,4 +15,15 @@ declare function generate1dSlug(timestamp: number, symbol: SupportedSymbol): str
|
|
|
15
15
|
|
|
16
16
|
declare function calculatePeriodStartInET(intervalSeconds: number): number;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
declare function parseSymbolFromSlug(slug: string): SupportedSymbol | null;
|
|
19
|
+
|
|
20
|
+
declare function parseIntervalFromSlug(slug: string): SupportedInterval | null;
|
|
21
|
+
|
|
22
|
+
declare function getIntervalSeconds(interval: SupportedInterval): number;
|
|
23
|
+
|
|
24
|
+
declare function parseSymbolAndIntervalFromSlug(slug: string): {
|
|
25
|
+
symbol: SupportedSymbol | null;
|
|
26
|
+
interval: SupportedInterval | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl, getIntervalSeconds, parseIntervalFromSlug, parseSymbolAndIntervalFromSlug, parseSymbolFromSlug };
|
package/markets/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedSymbol, SymbolFullNameMap } from './types.js';
|
|
1
|
+
import { SupportedSymbol, SymbolFullNameMap, SupportedInterval } from './types.js';
|
|
2
2
|
|
|
3
3
|
declare const SUPPORTED_SYMBOLS: SupportedSymbol[];
|
|
4
4
|
declare const SYMBOL_FULL_NAME_MAP: SymbolFullNameMap;
|
|
@@ -15,4 +15,15 @@ declare function generate1dSlug(timestamp: number, symbol: SupportedSymbol): str
|
|
|
15
15
|
|
|
16
16
|
declare function calculatePeriodStartInET(intervalSeconds: number): number;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
declare function parseSymbolFromSlug(slug: string): SupportedSymbol | null;
|
|
19
|
+
|
|
20
|
+
declare function parseIntervalFromSlug(slug: string): SupportedInterval | null;
|
|
21
|
+
|
|
22
|
+
declare function getIntervalSeconds(interval: SupportedInterval): number;
|
|
23
|
+
|
|
24
|
+
declare function parseSymbolAndIntervalFromSlug(slug: string): {
|
|
25
|
+
symbol: SupportedSymbol | null;
|
|
26
|
+
interval: SupportedInterval | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl, getIntervalSeconds, parseIntervalFromSlug, parseSymbolAndIntervalFromSlug, parseSymbolFromSlug };
|
package/markets/utils.js
CHANGED
|
@@ -633,6 +633,61 @@ function calculatePeriodStartInET(intervalSeconds) {
|
|
|
633
633
|
const periodStartInET = Math.floor(nowInET / intervalSeconds) * intervalSeconds;
|
|
634
634
|
return periodStartInET + offset;
|
|
635
635
|
}
|
|
636
|
+
function parseSymbolFromSlug(slug) {
|
|
637
|
+
const lowerSlug = slug.toLowerCase();
|
|
638
|
+
for (const sym of SUPPORTED_SYMBOLS) {
|
|
639
|
+
const shortForm = sym.toLowerCase();
|
|
640
|
+
if (lowerSlug.startsWith(`${shortForm}-updown-`)) {
|
|
641
|
+
return sym;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
for (const sym of SUPPORTED_SYMBOLS) {
|
|
645
|
+
const fullName = SYMBOL_FULL_NAME_MAP[sym];
|
|
646
|
+
if (fullName && lowerSlug.startsWith(`${fullName}-up-or-down-`)) {
|
|
647
|
+
return sym;
|
|
648
|
+
}
|
|
649
|
+
const shortForm = sym.toLowerCase();
|
|
650
|
+
if (lowerSlug.startsWith(`${shortForm}-up-or-down-`)) {
|
|
651
|
+
return sym;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
function parseIntervalFromSlug(slug) {
|
|
657
|
+
const lowerSlug = slug.toLowerCase();
|
|
658
|
+
if (lowerSlug.includes("-updown-15m-")) {
|
|
659
|
+
return "15m" /* M15 */;
|
|
660
|
+
}
|
|
661
|
+
if (lowerSlug.includes("-updown-4h-")) {
|
|
662
|
+
return "4h" /* H4 */;
|
|
663
|
+
}
|
|
664
|
+
if (lowerSlug.match(/-up-or-down-\w+-\d+-\d+(am|pm)-et$/)) {
|
|
665
|
+
return "1h" /* H1 */;
|
|
666
|
+
}
|
|
667
|
+
if (lowerSlug.match(/-up-or-down-on-\w+-\d+$/)) {
|
|
668
|
+
return "1d" /* D1 */;
|
|
669
|
+
}
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
function getIntervalSeconds(interval) {
|
|
673
|
+
const intervalSecondsMap = {
|
|
674
|
+
["15m" /* M15 */]: 15 * 60,
|
|
675
|
+
// 900秒
|
|
676
|
+
["1h" /* H1 */]: 60 * 60,
|
|
677
|
+
// 3600秒
|
|
678
|
+
["4h" /* H4 */]: 4 * 60 * 60,
|
|
679
|
+
// 14400秒
|
|
680
|
+
["1d" /* D1 */]: 24 * 60 * 60
|
|
681
|
+
// 86400秒
|
|
682
|
+
};
|
|
683
|
+
return intervalSecondsMap[interval];
|
|
684
|
+
}
|
|
685
|
+
function parseSymbolAndIntervalFromSlug(slug) {
|
|
686
|
+
return {
|
|
687
|
+
symbol: parseSymbolFromSlug(slug),
|
|
688
|
+
interval: parseIntervalFromSlug(slug)
|
|
689
|
+
};
|
|
690
|
+
}
|
|
636
691
|
export {
|
|
637
692
|
SUPPORTED_SYMBOLS,
|
|
638
693
|
SYMBOL_FULL_NAME_MAP,
|
|
@@ -641,5 +696,9 @@ export {
|
|
|
641
696
|
generate1dSlug,
|
|
642
697
|
generate1hSlug,
|
|
643
698
|
generate4hSlug,
|
|
644
|
-
generateMarketUrl
|
|
699
|
+
generateMarketUrl,
|
|
700
|
+
getIntervalSeconds,
|
|
701
|
+
parseIntervalFromSlug,
|
|
702
|
+
parseSymbolAndIntervalFromSlug,
|
|
703
|
+
parseSymbolFromSlug
|
|
645
704
|
};
|