@polymarbot/shared 0.3.1 → 0.3.3

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.
@@ -0,0 +1,17 @@
1
+ // src/utils/trade-strategy/types.ts
2
+ var TradeSide = /* @__PURE__ */ ((TradeSide2) => {
3
+ TradeSide2["BUY"] = "BUY";
4
+ TradeSide2["SELL"] = "SELL";
5
+ return TradeSide2;
6
+ })(TradeSide || {});
7
+ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
8
+ OrderStatus2["LIVE"] = "LIVE";
9
+ OrderStatus2["MATCHED"] = "MATCHED";
10
+ OrderStatus2["CANCELED"] = "CANCELED";
11
+ return OrderStatus2;
12
+ })(OrderStatus || {});
13
+
14
+ export {
15
+ TradeSide,
16
+ OrderStatus
17
+ };
package/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
2
  ...require('./basic.cjs'),
3
3
  ...require('./crypto.cjs'),
4
- ...require('./markets/tools.cjs'),
4
+ ...require('./loadEnv.cjs'),
5
5
  ...require('./markets/types.cjs'),
6
6
  ...require('./relayer-client.cjs'),
7
7
  ...require('./trade-strategy/normalize.cjs'),
package/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './basic.js'
2
2
  export * from './crypto.js'
3
- export * from './markets/tools.js'
3
+ export * from './loadEnv.js'
4
4
  export * from './markets/types.js'
5
5
  export * from './relayer-client.js'
6
6
  export * from './trade-strategy/normalize.js'
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './basic.js'
2
2
  export * from './crypto.js'
3
- export * from './markets/tools.js'
3
+ export * from './loadEnv.js'
4
4
  export * from './markets/types.js'
5
5
  export * from './relayer-client.js'
6
6
  export * from './trade-strategy/normalize.js'
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './basic.js'
2
2
  export * from './crypto.js'
3
- export * from './markets/tools.js'
3
+ export * from './loadEnv.js'
4
4
  export * from './markets/types.js'
5
5
  export * from './relayer-client.js'
6
6
  export * from './trade-strategy/normalize.js'
package/loadEnv.cjs ADDED
@@ -0,0 +1,47 @@
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/loadEnv.ts
21
+ var loadEnv_exports = {};
22
+ __export(loadEnv_exports, {
23
+ loadEnv: () => loadEnv
24
+ });
25
+ module.exports = __toCommonJS(loadEnv_exports);
26
+ var import_node_fs = require("fs");
27
+ var import_dotenv = require("dotenv");
28
+ function loadEnv(cwd = process.cwd(), extraPaths = []) {
29
+ const envPath = `${cwd}/.env`;
30
+ const envLocalPath = `${cwd}/.env.local`;
31
+ if ((0, import_node_fs.existsSync)(envPath)) {
32
+ (0, import_dotenv.config)({ path: envPath });
33
+ }
34
+ if ((0, import_node_fs.existsSync)(envLocalPath)) {
35
+ (0, import_dotenv.config)({ path: envLocalPath, override: true });
36
+ }
37
+ for (const relativePath of extraPaths) {
38
+ const fullPath = `${cwd}/${relativePath}`;
39
+ if ((0, import_node_fs.existsSync)(fullPath)) {
40
+ (0, import_dotenv.config)({ path: fullPath, override: true });
41
+ }
42
+ }
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ loadEnv
47
+ });
package/loadEnv.d.cts ADDED
@@ -0,0 +1,3 @@
1
+ declare function loadEnv(cwd?: string, extraPaths?: string[]): void;
2
+
3
+ export { loadEnv };
package/loadEnv.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function loadEnv(cwd?: string, extraPaths?: string[]): void;
2
+
3
+ export { loadEnv };
package/loadEnv.js ADDED
@@ -0,0 +1,22 @@
1
+ // src/utils/loadEnv.ts
2
+ import { existsSync } from "fs";
3
+ import { config as dotenvConfig } from "dotenv";
4
+ function loadEnv(cwd = process.cwd(), extraPaths = []) {
5
+ const envPath = `${cwd}/.env`;
6
+ const envLocalPath = `${cwd}/.env.local`;
7
+ if (existsSync(envPath)) {
8
+ dotenvConfig({ path: envPath });
9
+ }
10
+ if (existsSync(envLocalPath)) {
11
+ dotenvConfig({ path: envLocalPath, override: true });
12
+ }
13
+ for (const relativePath of extraPaths) {
14
+ const fullPath = `${cwd}/${relativePath}`;
15
+ if (existsSync(fullPath)) {
16
+ dotenvConfig({ path: fullPath, override: true });
17
+ }
18
+ }
19
+ }
20
+ export {
21
+ loadEnv
22
+ };
package/markets/types.js CHANGED
@@ -1,7 +1,18 @@
1
- import {
2
- SupportedInterval,
3
- SupportedSymbol
4
- } from "../chunk-S6EEUHHX.js";
1
+ // src/utils/markets/types.ts
2
+ var SupportedSymbol = /* @__PURE__ */ ((SupportedSymbol2) => {
3
+ SupportedSymbol2["ETH"] = "eth";
4
+ SupportedSymbol2["BTC"] = "btc";
5
+ SupportedSymbol2["SOL"] = "sol";
6
+ SupportedSymbol2["XRP"] = "xrp";
7
+ return SupportedSymbol2;
8
+ })(SupportedSymbol || {});
9
+ var SupportedInterval = /* @__PURE__ */ ((SupportedInterval2) => {
10
+ SupportedInterval2["M15"] = "15m";
11
+ SupportedInterval2["H1"] = "1h";
12
+ SupportedInterval2["H4"] = "4h";
13
+ SupportedInterval2["D1"] = "1d";
14
+ return SupportedInterval2;
15
+ })(SupportedInterval || {});
5
16
  export {
6
17
  SupportedInterval,
7
18
  SupportedSymbol
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polymarbot/shared",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -36,14 +36,14 @@
36
36
  "default": "./crypto.cjs"
37
37
  }
38
38
  },
39
- "./markets/tools": {
39
+ "./loadEnv": {
40
40
  "import": {
41
- "types": "./markets/tools.d.ts",
42
- "default": "./markets/tools.js"
41
+ "types": "./loadEnv.d.ts",
42
+ "default": "./loadEnv.js"
43
43
  },
44
44
  "require": {
45
- "types": "./markets/tools.d.cts",
46
- "default": "./markets/tools.cjs"
45
+ "types": "./loadEnv.d.cts",
46
+ "default": "./loadEnv.cjs"
47
47
  }
48
48
  },
49
49
  "./markets/types": {
@@ -104,7 +104,7 @@
104
104
  "**/*.d.cts"
105
105
  ],
106
106
  "dependencies": {
107
- "dayjs": "^1.11.19",
107
+ "dotenv": "^17.2.3",
108
108
  "viem": "^2.38.6",
109
109
  "@polymarket/builder-relayer-client": "^0.0.6",
110
110
  "@polymarket/builder-signing-sdk": "^0.0.8"
@@ -1,4 +1,4 @@
1
- import "../chunk-6XBSEJGX.js";
1
+ import "../chunk-BBDXS63M.js";
2
2
 
3
3
  // src/utils/trade-strategy/normalize.ts
4
4
  function normalizeTradeStepBuy(step, options) {
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils/trade-strategy/types.ts
21
21
  var types_exports = {};
22
22
  __export(types_exports, {
23
+ OrderStatus: () => OrderStatus,
23
24
  TradeSide: () => TradeSide
24
25
  });
25
26
  module.exports = __toCommonJS(types_exports);
@@ -28,7 +29,14 @@ var TradeSide = /* @__PURE__ */ ((TradeSide2) => {
28
29
  TradeSide2["SELL"] = "SELL";
29
30
  return TradeSide2;
30
31
  })(TradeSide || {});
32
+ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
33
+ OrderStatus2["LIVE"] = "LIVE";
34
+ OrderStatus2["MATCHED"] = "MATCHED";
35
+ OrderStatus2["CANCELED"] = "CANCELED";
36
+ return OrderStatus2;
37
+ })(OrderStatus || {});
31
38
  // Annotate the CommonJS export names for ESM import in node:
32
39
  0 && (module.exports = {
40
+ OrderStatus,
33
41
  TradeSide
34
42
  });
@@ -30,10 +30,16 @@ interface PriceChangeInfo {
30
30
  }
31
31
 
32
32
  declare enum TradeSide {
33
- BUY = "BUY",
33
+ BUY = "BUY",// 买入
34
34
  SELL = "SELL"
35
35
  }
36
36
 
37
+ declare enum OrderStatus {
38
+ LIVE = "LIVE",// 挂单中
39
+ MATCHED = "MATCHED",// 已成交
40
+ CANCELED = "CANCELED"
41
+ }
42
+
37
43
  interface TradeStepBuy {
38
44
  side: TradeSide.BUY;
39
45
  price: number;
@@ -71,8 +77,10 @@ interface TokenTradeStepOrder {
71
77
  id: string;
72
78
  stepJson: string;
73
79
  side: TradeSide;
80
+ size: number;
74
81
  status: string;
75
82
  updatedAt: number;
83
+ keep?: boolean;
76
84
  }
77
85
 
78
86
  interface MarketTradeRecord {
@@ -109,4 +117,4 @@ interface MarketTokenData extends MarketToken {
109
117
 
110
118
  type MarketTokenContext = Record<string, MarketTokenData>;
111
119
 
112
- export { type MarketTokenContext, type MarketTokenData, type MarketTradeContext, type MarketTradeRecord, type StrategyCallback, type StrategyCondition, type StrategyConfig, type StrategyErrorCallback, type StrategyExecQueue, type StrategyFn, type TokenTradeStepOrder, TradeSide, type TradeStep, type TradeStepBuy, type TradeStepSell };
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 };
@@ -30,10 +30,16 @@ interface PriceChangeInfo {
30
30
  }
31
31
 
32
32
  declare enum TradeSide {
33
- BUY = "BUY",
33
+ BUY = "BUY",// 买入
34
34
  SELL = "SELL"
35
35
  }
36
36
 
37
+ declare enum OrderStatus {
38
+ LIVE = "LIVE",// 挂单中
39
+ MATCHED = "MATCHED",// 已成交
40
+ CANCELED = "CANCELED"
41
+ }
42
+
37
43
  interface TradeStepBuy {
38
44
  side: TradeSide.BUY;
39
45
  price: number;
@@ -71,8 +77,10 @@ interface TokenTradeStepOrder {
71
77
  id: string;
72
78
  stepJson: string;
73
79
  side: TradeSide;
80
+ size: number;
74
81
  status: string;
75
82
  updatedAt: number;
83
+ keep?: boolean;
76
84
  }
77
85
 
78
86
  interface MarketTradeRecord {
@@ -109,4 +117,4 @@ interface MarketTokenData extends MarketToken {
109
117
 
110
118
  type MarketTokenContext = Record<string, MarketTokenData>;
111
119
 
112
- export { type MarketTokenContext, type MarketTokenData, type MarketTradeContext, type MarketTradeRecord, type StrategyCallback, type StrategyCondition, type StrategyConfig, type StrategyErrorCallback, type StrategyExecQueue, type StrategyFn, type TokenTradeStepOrder, TradeSide, type TradeStep, type TradeStepBuy, type TradeStepSell };
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 };
@@ -1,6 +1,8 @@
1
1
  import {
2
+ OrderStatus,
2
3
  TradeSide
3
- } from "../chunk-6XBSEJGX.js";
4
+ } from "../chunk-BBDXS63M.js";
4
5
  export {
6
+ OrderStatus,
5
7
  TradeSide
6
8
  };
package/wallet.cjs CHANGED
@@ -26,6 +26,7 @@ __export(wallet_exports, {
26
26
  formatBalance: () => formatBalance,
27
27
  getPublicClient: () => getPublicClient,
28
28
  getUSDCBalance: () => getUSDCBalance,
29
+ getUSDCBalancesBatch: () => getUSDCBalancesBatch,
29
30
  isAddressEqual: () => isAddressEqual
30
31
  });
31
32
  module.exports = __toCommonJS(wallet_exports);
@@ -59,6 +60,24 @@ async function getUSDCBalance(address) {
59
60
  args: [address]
60
61
  });
61
62
  }
63
+ async function getUSDCBalancesBatch(addresses) {
64
+ if (addresses.length === 0) {
65
+ return [];
66
+ }
67
+ const publicClient = getPublicClient();
68
+ const multicallResults = await publicClient.multicall({
69
+ contracts: addresses.map((address) => ({
70
+ address: USDC_ADDRESS,
71
+ abi: USDC_ABI,
72
+ functionName: "balanceOf",
73
+ args: [address]
74
+ })),
75
+ allowFailure: true
76
+ });
77
+ return multicallResults.map(
78
+ (result) => result.status === "success" ? result.result : 0n
79
+ );
80
+ }
62
81
  function isAddressEqual(a, b) {
63
82
  if (!a) return false;
64
83
  if (!b) return false;
@@ -72,5 +91,6 @@ function isAddressEqual(a, b) {
72
91
  formatBalance,
73
92
  getPublicClient,
74
93
  getUSDCBalance,
94
+ getUSDCBalancesBatch,
75
95
  isAddressEqual
76
96
  });
package/wallet.d.cts CHANGED
@@ -20,6 +20,8 @@ declare function formatBalance(rawBalance: string | bigint, decimals?: number):
20
20
 
21
21
  declare function getUSDCBalance(address: string): Promise<bigint>;
22
22
 
23
+ declare function getUSDCBalancesBatch(addresses: string[]): Promise<bigint[]>;
24
+
23
25
  declare function isAddressEqual(a?: Address | string | null, b?: Address | string | null): boolean;
24
26
 
25
- export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, isAddressEqual };
27
+ export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, getUSDCBalancesBatch, isAddressEqual };
package/wallet.d.ts CHANGED
@@ -20,6 +20,8 @@ declare function formatBalance(rawBalance: string | bigint, decimals?: number):
20
20
 
21
21
  declare function getUSDCBalance(address: string): Promise<bigint>;
22
22
 
23
+ declare function getUSDCBalancesBatch(addresses: string[]): Promise<bigint[]>;
24
+
23
25
  declare function isAddressEqual(a?: Address | string | null, b?: Address | string | null): boolean;
24
26
 
25
- export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, isAddressEqual };
27
+ export { USDC_ABI, USDC_ADDRESS, USDC_DECIMALS, formatBalance, getPublicClient, getUSDCBalance, getUSDCBalancesBatch, isAddressEqual };
package/wallet.js CHANGED
@@ -29,6 +29,24 @@ async function getUSDCBalance(address) {
29
29
  args: [address]
30
30
  });
31
31
  }
32
+ async function getUSDCBalancesBatch(addresses) {
33
+ if (addresses.length === 0) {
34
+ return [];
35
+ }
36
+ const publicClient = getPublicClient();
37
+ const multicallResults = await publicClient.multicall({
38
+ contracts: addresses.map((address) => ({
39
+ address: USDC_ADDRESS,
40
+ abi: USDC_ABI,
41
+ functionName: "balanceOf",
42
+ args: [address]
43
+ })),
44
+ allowFailure: true
45
+ });
46
+ return multicallResults.map(
47
+ (result) => result.status === "success" ? result.result : 0n
48
+ );
49
+ }
32
50
  function isAddressEqual(a, b) {
33
51
  if (!a) return false;
34
52
  if (!b) return false;
@@ -41,5 +59,6 @@ export {
41
59
  formatBalance,
42
60
  getPublicClient,
43
61
  getUSDCBalance,
62
+ getUSDCBalancesBatch,
44
63
  isAddressEqual
45
64
  };
package/chunk-6XBSEJGX.js DELETED
@@ -1,10 +0,0 @@
1
- // src/utils/trade-strategy/types.ts
2
- var TradeSide = /* @__PURE__ */ ((TradeSide2) => {
3
- TradeSide2["BUY"] = "BUY";
4
- TradeSide2["SELL"] = "SELL";
5
- return TradeSide2;
6
- })(TradeSide || {});
7
-
8
- export {
9
- TradeSide
10
- };
package/chunk-S6EEUHHX.js DELETED
@@ -1,20 +0,0 @@
1
- // src/utils/markets/types.ts
2
- var SupportedSymbol = /* @__PURE__ */ ((SupportedSymbol2) => {
3
- SupportedSymbol2["ETH"] = "eth";
4
- SupportedSymbol2["BTC"] = "btc";
5
- SupportedSymbol2["SOL"] = "sol";
6
- SupportedSymbol2["XRP"] = "xrp";
7
- return SupportedSymbol2;
8
- })(SupportedSymbol || {});
9
- var SupportedInterval = /* @__PURE__ */ ((SupportedInterval2) => {
10
- SupportedInterval2["M15"] = "15m";
11
- SupportedInterval2["H1"] = "1h";
12
- SupportedInterval2["H4"] = "4h";
13
- SupportedInterval2["D1"] = "1d";
14
- return SupportedInterval2;
15
- })(SupportedInterval || {});
16
-
17
- export {
18
- SupportedSymbol,
19
- SupportedInterval
20
- };
package/markets/tools.cjs DELETED
@@ -1,130 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/utils/markets/tools.ts
31
- var tools_exports = {};
32
- __export(tools_exports, {
33
- SUPPORTED_SYMBOLS: () => SUPPORTED_SYMBOLS,
34
- SYMBOL_FULL_NAME_MAP: () => SYMBOL_FULL_NAME_MAP,
35
- calculatePeriodStartInET: () => calculatePeriodStartInET,
36
- generate15mSlug: () => generate15mSlug,
37
- generate1dSlug: () => generate1dSlug,
38
- generate1hSlug: () => generate1hSlug,
39
- generate4hSlug: () => generate4hSlug,
40
- generateMarketUrl: () => generateMarketUrl
41
- });
42
- module.exports = __toCommonJS(tools_exports);
43
-
44
- // src/utils/dayjs.ts
45
- var import_dayjs = __toESM(require("dayjs"), 1);
46
- var import_utc = __toESM(require("dayjs/plugin/utc"), 1);
47
- var import_timezone = __toESM(require("dayjs/plugin/timezone"), 1);
48
- var import_duration = __toESM(require("dayjs/plugin/duration"), 1);
49
- import_dayjs.default.extend(import_utc.default);
50
- import_dayjs.default.extend(import_timezone.default);
51
- import_dayjs.default.extend(import_duration.default);
52
- var dayjs_default = import_dayjs.default;
53
-
54
- // src/utils/markets/types.ts
55
- var SupportedSymbol = /* @__PURE__ */ ((SupportedSymbol2) => {
56
- SupportedSymbol2["ETH"] = "eth";
57
- SupportedSymbol2["BTC"] = "btc";
58
- SupportedSymbol2["SOL"] = "sol";
59
- SupportedSymbol2["XRP"] = "xrp";
60
- return SupportedSymbol2;
61
- })(SupportedSymbol || {});
62
-
63
- // src/utils/markets/tools.ts
64
- var SUPPORTED_SYMBOLS = Object.values(SupportedSymbol);
65
- var SYMBOL_FULL_NAME_MAP = {
66
- ["eth" /* ETH */]: "ethereum",
67
- ["btc" /* BTC */]: "bitcoin",
68
- ["sol" /* SOL */]: "solana"
69
- };
70
- var MONTH_NAMES = [
71
- "january",
72
- "february",
73
- "march",
74
- "april",
75
- "may",
76
- "june",
77
- "july",
78
- "august",
79
- "september",
80
- "october",
81
- "november",
82
- "december"
83
- ];
84
- function generateMarketUrl(slug) {
85
- return `https://polymarket.com/event/${slug}`;
86
- }
87
- function generate15mSlug(timestamp, symbol) {
88
- const prefix = symbol.toLowerCase();
89
- return `${prefix}-updown-15m-${timestamp}`;
90
- }
91
- function generate1hSlug(timestamp, symbol) {
92
- const prefix = SYMBOL_FULL_NAME_MAP[symbol] || symbol.toLowerCase();
93
- const etTime = dayjs_default.unix(timestamp).tz("America/New_York");
94
- const month = etTime.format("MMMM").toLowerCase();
95
- const day = etTime.date();
96
- const hour = etTime.format("h");
97
- const ampm = etTime.format("a");
98
- return `${prefix}-up-or-down-${month}-${day}-${hour}${ampm}-et`;
99
- }
100
- function generate4hSlug(timestamp, symbol) {
101
- const prefix = symbol.toLowerCase();
102
- return `${prefix}-updown-4h-${timestamp}`;
103
- }
104
- function generate1dSlug(timestamp, symbol) {
105
- const prefix = SYMBOL_FULL_NAME_MAP[symbol] || symbol.toLowerCase();
106
- const date = new Date(timestamp * 1e3);
107
- const month = MONTH_NAMES[date.getUTCMonth()];
108
- const day = date.getUTCDate();
109
- return `${prefix}-up-or-down-on-${month}-${day}`;
110
- }
111
- function calculatePeriodStartInET(intervalSeconds) {
112
- const now = Math.floor(Date.now() / 1e3);
113
- const utcTime = dayjs_default.unix(now).utc();
114
- const etTime = dayjs_default.unix(now).tz("America/New_York");
115
- const offset = utcTime.utcOffset() * 60 - etTime.utcOffset() * 60;
116
- const nowInET = now - offset;
117
- const periodStartInET = Math.floor(nowInET / intervalSeconds) * intervalSeconds;
118
- return periodStartInET + offset;
119
- }
120
- // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {
122
- SUPPORTED_SYMBOLS,
123
- SYMBOL_FULL_NAME_MAP,
124
- calculatePeriodStartInET,
125
- generate15mSlug,
126
- generate1dSlug,
127
- generate1hSlug,
128
- generate4hSlug,
129
- generateMarketUrl
130
- });
@@ -1,18 +0,0 @@
1
- import { SupportedSymbol, SymbolFullNameMap } from './types.cjs';
2
-
3
- declare const SUPPORTED_SYMBOLS: SupportedSymbol[];
4
- declare const SYMBOL_FULL_NAME_MAP: SymbolFullNameMap;
5
-
6
- declare function generateMarketUrl(slug: string): string;
7
-
8
- declare function generate15mSlug(timestamp: number, symbol: SupportedSymbol): string;
9
-
10
- declare function generate1hSlug(timestamp: number, symbol: SupportedSymbol): string;
11
-
12
- declare function generate4hSlug(timestamp: number, symbol: SupportedSymbol): string;
13
-
14
- declare function generate1dSlug(timestamp: number, symbol: SupportedSymbol): string;
15
-
16
- declare function calculatePeriodStartInET(intervalSeconds: number): number;
17
-
18
- export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl };
@@ -1,18 +0,0 @@
1
- import { SupportedSymbol, SymbolFullNameMap } from './types.js';
2
-
3
- declare const SUPPORTED_SYMBOLS: SupportedSymbol[];
4
- declare const SYMBOL_FULL_NAME_MAP: SymbolFullNameMap;
5
-
6
- declare function generateMarketUrl(slug: string): string;
7
-
8
- declare function generate15mSlug(timestamp: number, symbol: SupportedSymbol): string;
9
-
10
- declare function generate1hSlug(timestamp: number, symbol: SupportedSymbol): string;
11
-
12
- declare function generate4hSlug(timestamp: number, symbol: SupportedSymbol): string;
13
-
14
- declare function generate1dSlug(timestamp: number, symbol: SupportedSymbol): string;
15
-
16
- declare function calculatePeriodStartInET(intervalSeconds: number): number;
17
-
18
- export { SUPPORTED_SYMBOLS, SYMBOL_FULL_NAME_MAP, calculatePeriodStartInET, generate15mSlug, generate1dSlug, generate1hSlug, generate4hSlug, generateMarketUrl };
package/markets/tools.js DELETED
@@ -1,81 +0,0 @@
1
- import {
2
- SupportedSymbol
3
- } from "../chunk-S6EEUHHX.js";
4
-
5
- // src/utils/dayjs.ts
6
- import dayjs from "dayjs";
7
- import utc from "dayjs/plugin/utc";
8
- import timezone from "dayjs/plugin/timezone";
9
- import duration from "dayjs/plugin/duration";
10
- dayjs.extend(utc);
11
- dayjs.extend(timezone);
12
- dayjs.extend(duration);
13
- var dayjs_default = dayjs;
14
-
15
- // src/utils/markets/tools.ts
16
- var SUPPORTED_SYMBOLS = Object.values(SupportedSymbol);
17
- var SYMBOL_FULL_NAME_MAP = {
18
- ["eth" /* ETH */]: "ethereum",
19
- ["btc" /* BTC */]: "bitcoin",
20
- ["sol" /* SOL */]: "solana"
21
- };
22
- var MONTH_NAMES = [
23
- "january",
24
- "february",
25
- "march",
26
- "april",
27
- "may",
28
- "june",
29
- "july",
30
- "august",
31
- "september",
32
- "october",
33
- "november",
34
- "december"
35
- ];
36
- function generateMarketUrl(slug) {
37
- return `https://polymarket.com/event/${slug}`;
38
- }
39
- function generate15mSlug(timestamp, symbol) {
40
- const prefix = symbol.toLowerCase();
41
- return `${prefix}-updown-15m-${timestamp}`;
42
- }
43
- function generate1hSlug(timestamp, symbol) {
44
- const prefix = SYMBOL_FULL_NAME_MAP[symbol] || symbol.toLowerCase();
45
- const etTime = dayjs_default.unix(timestamp).tz("America/New_York");
46
- const month = etTime.format("MMMM").toLowerCase();
47
- const day = etTime.date();
48
- const hour = etTime.format("h");
49
- const ampm = etTime.format("a");
50
- return `${prefix}-up-or-down-${month}-${day}-${hour}${ampm}-et`;
51
- }
52
- function generate4hSlug(timestamp, symbol) {
53
- const prefix = symbol.toLowerCase();
54
- return `${prefix}-updown-4h-${timestamp}`;
55
- }
56
- function generate1dSlug(timestamp, symbol) {
57
- const prefix = SYMBOL_FULL_NAME_MAP[symbol] || symbol.toLowerCase();
58
- const date = new Date(timestamp * 1e3);
59
- const month = MONTH_NAMES[date.getUTCMonth()];
60
- const day = date.getUTCDate();
61
- return `${prefix}-up-or-down-on-${month}-${day}`;
62
- }
63
- function calculatePeriodStartInET(intervalSeconds) {
64
- const now = Math.floor(Date.now() / 1e3);
65
- const utcTime = dayjs_default.unix(now).utc();
66
- const etTime = dayjs_default.unix(now).tz("America/New_York");
67
- const offset = utcTime.utcOffset() * 60 - etTime.utcOffset() * 60;
68
- const nowInET = now - offset;
69
- const periodStartInET = Math.floor(nowInET / intervalSeconds) * intervalSeconds;
70
- return periodStartInET + offset;
71
- }
72
- export {
73
- SUPPORTED_SYMBOLS,
74
- SYMBOL_FULL_NAME_MAP,
75
- calculatePeriodStartInET,
76
- generate15mSlug,
77
- generate1dSlug,
78
- generate1hSlug,
79
- generate4hSlug,
80
- generateMarketUrl
81
- };