crypto_alert_bot/internal/provider/provider.go
2026-04-28 11:42:52 +03:00

69 lines
1.7 KiB
Go

package provider
import (
"context"
"time"
"gitea.computernetthings.ru/yash/crypto_alert_bot/internal/entities"
)
type Provider interface {
// Price returns the current price of the pair (base currency / quote currency).
// e.g. BTC/USDT.
Price(ctx context.Context, instrument entities.Instrument) (*entities.Price, error)
// Candles returns OHLC candles for the given interval in the [from, to) range.
// interval is a provider-specific string (e.g. "1", "5", "60", "D", "W" for Bybit).
// The implementation handles pagination automatically when the range exceeds one
// request's capacity.
Candles(ctx context.Context, instrument entities.Instrument, from, to time.Time, interval KlineInterval) ([]entities.Candle, error)
// InstrumentExists reports whether the trading pair base/quote is listed on this provider.
// Returns (false, nil) when the symbol is simply not found (as opposed to a network error).
InstrumentExists(ctx context.Context, base, quote string) (bool, error)
}
type KlineInterval string
const (
Kline1m = "1"
Kline3m = "3"
Kline5m = "5"
Kline15m = "15"
Kline30m = "30"
Kline1H = "1h"
Kline4H = "4h"
Kline6H = "6h"
Kline12H = "12h"
Kline1D = "1d"
Kline1W = "1w"
)
func (k KlineInterval) ToDuration() time.Duration {
switch k {
case Kline1m:
return time.Minute
case Kline3m:
return 3 * time.Minute
case Kline5m:
return 5 * time.Minute
case Kline15m:
return 15 * time.Minute
case Kline30m:
return 30 * time.Minute
case Kline1H:
return time.Hour
case Kline4H:
return 4 * time.Hour
case Kline6H:
return 6 * time.Hour
case Kline12H:
return 12 * time.Hour
case Kline1D:
return 24 * time.Hour
case Kline1W:
return 7 * 24 * time.Hour
default:
return time.Minute
}
}