feat: 初始化 cryptoHermes 行情网关 v1 MVP + harness 工程文档
Binance USDⓈ-M Futures 行情网关,给上游 Hermes 量化分析引擎提供单一聚合 接口 /v1/market/context(K 线 + funding + OI + 多空比 + taker volume)。 只读公共行情,不下单、不接私钥、不查账户。 ## v1 实现范围(Milestone 1-5) - Clean Architecture 4 层(controller/usecase/repo/entity),接口边界在 internal/usecase/ports.go - Binance Futures REST client(K 线 / ticker24h / funding / OI / 多空比 / taker volume 共 9 个接口),全链路 string 价格避免 float64 精度问题 - TimescaleDB 5 张 hypertable(market_klines / funding_rates / open_interest / long_short_ratio / taker_buy_sell_volume),主键含 时间维度,UpsertMany 幂等 - robfig/cron 定时采集(15m/1h/4h/1d/1w 多周期 K 线 + 衍生品 15 分钟 落库),未收线 K 线 (close_time > now) 由 mapper/repo 双重过滤 - pkg/httpclient 统一限流(默认 20 req/s, burst 40)+ 重试,避免触发 Binance 2400 weight/min IP 上限 - /v1/market/context 聚合接口:errgroup 并发拉 snapshot/funding/OI,DB K 线不足 200 根回源 Binance 异步补 - cmd/backfill CLI 支持指定 from/to 大段回填(Binance 历史 OI / 多空比 官方只保留 30 天,必须自己存) - Docker Compose + Makefile + golang-migrate,本地一键启 技术指标(support/resistance/Vegas/箱体)留待 v2,技术段返回空对象 + warning 占位。 ## Harness 工程文档 - AGENTS.md — AI agent 工作速查(10 个章节) - ai/project-map.md — 仓库结构、扩展点、控制流 - ai/risk-guardrails.md — G1-G10 守卫规则(每条带可机械验证命令) - ai/adr/0001-architecture-foundations.md — 9 条架构基础决策 - ai/task-templates.md — 6 种任务契约模板 - ai/harness-health.md — 当前 harness 健康度评估 3 个 grep 守卫已验证通过:controller / usecase 无具体实现依赖,全项目 无私钥/签名字段。
This commit is contained in:
62
config/config.go
Normal file
62
config/config.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
App App `yaml:"app"`
|
||||
HTTP HTTP `yaml:"http"`
|
||||
Binance Binance `yaml:"binance"`
|
||||
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 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"`
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user