candles based alerts
This commit is contained in:
parent
bec3b7de5b
commit
999f675da9
11 changed files with 316 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ package provider
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.computernetthings.ru/yash/crypto_alert_bot/internal/entities"
|
||||
)
|
||||
|
|
@ -10,4 +11,55 @@ 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)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue