@polymarbot/shared 0.3.4 → 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/types.cjs +2 -2
- package/markets/types.d.cts +3 -3
- package/markets/types.d.ts +3 -3
- package/markets/types.js +1 -1
- package/markets/utils.cjs +67 -4
- package/markets/utils.d.cts +13 -2
- package/markets/utils.d.ts +13 -2
- package/markets/utils.js +61 -2
- package/package.json +1 -1
- package/trade-strategy/types.d.cts +10 -2
- package/trade-strategy/types.d.ts +10 -2
- package/{chunk-S6EEUHHX.js → chunk-DF467RX7.js} +2 -2
package/markets/types.cjs
CHANGED
|
@@ -25,10 +25,10 @@ __export(types_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(types_exports);
|
|
27
27
|
var SupportedSymbol = /* @__PURE__ */ ((SupportedSymbol2) => {
|
|
28
|
-
SupportedSymbol2["ETH"] = "eth";
|
|
29
28
|
SupportedSymbol2["BTC"] = "btc";
|
|
30
|
-
SupportedSymbol2["
|
|
29
|
+
SupportedSymbol2["ETH"] = "eth";
|
|
31
30
|
SupportedSymbol2["XRP"] = "xrp";
|
|
31
|
+
SupportedSymbol2["SOL"] = "sol";
|
|
32
32
|
return SupportedSymbol2;
|
|
33
33
|
})(SupportedSymbol || {});
|
|
34
34
|
var SupportedInterval = /* @__PURE__ */ ((SupportedInterval2) => {
|
package/markets/types.d.cts
CHANGED
package/markets/types.d.ts
CHANGED
package/markets/types.js
CHANGED
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
|
|
|
@@ -616,10 +620,10 @@ var dayjs_default = import_dayjs.default;
|
|
|
616
620
|
|
|
617
621
|
// src/utils/markets/types.ts
|
|
618
622
|
var SupportedSymbol = /* @__PURE__ */ ((SupportedSymbol2) => {
|
|
619
|
-
SupportedSymbol2["ETH"] = "eth";
|
|
620
623
|
SupportedSymbol2["BTC"] = "btc";
|
|
621
|
-
SupportedSymbol2["
|
|
624
|
+
SupportedSymbol2["ETH"] = "eth";
|
|
622
625
|
SupportedSymbol2["XRP"] = "xrp";
|
|
626
|
+
SupportedSymbol2["SOL"] = "sol";
|
|
623
627
|
return SupportedSymbol2;
|
|
624
628
|
})(SupportedSymbol || {});
|
|
625
629
|
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SupportedSymbol
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-DF467RX7.js";
|
|
4
4
|
import {
|
|
5
5
|
__commonJS,
|
|
6
6
|
__toESM
|
|
@@ -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
|
};
|
package/package.json
CHANGED
|
@@ -80,14 +80,22 @@ interface TokenTradeStepOrder {
|
|
|
80
80
|
size: number;
|
|
81
81
|
status: string;
|
|
82
82
|
updatedAt: number;
|
|
83
|
+
expiresAt?: number;
|
|
83
84
|
keep?: boolean;
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
interface TokenTradeRecordData {
|
|
88
|
+
|
|
89
|
+
positionSize: number;
|
|
90
|
+
|
|
91
|
+
orders: TokenTradeStepOrder[];
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
interface MarketTradeRecord {
|
|
87
95
|
marketId: string;
|
|
88
96
|
strategyJson: string;
|
|
89
97
|
tokens: {
|
|
90
|
-
[tokenId: string]:
|
|
98
|
+
[tokenId: string]: TokenTradeRecordData;
|
|
91
99
|
};
|
|
92
100
|
}
|
|
93
101
|
|
|
@@ -117,4 +125,4 @@ interface MarketTokenData extends MarketToken {
|
|
|
117
125
|
|
|
118
126
|
type MarketTokenContext = Record<string, MarketTokenData>;
|
|
119
127
|
|
|
120
|
-
export { type MarketTokenContext, type MarketTokenData, type MarketTradeContext, type MarketTradeRecord, OrderStatus, type StrategyCallback, type StrategyCondition, type StrategyConfig, type StrategyErrorCallback, type StrategyExecQueue, type StrategyFn, type TokenTradeStepOrder, TradeSide, type TradeStep, type TradeStepBuy, type TradeStepSell };
|
|
128
|
+
export { type MarketTokenContext, type MarketTokenData, type MarketTradeContext, type MarketTradeRecord, OrderStatus, type StrategyCallback, type StrategyCondition, type StrategyConfig, type StrategyErrorCallback, type StrategyExecQueue, type StrategyFn, type TokenTradeRecordData, type TokenTradeStepOrder, TradeSide, type TradeStep, type TradeStepBuy, type TradeStepSell };
|
|
@@ -80,14 +80,22 @@ interface TokenTradeStepOrder {
|
|
|
80
80
|
size: number;
|
|
81
81
|
status: string;
|
|
82
82
|
updatedAt: number;
|
|
83
|
+
expiresAt?: number;
|
|
83
84
|
keep?: boolean;
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
interface TokenTradeRecordData {
|
|
88
|
+
|
|
89
|
+
positionSize: number;
|
|
90
|
+
|
|
91
|
+
orders: TokenTradeStepOrder[];
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
interface MarketTradeRecord {
|
|
87
95
|
marketId: string;
|
|
88
96
|
strategyJson: string;
|
|
89
97
|
tokens: {
|
|
90
|
-
[tokenId: string]:
|
|
98
|
+
[tokenId: string]: TokenTradeRecordData;
|
|
91
99
|
};
|
|
92
100
|
}
|
|
93
101
|
|
|
@@ -117,4 +125,4 @@ interface MarketTokenData extends MarketToken {
|
|
|
117
125
|
|
|
118
126
|
type MarketTokenContext = Record<string, MarketTokenData>;
|
|
119
127
|
|
|
120
|
-
export { type MarketTokenContext, type MarketTokenData, type MarketTradeContext, type MarketTradeRecord, OrderStatus, type StrategyCallback, type StrategyCondition, type StrategyConfig, type StrategyErrorCallback, type StrategyExecQueue, type StrategyFn, type TokenTradeStepOrder, TradeSide, type TradeStep, type TradeStepBuy, type TradeStepSell };
|
|
128
|
+
export { type MarketTokenContext, type MarketTokenData, type MarketTradeContext, type MarketTradeRecord, OrderStatus, type StrategyCallback, type StrategyCondition, type StrategyConfig, type StrategyErrorCallback, type StrategyExecQueue, type StrategyFn, type TokenTradeRecordData, type TokenTradeStepOrder, TradeSide, type TradeStep, type TradeStepBuy, type TradeStepSell };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/utils/markets/types.ts
|
|
2
2
|
var SupportedSymbol = /* @__PURE__ */ ((SupportedSymbol2) => {
|
|
3
|
-
SupportedSymbol2["ETH"] = "eth";
|
|
4
3
|
SupportedSymbol2["BTC"] = "btc";
|
|
5
|
-
SupportedSymbol2["
|
|
4
|
+
SupportedSymbol2["ETH"] = "eth";
|
|
6
5
|
SupportedSymbol2["XRP"] = "xrp";
|
|
6
|
+
SupportedSymbol2["SOL"] = "sol";
|
|
7
7
|
return SupportedSymbol2;
|
|
8
8
|
})(SupportedSymbol || {});
|
|
9
9
|
var SupportedInterval = /* @__PURE__ */ ((SupportedInterval2) => {
|