Skip to content

M3R1ttt/tracker-notification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tracker-notification

Clean notification system for trading applications with built-in providers for Telegram, Slack, and Discord.

Features

  • 📱 Built-in Providers: Telegram, Slack, Discord support
  • 🎯 Trading Focused: Trade, stop order, and portfolio notifications
  • Async Processing: Concurrent message sending
  • 📝 Markdown Formatting: Clean markdown messages
  • 🔧 Simple API: Easy to use and configure
  • 📦 TypeScript Support: Full TypeScript definitions
  • 🎯 Lightweight: Minimal dependencies, small package size

Installation

npm install tracker-notification

Quick Start

import {
  NotificationManager,
  TelegramNotificationProvider,
  SlackNotificationProvider,
  DiscordNotificationProvider,
  TradeNotificationData
} from 'tracker-notification';

// Create notification manager
const manager = new NotificationManager();

// Add providers
const telegramProvider = new TelegramNotificationProvider({
  botToken: 'your-bot-token',
  chatId: 'your-chat-id',
  parseMode: 'Markdown'
});

const slackProvider = new SlackNotificationProvider({
  botToken: 'your-slack-token',
  channelId: 'your-channel-id'
});

manager.addProvider(telegramProvider);
manager.addProvider(slackProvider);

// Send a trade notification
const tradeData: TradeNotificationData = {
  symbol: 'BTCUSDT',
  side: 'BUY',
  quantity: '0.001',
  price: '45000.00',
  orderId: '12345678',
  status: 'FILLED',
  leverage: 10,
  marginType: 'ISOLATED'
};

await manager.notifyTrade(tradeData); // Sends to all enabled providers

Built-in Providers

Telegram Provider

import { TelegramNotificationProvider } from 'tracker-notification';

const telegramProvider = new TelegramNotificationProvider({
  botToken: '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
  chatId: '123456789',
  parseMode: 'Markdown' // Optional, default: Markdown
});

manager.addProvider(telegramProvider);

Slack Provider

import { SlackNotificationProvider } from 'tracker-notification';

const slackProvider = new SlackNotificationProvider({
  botToken: 'xoxb-your-slack-bot-token',
  channelId: 'C0123456789',
  username: 'Trading Bot' // Optional
});

manager.addProvider(slackProvider);

Message Types

Trade Notifications

const tradeData: TradeNotificationData = {
  symbol: 'BTCUSDT',
  side: 'BUY',
  quantity: '0.001',
  price: '45000.00',
  orderId: '12345678',
  status: 'FILLED',
  leverage: 10,
  marginType: 'ISOLATED'
};

await manager.notifyTrade(tradeData);

Stop Order Notifications

const stopOrderData = {
  type: 'take_profit' as const,
  symbol: 'BTCUSDT',
  price: '46000.00',
  orderId: '87654321'
};

await manager.notifyStopOrder(stopOrderData);

Custom Messages

await manager.notifyCustom('Market analysis completed successfully');
await manager.notifyProvider('telegram', 'This goes only to Telegram');

Message Formatting

All messages are formatted in Markdown for consistency across platforms:

✅ **Trade Executed**

📈 **LONG** BTCUSDT
💰 **Quantity:** 0.001
💵 **Price:** 45000.00
🆔 **Order ID:** 12345678
📊 **Status:** FILLED
🕐 **Time:** 30.10.2025 00:54:32
⚡ **Leverage:** 10x
🔒 Isolated

API Reference

NotificationManager

Methods

  • addProvider(provider: NotificationProvider): void - Add a notification provider
  • removeProvider(providerName: string): boolean - Remove a provider by name
  • notifyTrade(data: TradeNotificationData): Promise<NotificationResult[]> - Send trade notification
  • notifyStopOrder(data: StopOrderData): Promise<NotificationResult[]> - Send stop order notification
  • notifyCustom(message: string): Promise<NotificationResult[]> - Send custom message
  • getProviders(): NotificationProvider[] - Get all registered providers

MessageFormatter

Static Methods

  • formatTradeMessage(data: TradeNotificationData): string - Format trade message
  • formatStopOrderMessage(data: StopOrderData): string - Format stop order message
  • formatCustomMessage(message: string): string - Format custom message
  • formatErrorMessage(error: Error | string): string - Format error message

Error Handling

The system provides robust error handling with detailed results:

const results = await manager.notifyTrade(tradeData);

results.forEach(result => {
  if (result.success) {
    console.log(`✅ ${result.provider}: Message sent`);
  } else {
    console.log(`❌ ${result.provider}: ${result.error}`);
  }
});

License

MIT License - see LICENSE file for details.


Version: 1.0.0 Compatibility: Node.js 14+ TypeScript: Full support included

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published