80 lines
3.6 KiB
Go
80 lines
3.6 KiB
Go
package config
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ilyakaznacheev/cleanenv"
|
|
)
|
|
|
|
type Config struct {
|
|
App App `yaml:"app"`
|
|
HTTP HTTP `yaml:"http"`
|
|
Binance Binance `yaml:"binance"`
|
|
Coinglass Coinglass `yaml:"coinglass"`
|
|
Postgres Postgres `yaml:"postgres"`
|
|
Collector Collector `yaml:"collector"`
|
|
}
|
|
|
|
type App struct {
|
|
Name string `yaml:"name" env:"APP_NAME" env-default:"crypto-hermes-gateway"`
|
|
Env string `yaml:"env" env:"APP_ENV" env-default:"local"`
|
|
Port int `yaml:"port" env:"APP_PORT" env-default:"8080"`
|
|
}
|
|
|
|
type HTTP struct {
|
|
ReadTimeout time.Duration `yaml:"read_timeout" env-default:"5s"`
|
|
WriteTimeout time.Duration `yaml:"write_timeout" env-default:"10s"`
|
|
IdleTimeout time.Duration `yaml:"idle_timeout" env-default:"60s"`
|
|
}
|
|
|
|
type Binance struct {
|
|
BaseURL string `yaml:"base_url" env:"BINANCE_BASE_URL" env-default:"https://fapi.binance.com"`
|
|
Timeout time.Duration `yaml:"timeout" env-default:"10s"`
|
|
RetryCount int `yaml:"retry_count" env-default:"2"`
|
|
RPS float64 `yaml:"rps" env-default:"20"`
|
|
Burst int `yaml:"burst" env-default:"40"`
|
|
}
|
|
|
|
type Coinglass struct {
|
|
Enabled bool `yaml:"enabled" env:"COINGLASS_ENABLED" env-default:"false"`
|
|
BaseURL string `yaml:"base_url" env:"COINGLASS_BASE_URL" env-default:"https://capi.coinglass.com"`
|
|
TOTPSecret string `yaml:"totp_secret" env:"COINGLASS_TOTP_SECRET"`
|
|
DataAESKey string `yaml:"data_aes_key" env:"COINGLASS_DATA_AES_KEY" env-default:"1f68efd73f8d4921acc0dead41dd39bc"`
|
|
Timeout time.Duration `yaml:"timeout" env:"COINGLASS_TIMEOUT" env-default:"15s"`
|
|
FakeSuccessRetry int `yaml:"fake_success_retry" env:"COINGLASS_FAKE_SUCCESS_RETRY" env-default:"1"`
|
|
FakeSuccessRetryWait time.Duration `yaml:"fake_success_retry_wait" env:"COINGLASS_FAKE_SUCCESS_RETRY_WAIT" env-default:"2s"`
|
|
LiqHeatMapCron string `yaml:"liq_heatmap_cron" env:"COINGLASS_LIQ_HEATMAP_CRON" env-default:"*/5 * * * *"`
|
|
LiqHeatMapInterval string `yaml:"liq_heatmap_interval" env:"COINGLASS_LIQ_HEATMAP_INTERVAL" env-default:"5"`
|
|
LiqHeatMapLimit int `yaml:"liq_heatmap_limit" env:"COINGLASS_LIQ_HEATMAP_LIMIT" env-default:"288"`
|
|
StartupJitterMax time.Duration `yaml:"startup_jitter_max" env:"COINGLASS_STARTUP_JITTER_MAX" env-default:"30s"`
|
|
BackoffInitial time.Duration `yaml:"backoff_initial" env:"COINGLASS_BACKOFF_INITIAL" env-default:"30s"`
|
|
BackoffMax time.Duration `yaml:"backoff_max" env:"COINGLASS_BACKOFF_MAX" env-default:"10m"`
|
|
}
|
|
|
|
type Postgres struct {
|
|
DSN string `yaml:"dsn" env:"POSTGRES_DSN" env-required:"true"`
|
|
MaxConns int32 `yaml:"max_conns" env-default:"10"`
|
|
MinConns int32 `yaml:"min_conns" env-default:"2"`
|
|
}
|
|
|
|
type Collector struct {
|
|
Enabled bool `yaml:"enabled" env-default:"true"`
|
|
Symbols []string `yaml:"symbols" env-default:"BTCUSDT,ETHUSDT,SOLUSDT,BNBUSDT,DOGEUSDT"`
|
|
Intervals []string `yaml:"intervals" env-default:"15m,1h,4h,1d,1w"`
|
|
DefaultLimit int `yaml:"default_limit" env-default:"500"`
|
|
}
|
|
|
|
func Load(path string) (*Config, error) {
|
|
var cfg Config
|
|
if path != "" {
|
|
if err := cleanenv.ReadConfig(path, &cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
if err := cleanenv.ReadEnv(&cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return &cfg, nil
|
|
}
|