index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { SniperEngine } from '../core/index.js';
  2. import { logger, formatUsd } from '../utils/index.js';
  3. import { CONFIG } from '../config/index.js';
  4. import { PositionCache } from '../utils/index.js';
  5. export function showStatus() {
  6. const copiedCache = new PositionCache('.copied-positions.json', CONFIG.DATA_DIR);
  7. const closedCache = new PositionCache('.closed-positions.json', CONFIG.DATA_DIR);
  8. console.log('═══════════════════════════════════════════');
  9. console.log('📊 Byreal Sniper Status');
  10. console.log('═══════════════════════════════════════════\n');
  11. const copied = copiedCache.getAll();
  12. const closed = closedCache.getAll();
  13. console.log(`🎯 Active Copied Positions: ${copied.positions.length}`);
  14. if (copied.positions.length > 0) {
  15. console.log('\nActive Positions:');
  16. copied.positions.forEach((pos, i) => {
  17. const data = copied.data[pos] || {};
  18. console.log(` ${i + 1}. ${pos}`);
  19. console.log(` Pool: ${data.poolAddress || 'N/A'}`);
  20. console.log(` Target Value: ${data.targetUsdValue ? formatUsd(data.targetUsdValue) : 'N/A'}`);
  21. console.log(` Copied At: ${data.copiedAt || 'N/A'}`);
  22. });
  23. }
  24. console.log(`\n🚪 Closed Positions: ${closed.positions.length}`);
  25. if (closed.positions.length > 0) {
  26. console.log('\nClosed Positions:');
  27. closed.positions.forEach((pos, i) => {
  28. const data = closed.data[pos] || {};
  29. console.log(` ${i + 1}. ${pos}`);
  30. console.log(` Reason: ${data.reason || 'N/A'}`);
  31. console.log(` Closed At: ${data.closedAt || 'N/A'}`);
  32. });
  33. }
  34. console.log('\n═══════════════════════════════════════════');
  35. }
  36. export async function startSniper() {
  37. const sniper = new SniperEngine();
  38. // Handle graceful shutdown
  39. process.on('SIGINT', () => {
  40. logger.info('\nShutting down sniper bot...');
  41. sniper.stop();
  42. process.exit(0);
  43. });
  44. process.on('SIGTERM', () => {
  45. logger.info('\nShutting down sniper bot...');
  46. sniper.stop();
  47. process.exit(0);
  48. });
  49. await sniper.start();
  50. }
  51. export function clearCache() {
  52. const copiedCache = new PositionCache('.copied-positions.json', CONFIG.DATA_DIR);
  53. const closedCache = new PositionCache('.closed-positions.json', CONFIG.DATA_DIR);
  54. console.log('Clearing all position caches...');
  55. copiedCache.clear();
  56. closedCache.clear();
  57. console.log('✅ Caches cleared successfully');
  58. }
  59. export default { showStatus, startSniper, clearCache };