polycopy 0.0.5 → 0.0.7

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/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const child_process = require("child_process");
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
- const paths = require("./paths-D38j8blX.js");
6
+ const paths = require("./paths-CEeDxAGM.js");
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -174,9 +174,13 @@ function showLogs() {
174
174
  `);
175
175
  console.log(`>>> 日志文件: ${currentLogFile}
176
176
  `);
177
- let tail = child_process.spawn("tail", ["-f", "-n", "100", currentLogFile], {
178
- stdio: "inherit"
179
- });
177
+ let tail = child_process.spawn(
178
+ "tail",
179
+ ["-f", "-n", "100", currentLogFile],
180
+ {
181
+ stdio: "inherit"
182
+ }
183
+ );
180
184
  const watcher = fs__namespace.watch(paths.LOGS_DIR, (eventType, filename) => {
181
185
  if (eventType === "rename" && filename?.endsWith(".log")) {
182
186
  const newLogFile = getLatestLogFile();
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const init = require("./init-Bm-Q_fD_.js");
2
+ const init = require("./init-D8USSmrw.js");
3
3
  async function main() {
4
4
  try {
5
5
  await init.runConfigWizard();
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const init = require("./init-Bm-Q_fD_.js");
2
+ const init = require("./init-D8USSmrw.js");
3
3
  const grammy = require("grammy");
4
4
  const wallet = require("@ethersproject/wallet");
5
5
  const clobClient = require("@polymarket/clob-client");
@@ -11,7 +11,7 @@ const builderRelayerClient = require("@polymarket/builder-relayer-client");
11
11
  const setPromiseInterval = require("set-promise-interval");
12
12
  const child_process = require("child_process");
13
13
  const fs = require("fs");
14
- const paths = require("./paths-D38j8blX.js");
14
+ const paths = require("./paths-CEeDxAGM.js");
15
15
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
16
16
  function _interopNamespace(e) {
17
17
  if (e && e.__esModule) return e;
@@ -490,7 +490,9 @@ class OrderWatcher {
490
490
  async watch(orderId, endTime, getOrderFn) {
491
491
  const timeoutAt = endTime + TIMEOUT_BUFFER;
492
492
  const shortId = orderId.substring(0, 10) + "...";
493
- init.logger.info(`开始监控订单 ${shortId},超时: ${new Date(timeoutAt).toLocaleString()}`);
493
+ init.logger.info(
494
+ `开始监控订单 ${shortId},超时: ${new Date(timeoutAt).toLocaleString()}`
495
+ );
494
496
  while (true) {
495
497
  const now = Date.now();
496
498
  if (now >= timeoutAt) {
@@ -607,7 +609,9 @@ class Redeemer {
607
609
  url.searchParams.set("limit", "10");
608
610
  const response = await fetch(url.toString());
609
611
  if (!response.ok) {
610
- throw new Error(`获取仓位失败: ${response.status} ${response.statusText}`);
612
+ throw new Error(
613
+ `获取仓位失败: ${response.status} ${response.statusText}`
614
+ );
611
615
  }
612
616
  const data = await response.json();
613
617
  const positions = [];
@@ -688,7 +692,9 @@ conditionId: ${position.conditionId}
688
692
  this.pauseAndRestart((resetSeconds + 60) * 1e3);
689
693
  return;
690
694
  }
691
- init.logger.error(`Redeem 异常 (第 ${record.failedCount} 次): ${errorMsg}`);
695
+ init.logger.error(
696
+ `Redeem 异常 (第 ${record.failedCount} 次): ${errorMsg}`
697
+ );
692
698
  if (record.failedCount >= MAX_MATCH_TIMES) {
693
699
  notifier.error(
694
700
  "Redeem 异常",
@@ -769,7 +775,7 @@ class Trader {
769
775
  builderCreds: config.polymarket.builderCreds
770
776
  });
771
777
  } else {
772
- init.logger.warning("未配置 builderCredsRedeem 功能已禁用");
778
+ init.logger.warning("未配置 builderCreds,自动 Redeem 功能已禁用");
773
779
  }
774
780
  this.initialized = true;
775
781
  init.logger.success("交易模块初始化完成");
@@ -827,8 +833,11 @@ class Trader {
827
833
  if (amountMode === "fixed" && balance < amountValue) {
828
834
  const msg = `余额不足: ${balance} USDC < ${amountValue} USDC`;
829
835
  init.logger.warning(msg);
830
- notifier.warning("余额不足", `当前余额: ${balance} USDC
831
- 需要金额: ${amountValue} USDC`);
836
+ notifier.warning(
837
+ "余额不足",
838
+ `当前余额: ${balance} USDC
839
+ 需要金额: ${amountValue} USDC`
840
+ );
832
841
  return;
833
842
  }
834
843
  if (amountMode === "percentage" && balance <= 0) {
@@ -844,8 +853,11 @@ class Trader {
844
853
  const buyResult = await this.client.createBuyOrder(assetId, buyPrice, size);
845
854
  if (!buyResult.success) {
846
855
  init.logger.error(`买单失败: ${buyResult.errorMsg}`);
847
- notifier.error("买单失败", `事件: ${metadata.eventId}
848
- 错误: ${buyResult.errorMsg}`);
856
+ notifier.error(
857
+ "买单失败",
858
+ `事件: ${metadata.eventId}
859
+ 错误: ${buyResult.errorMsg}`
860
+ );
849
861
  return;
850
862
  }
851
863
  this.assetFilter.markTraded(assetId, endTime);
@@ -854,7 +866,13 @@ class Trader {
854
866
  init.logger.line("", "sellPrice = 1,成交后将自动 redeem");
855
867
  return;
856
868
  }
857
- this.watchAndHandle(buyResult.orderId, assetId, sellPrice, endTime, metadata.eventId);
869
+ this.watchAndHandle(
870
+ buyResult.orderId,
871
+ assetId,
872
+ sellPrice,
873
+ endTime,
874
+ metadata.eventId
875
+ );
858
876
  }
859
877
  /**
860
878
  * 异步监控订单并处理结果(不阻塞主流程)
@@ -866,13 +884,22 @@ class Trader {
866
884
  endTime,
867
885
  (id) => this.client.getOrder(id)
868
886
  );
869
- await this.handleBuyResult(watchResult, orderId, assetId, sellPrice, endTime);
887
+ await this.handleBuyResult(
888
+ watchResult,
889
+ orderId,
890
+ assetId,
891
+ sellPrice,
892
+ endTime
893
+ );
870
894
  } catch (error) {
871
895
  const errorMsg = error instanceof Error ? error.message : String(error);
872
896
  init.logger.error(`订单监控异常: ${errorMsg}`);
873
- notifier.error("订单监控异常", `事件: ${eventId}
897
+ notifier.error(
898
+ "订单监控异常",
899
+ `事件: ${eventId}
874
900
  订单: ${orderId}
875
- 错误: ${errorMsg}`);
901
+ 错误: ${errorMsg}`
902
+ );
876
903
  }
877
904
  }
878
905
  /**
@@ -922,7 +949,9 @@ class Trader {
922
949
  try {
923
950
  const positionSize = await this.client.getPositionSize(assetId);
924
951
  if (positionSize >= threshold) {
925
- init.logger.info(`仓位已同步: ${shortId},数量: ${positionSize.toFixed(4)}`);
952
+ init.logger.info(
953
+ `仓位已同步: ${shortId},数量: ${positionSize.toFixed(4)}`
954
+ );
926
955
  await this.executeSellOrder(assetId, sellPrice, positionSize);
927
956
  return;
928
957
  }
@@ -1027,8 +1056,13 @@ async function main() {
1027
1056
  try {
1028
1057
  await trader.init(config);
1029
1058
  if (config.trading?.sellPrice === 1 && !config.polymarket?.builderCreds) {
1030
- init.logger.warning("sellPrice = 1 但未配置 builderCreds,持仓将无法自动结算");
1031
- init.logger.line("", "请配置 Builder API 凭证,或手动 claim");
1059
+ init.logger.warning(
1060
+ "sellPrice = 1 但未配置 builderCreds,Redeem 功能将无法使用"
1061
+ );
1062
+ init.logger.line(
1063
+ "",
1064
+ "请配置 Builder API 凭证,或将卖价设置为 < 1 使用限价卖出模式"
1065
+ );
1032
1066
  }
1033
1067
  } catch (error) {
1034
1068
  const errorMsg = error instanceof Error ? error.message : String(error);
@@ -1053,9 +1087,15 @@ async function main() {
1053
1087
  listener.onSignal(async (signal) => {
1054
1088
  init.logger.info(`📨 收到预测信号:`);
1055
1089
  init.logger.line("", `事件: ${signal.metadata.eventId}`);
1056
- init.logger.line("", `方向: ${signal.metadata.outcome === "Up" ? "上涨 📈" : "下跌 📉"}`);
1090
+ init.logger.line(
1091
+ "",
1092
+ `方向: ${signal.metadata.outcome === "Up" ? "上涨 📈" : "下跌 📉"}`
1093
+ );
1057
1094
  init.logger.line("", `Asset: ${signal.metadata.assetId}`);
1058
- init.logger.line("", `结束时间: ${new Date(signal.metadata.endTime).toLocaleString()}`);
1095
+ init.logger.line(
1096
+ "",
1097
+ `结束时间: ${new Date(signal.metadata.endTime).toLocaleString()}`
1098
+ );
1059
1099
  if (trader.isInitialized()) {
1060
1100
  try {
1061
1101
  await trader.executeSignal(signal);
@@ -1076,10 +1116,7 @@ async function main() {
1076
1116
  setTimeout(() => {
1077
1117
  process.exit(0);
1078
1118
  }, 1e3);
1079
- Promise.all([
1080
- trader.shutdown(),
1081
- listener.stop()
1082
- ]).finally(() => {
1119
+ Promise.all([trader.shutdown(), listener.stop()]).finally(() => {
1083
1120
  process.exit(0);
1084
1121
  });
1085
1122
  };
@@ -2,7 +2,7 @@
2
2
  const readline = require("readline");
3
3
  const fsExtra = require("fs-extra");
4
4
  const path = require("path");
5
- const paths = require("./paths-D38j8blX.js");
5
+ const paths = require("./paths-CEeDxAGM.js");
6
6
  const grammy = require("grammy");
7
7
  const winston = require("winston");
8
8
  const DailyRotateFile = require("winston-daily-rotate-file");
@@ -331,7 +331,10 @@ class TelegramListener {
331
331
  }
332
332
  logger.info(`📢 频道状态更新: ${chatTitle}`);
333
333
  logger.line("", action);
334
- logger.line("", `当前状态: ${canListen ? "✅ 可监听预测消息" : "❌ 无法监听预测消息"}`);
334
+ logger.line(
335
+ "",
336
+ `当前状态: ${canListen ? "✅ 可监听预测消息" : "❌ 无法监听预测消息"}`
337
+ );
335
338
  if (reason) {
336
339
  logger.line("", `原因: ${reason}`);
337
340
  }
@@ -409,7 +412,10 @@ class TelegramListener {
409
412
  const jsonEnd = Math.min(jsonStart + 200, messageText.length);
410
413
  logger.warning(`解析预测消息失败:`);
411
414
  logger.line("", `频道 ID: ${chatId}`);
412
- logger.line("", `消息片段: ${messageText.substring(emojiIndex, jsonEnd)}${messageText.length > jsonEnd ? "..." : ""}`);
415
+ logger.line(
416
+ "",
417
+ `消息片段: ${messageText.substring(emojiIndex, jsonEnd)}${messageText.length > jsonEnd ? "..." : ""}`
418
+ );
413
419
  logger.line("", "提示: 请检查消息格式是否正确");
414
420
  }
415
421
  return;
@@ -483,7 +489,10 @@ class TelegramListener {
483
489
  const chatIds = Array.from(this.targetChatIds);
484
490
  if (chatIds.length === 0) {
485
491
  logger.info(`📋 当前没有保存的频道配置`);
486
- logger.line("", "提示: 当 Bot 被添加为频道管理员时,会自动添加到监听列表");
492
+ logger.line(
493
+ "",
494
+ "提示: 当 Bot 被添加为频道管理员时,会自动添加到监听列表"
495
+ );
487
496
  return;
488
497
  }
489
498
  logger.info(`📋 检查 Bot 所在的频道:`);
@@ -520,7 +529,10 @@ class TelegramListener {
520
529
  if (adminChannels.length > 0) {
521
530
  logger.info(`📡 可监听频道 (${adminChannels.length} 个):`);
522
531
  adminChannels.forEach((channel, index) => {
523
- logger.item(`${index + 1}. ${channel.title} (ID: ${channel.id}) 👑 管理员`, 1);
532
+ logger.item(
533
+ `${index + 1}. ${channel.title} (ID: ${channel.id}) 👑 管理员`,
534
+ 1
535
+ );
524
536
  });
525
537
  }
526
538
  if (nonAdminChannels.length > 0) {
@@ -609,7 +621,9 @@ async function runConfigWizard(existingConfig) {
609
621
  const currentToken = currentTelegram?.botToken || "";
610
622
  const currentDisplay = currentToken ? `${currentToken.substring(0, 10)}...` : "未配置";
611
623
  const hint = currentToken ? "回车保持,或输入新值" : "必填";
612
- const input = await question(` - Bot Token [${currentDisplay}] (${hint}): `);
624
+ const input = await question(
625
+ ` - Bot Token [${currentDisplay}] (${hint}): `
626
+ );
613
627
  botToken = input.trim();
614
628
  if (!botToken && currentToken) {
615
629
  botToken = currentToken;
@@ -649,14 +663,18 @@ async function runConfigWizard(existingConfig) {
649
663
  const currentPrivateKey = currentPolymarket?.privateKey || "";
650
664
  const pkDisplay = currentPrivateKey ? "已配置" : "未配置";
651
665
  const pkHint = currentPrivateKey ? "回车保持,skip 清除" : "回车跳过";
652
- const privateKeyInput = await question(` - 钱包私钥 [${pkDisplay}] (${pkHint}): `);
666
+ const privateKeyInput = await question(
667
+ ` - 钱包私钥 [${pkDisplay}] (${pkHint}): `
668
+ );
653
669
  const privateKeyTrimmed = privateKeyInput.trim().toLowerCase() === "skip" ? "" : privateKeyInput.trim() || currentPrivateKey;
654
670
  let funderAddress = currentPolymarket?.funderAddress;
655
671
  let builderCreds = currentPolymarket?.builderCreds;
656
672
  if (privateKeyTrimmed) {
657
673
  const funderDisplay = funderAddress || "未配置";
658
674
  const funderHint = funderAddress ? "回车保持,skip 清除" : "回车跳过";
659
- const funderInput = await question(` - Polymarket 账户地址 [${funderDisplay}] (${funderHint}): `);
675
+ const funderInput = await question(
676
+ ` - Polymarket 账户地址 [${funderDisplay}] (${funderHint}): `
677
+ );
660
678
  if (funderInput.trim().toLowerCase() === "skip") {
661
679
  funderAddress = void 0;
662
680
  } else if (funderInput.trim()) {
@@ -672,11 +690,17 @@ async function runConfigWizard(existingConfig) {
672
690
  const shouldConfigBuilder = needBuilderCredsLower === "y" || !needBuilderCredsLower && hasBuilderCreds;
673
691
  if (shouldConfigBuilder) {
674
692
  const keyDisplay = builderCreds?.key ? `${builderCreds.key.substring(0, 10)}...` : "未配置";
675
- const builderKey = await question(` - API Key [${keyDisplay}] (回车保持): `);
693
+ const builderKey = await question(
694
+ ` - API Key [${keyDisplay}] (回车保持): `
695
+ );
676
696
  const secretDisplay = builderCreds?.secret ? "已配置" : "未配置";
677
- const builderSecret = await question(` - API Secret [${secretDisplay}] (回车保持): `);
697
+ const builderSecret = await question(
698
+ ` - API Secret [${secretDisplay}] (回车保持): `
699
+ );
678
700
  const passDisplay = builderCreds?.passphrase ? "已配置" : "未配置";
679
- const builderPassphrase = await question(` - API Passphrase [${passDisplay}] (回车保持): `);
701
+ const builderPassphrase = await question(
702
+ ` - API Passphrase [${passDisplay}] (回车保持): `
703
+ );
680
704
  if (!builderKey.trim() && !builderSecret.trim() && !builderPassphrase.trim()) {
681
705
  builderCreds = currentPolymarket?.builderCreds;
682
706
  } else {
@@ -718,16 +742,25 @@ async function runConfigWizard(existingConfig) {
718
742
  trading: tradingConfig
719
743
  };
720
744
  if (tradingConfig.sellPrice === 1 && !builderCreds) {
721
- logger.warning("sellPrice = 1 但未配置 builderCreds,Redeem 功能将无法使用");
722
- logger.line("", "请配置 Builder API 凭证,或将卖价设置为 < 1 使用限价卖出模式");
745
+ logger.warning(
746
+ "sellPrice = 1 但未配置 builderCreds,Redeem 功能将无法使用"
747
+ );
748
+ logger.line(
749
+ "",
750
+ "请配置 Builder API 凭证,或将卖价设置为 < 1 使用限价卖出模式"
751
+ );
723
752
  }
724
753
  configLocal.setItem("telegram", config.telegram);
725
754
  configLocal.setItem("polymarket", config.polymarket);
726
755
  const cleanTradingConfig = {};
727
- if (config.trading.amountMode !== void 0) cleanTradingConfig.amountMode = config.trading.amountMode;
728
- if (config.trading.amountValue !== void 0) cleanTradingConfig.amountValue = config.trading.amountValue;
729
- if (config.trading.buyPrice !== void 0) cleanTradingConfig.buyPrice = config.trading.buyPrice;
730
- if (config.trading.sellPrice !== void 0) cleanTradingConfig.sellPrice = config.trading.sellPrice;
756
+ if (config.trading.amountMode !== void 0)
757
+ cleanTradingConfig.amountMode = config.trading.amountMode;
758
+ if (config.trading.amountValue !== void 0)
759
+ cleanTradingConfig.amountValue = config.trading.amountValue;
760
+ if (config.trading.buyPrice !== void 0)
761
+ cleanTradingConfig.buyPrice = config.trading.buyPrice;
762
+ if (config.trading.sellPrice !== void 0)
763
+ cleanTradingConfig.sellPrice = config.trading.sellPrice;
731
764
  configLocal.setItem("trading", cleanTradingConfig);
732
765
  logger.success("配置已保存!");
733
766
  if (privateKeyTrimmed) {
@@ -848,8 +881,10 @@ async function configureTrading(existingConfig) {
848
881
  }
849
882
  const price = parseFloat(sellPriceInput.trim());
850
883
  if (isNaN(price) || buyPrice !== void 0 && price <= buyPrice || price > 1) {
851
- console.log(`卖价必须大于 ${buyPrice ?? 0.98} 且小于等于 1,或输入 'skip' 跳过
852
- `);
884
+ console.log(
885
+ `卖价必须大于 ${buyPrice ?? 0.98} 且小于等于 1,或输入 'skip' 跳过
886
+ `
887
+ );
853
888
  continue;
854
889
  }
855
890
  sellPrice = price;
@@ -865,7 +900,10 @@ async function configureTrading(existingConfig) {
865
900
  if (tradingConfig.sellPrice === 1) {
866
901
  logger.line("ℹ️", "卖价设置为 1,将使用自动 redeem 模式");
867
902
  } else if (tradingConfig.sellPrice !== void 0) {
868
- logger.line("ℹ️", `卖价设置为 ${tradingConfig.sellPrice},将使用限价卖出模式`);
903
+ logger.line(
904
+ "ℹ️",
905
+ `卖价设置为 ${tradingConfig.sellPrice},将使用限价卖出模式`
906
+ );
869
907
  }
870
908
  const hasAllConfig = tradingConfig.amountMode && tradingConfig.amountValue !== void 0 && tradingConfig.buyPrice !== void 0 && tradingConfig.sellPrice !== void 0;
871
909
  if (!hasAllConfig) {
@@ -915,10 +953,14 @@ async function ensureConfig() {
915
953
  ...tradingConfig
916
954
  };
917
955
  const cleanTradingConfig = {};
918
- if (config.trading.amountMode !== void 0) cleanTradingConfig.amountMode = config.trading.amountMode;
919
- if (config.trading.amountValue !== void 0) cleanTradingConfig.amountValue = config.trading.amountValue;
920
- if (config.trading.buyPrice !== void 0) cleanTradingConfig.buyPrice = config.trading.buyPrice;
921
- if (config.trading.sellPrice !== void 0) cleanTradingConfig.sellPrice = config.trading.sellPrice;
956
+ if (config.trading.amountMode !== void 0)
957
+ cleanTradingConfig.amountMode = config.trading.amountMode;
958
+ if (config.trading.amountValue !== void 0)
959
+ cleanTradingConfig.amountValue = config.trading.amountValue;
960
+ if (config.trading.buyPrice !== void 0)
961
+ cleanTradingConfig.buyPrice = config.trading.buyPrice;
962
+ if (config.trading.sellPrice !== void 0)
963
+ cleanTradingConfig.sellPrice = config.trading.sellPrice;
922
964
  configLocal.setItem("trading", cleanTradingConfig);
923
965
  }
924
966
  }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ const os = require("os");
3
+ const path = require("path");
4
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
5
+ const os__default = /* @__PURE__ */ _interopDefault(os);
6
+ const path__default = /* @__PURE__ */ _interopDefault(path);
7
+ const USER_DATA_DIR = path__default.default.join(os__default.default.homedir(), ".polycopy");
8
+ const PID_DIR = USER_DATA_DIR;
9
+ const LOGS_DIR = path__default.default.join(USER_DATA_DIR, "logs");
10
+ const LOCALSTORAGE_DIR = path__default.default.join(USER_DATA_DIR, "localstorage");
11
+ const PID_FILE = path__default.default.join(USER_DATA_DIR, "polycopy.pid");
12
+ exports.LOCALSTORAGE_DIR = LOCALSTORAGE_DIR;
13
+ exports.LOGS_DIR = LOGS_DIR;
14
+ exports.PID_DIR = PID_DIR;
15
+ exports.PID_FILE = PID_FILE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polycopy",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "polycopy test",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -1,13 +0,0 @@
1
- "use strict";
2
- const path = require("path");
3
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
4
- const path__default = /* @__PURE__ */ _interopDefault(path);
5
- const PROJECT_ROOT = path__default.default.join(__dirname, "..");
6
- const LOGS_DIR = path__default.default.join(PROJECT_ROOT, "logs");
7
- const LOCALSTORAGE_DIR = path__default.default.join(PROJECT_ROOT, "localstorage");
8
- const PID_DIR = path__default.default.join(process.env.HOME || PROJECT_ROOT, ".polycopy");
9
- const PID_FILE = path__default.default.join(PID_DIR, "polycopy.pid");
10
- exports.LOCALSTORAGE_DIR = LOCALSTORAGE_DIR;
11
- exports.LOGS_DIR = LOGS_DIR;
12
- exports.PID_DIR = PID_DIR;
13
- exports.PID_FILE = PID_FILE;