Files
coin/internal/config/config.go
2026-05-10 23:23:38 +08:00

50 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import (
"net"
"git.apinb.com/bsm-sdk/core/conf"
"git.apinb.com/bsm-sdk/core/utils"
)
var (
Spec SrvConfig
)
// SpotWatchItem 现货策略单标的:交易对标识 + 每笔市价买入的报价资产名义USDT开仓与超跌加仓相同
type SpotWatchItem struct {
Symbol string `yaml:"Symbol"` // 如 BTCUSDT
OrderQtyUsdt float64 `yaml:"OrderQtyUsdt"` // 每次开仓/加仓买入的 USDT 名义,须 ≥ 10会按现价换基础币量并按 LOT_SIZE 向下取整
}
type SrvConfig struct {
conf.Base `yaml:",inline"`
ApiPort string `yaml:"ApiPort"`
WebPort string `yaml:"WebPort"`
Databases *conf.DBConf `yaml:"Databases"`
BinanceApiKey string `yaml:"BinanceApiKey"`
BinanceApiSecret string `yaml:"BinanceApiSecret"`
// SpotWatchList 现货轮询标的;为空则跳过现货策略
SpotWatchList []SpotWatchItem `yaml:"SpotWatchList"`
}
func New(srvKey string) {
// 初始化配置 创建一个新的配置实例,用于服务配置
conf.New(srvKey, &Spec)
// 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口
Spec.Port = conf.CheckPort(Spec.Port)
Spec.BindIP = conf.CheckIP(Spec.BindIP)
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
// 配置校验 服务名称地址及监听地址不能为空
conf.NotNil(Spec.Service, Spec.Cache)
// check dirs
if !utils.PathExists("./cache") {
utils.CreateDir("./cache")
}
conf.PrintInfo(Spec.Addr)
}