alerts

package
v0.0.0-...-6deb405 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlertConnectionError

func AlertConnectionError(ctx context.Context, exchange string, err error)

AlertConnectionError sends an alert for exchange connection issues

func AlertOrderCancelFailed

func AlertOrderCancelFailed(ctx context.Context, orderID, symbol string, err error)

AlertOrderCancelFailed sends an alert for order cancellation failure

func AlertOrderFailed

func AlertOrderFailed(ctx context.Context, symbol, side string, quantity float64, err error)

AlertOrderFailed sends an alert for order placement failure

func AlertPositionRisk

func AlertPositionRisk(ctx context.Context, symbol string, riskLevel float64, reason string)

AlertPositionRisk sends an alert for position risk violations

func AlertSystemError

func AlertSystemError(ctx context.Context, component string, err error)

AlertSystemError sends an alert for critical system errors

func SetDefaultManager

func SetDefaultManager(manager *Manager)

SetDefaultManager sets the default alert manager

Types

type Alert

type Alert struct {
	Title     string
	Message   string
	Severity  Severity
	Timestamp time.Time
	Metadata  map[string]interface{}
}

Alert represents an alert message

type Alerter

type Alerter interface {
	Send(ctx context.Context, alert Alert) error
}

Alerter defines the interface for sending alerts

type ConsoleAlerter

type ConsoleAlerter struct{}

ConsoleAlerter prints alerts to console with prominent formatting using zerolog

func NewConsoleAlerter

func NewConsoleAlerter() *ConsoleAlerter

NewConsoleAlerter creates a new console-based alerter

func (*ConsoleAlerter) Send

func (c *ConsoleAlerter) Send(ctx context.Context, alert Alert) error

Send sends an alert by logging to console with prominent formatting

type EmailAlerter

type EmailAlerter struct {
	// contains filtered or unexported fields
}

EmailAlerter sends alerts via email

func NewEmailAlerter

func NewEmailAlerter(config EmailConfig, recipients []string) (*EmailAlerter, error)

NewEmailAlerter creates a new email-based alerter

func (*EmailAlerter) AddRecipient

func (e *EmailAlerter) AddRecipient(email string)

AddRecipient adds a recipient to the alerter

func (*EmailAlerter) GetRecipients

func (e *EmailAlerter) GetRecipients() []string

GetRecipients returns the list of recipients

func (*EmailAlerter) RemoveRecipient

func (e *EmailAlerter) RemoveRecipient(email string)

RemoveRecipient removes a recipient from the alerter

func (*EmailAlerter) Send

func (e *EmailAlerter) Send(ctx context.Context, alert Alert) error

Send sends an alert via email

func (*EmailAlerter) SetRecipients

func (e *EmailAlerter) SetRecipients(recipients []string)

SetRecipients sets the list of recipients

type EmailConfig

type EmailConfig struct {
	Host         string
	Port         int
	Username     string
	Password     string
	FromAddress  string
	FromName     string
	UseTLS       bool
	UseStartTLS  bool
	SkipVerify   bool
	AuthRequired bool
}

EmailConfig holds email alerter configuration

type LogAlerter

type LogAlerter struct{}

LogAlerter logs alerts using zerolog

func NewLogAlerter

func NewLogAlerter() *LogAlerter

NewLogAlerter creates a new log-based alerter

func (*LogAlerter) Send

func (l *LogAlerter) Send(ctx context.Context, alert Alert) error

Send sends an alert by logging it

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages multiple alert channels

func GetDefaultManager

func GetDefaultManager() *Manager

GetDefaultManager returns the default alert manager

func NewManager

func NewManager(alerters ...Alerter) *Manager

NewManager creates a new alert manager

func (*Manager) Send

func (m *Manager) Send(ctx context.Context, alert Alert) error

Send sends an alert to all configured alerters

func (*Manager) SendCritical

func (m *Manager) SendCritical(ctx context.Context, title, message string, metadata map[string]interface{}) error

SendCritical is a convenience method for sending critical alerts

func (*Manager) SendInfo

func (m *Manager) SendInfo(ctx context.Context, title, message string, metadata map[string]interface{}) error

SendInfo is a convenience method for sending info alerts

func (*Manager) SendWarning

func (m *Manager) SendWarning(ctx context.Context, title, message string, metadata map[string]interface{}) error

SendWarning is a convenience method for sending warning alerts

type Severity

type Severity string

Severity levels for alerts

const (
	SeverityInfo     Severity = "INFO"
	SeverityWarning  Severity = "WARNING"
	SeverityCritical Severity = "CRITICAL"
)

type SlackAlerter

type SlackAlerter struct {
	// contains filtered or unexported fields
}

SlackAlerter sends alerts via Slack webhook

func NewSlackAlerter

func NewSlackAlerter(config SlackConfig) (*SlackAlerter, error)

NewSlackAlerter creates a new Slack-based alerter

func (*SlackAlerter) GetChannel

func (s *SlackAlerter) GetChannel() string

GetChannel returns the default channel

func (*SlackAlerter) Send

func (s *SlackAlerter) Send(ctx context.Context, alert Alert) error

Send sends an alert via Slack webhook

func (*SlackAlerter) SetChannel

func (s *SlackAlerter) SetChannel(channel string)

SetChannel sets the default channel

type SlackConfig

type SlackConfig struct {
	WebhookURL     string
	Channel        string // Optional channel override
	Username       string
	IconEmoji      string
	IconURL        string
	TimeoutSeconds int
}

SlackConfig holds Slack alerter configuration

type TelegramAlerter

type TelegramAlerter struct {
	// contains filtered or unexported fields
}

TelegramAlerter sends alerts via Telegram bot

func NewTelegramAlerter

func NewTelegramAlerter(botToken string, chatIDs []int64) (*TelegramAlerter, error)

NewTelegramAlerter creates a new Telegram-based alerter botToken: Telegram bot API token chatIDs: List of chat IDs to send alerts to

func (*TelegramAlerter) AddChatID

func (t *TelegramAlerter) AddChatID(chatID int64)

AddChatID adds a chat ID to the alerter

func (*TelegramAlerter) GetChatIDs

func (t *TelegramAlerter) GetChatIDs() []int64

GetChatIDs returns the list of configured chat IDs

func (*TelegramAlerter) RemoveChatID

func (t *TelegramAlerter) RemoveChatID(chatID int64)

RemoveChatID removes a chat ID from the alerter

func (*TelegramAlerter) Send

func (t *TelegramAlerter) Send(ctx context.Context, alert Alert) error

Send sends an alert via Telegram

func (*TelegramAlerter) SetChatIDs

func (t *TelegramAlerter) SetChatIDs(chatIDs []int64)

SetChatIDs sets the list of chat IDs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL