Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package config owns the on-disk TOML configuration and its defaults.

Index

Constants

This section is empty.

Variables

View Source
var DefaultAliases = map[string][]string{
	"\u9f99\u867eUSDT":                   {"longxia", "lx", "lobster"},
	"\u725b\u6765USDT":                   {"niulai", "nl", "niu", "bull"},
	"\u6211\u8e0f\u9a6c\u6765\u4e86USDT": {"wotamalaile", "wtmll", "tama"},
	"\u5e01\u5b89\u4eba\u751fUSDT":       {"bianrensheng", "brs", "rensheng"},
}

DefaultAliases maps a symbol to short handles that are typeable on a US keyboard. Chinese contract names are otherwise painful to enter in a TUI.

View Source
var DefaultWatch = []string{"\u9f99\u867eUSDT", "\u725b\u6765USDT", "\u6211\u8e0f\u9a6c\u6765\u4e86USDT", "\u5e01\u5b89\u4eba\u751fUSDT", "BTCUSDT", "ETHUSDT"}

DefaultWatch is the starting watchlist. The four Chinese-named perps are the reason this tool exists, so they lead.

Functions

func BnwatchPath

func BnwatchPath() string

BnwatchPath is the config file written by the original Python prototype.

func CachePath

func CachePath(name string) string

CachePath returns a file inside the cache subdirectory.

func DBPath

func DBPath() string

DBPath is the history database location.

func Dir

func Dir() string

Dir is the per-user configuration directory. On Windows adrg/xdg resolves to %AppData%; elsewhere it honours XDG_CONFIG_HOME and falls back to ~/.config.

func Path

func Path() string

Path is the config file location.

func PromptDir added in v0.2.0

func PromptDir() string

PromptDir is where user-supplied analysis presets live. Dropping a markdown file here is all it takes to add one; nothing has to be registered.

func StatePath

func StatePath(name string) string

StatePath returns a runtime state file such as the daemon pidfile.

Types

type Alerts

type Alerts struct {
	Levels      []Level `toml:"levels"`
	Auto        Auto    `toml:"auto"`
	MuteMinutes int     `toml:"mute_minutes"`
}

type Auto

type Auto struct {
	Px15    float64 `toml:"px15"`
	OI15    float64 `toml:"oi15"`
	Taker   float64 `toml:"taker"`
	Liq     float64 `toml:"liq"`
	Stop    float64 `toml:"stop"`
	Funding float64 `toml:"funding"`
}

Auto holds thresholds for the always-on derived alerts. Zero disables a rule.

type Bark

type Bark struct {
	Enabled bool   `toml:"enabled"`
	URL     string `toml:"url"`
}

type Config

type Config struct {
	General  General  `toml:"general"`
	Proxy    Proxy    `toml:"proxy"`
	Endpoint Endpoint `toml:"endpoint"`
	Watch    Watch    `toml:"watch"`
	Position Position `toml:"position"`
	Alerts   Alerts   `toml:"alerts"`
	Notify   Notify   `toml:"notify"`
	History  History  `toml:"history"`
	LLM      LLM      `toml:"llm"`
	// contains filtered or unexported fields
}

func Default

func Default() *Config

Default returns a fully populated config with no file behind it.

func Load

func Load() (*Config, error)

Load reads the config file, filling anything missing from Default. A missing file is not an error: first run should just work.

func LoadFrom

func LoadFrom(path string) (*Config, error)

LoadFrom reads a specific file.

func (*Config) AddWatch

func (c *Config) AddWatch(symbol string) bool

AddWatch appends a symbol if absent, reporting whether it changed.

func (*Config) FilePath

func (c *Config) FilePath() string

FilePath reports the backing file.

func (*Config) Get

func (c *Config) Get(key string) (string, error)

Get resolves a dotted key such as "proxy.url" or "alerts.auto.px15" and renders it as text. Composite leaves (lists, maps) render as JSON so the output stays machine readable.

func (*Config) HasPosition

func (c *Config) HasPosition() bool

HasPosition reports whether a usable manual position is recorded.

func (*Config) ImportBnwatch

func (c *Config) ImportBnwatch(path string) ([]string, error)

ImportBnwatch merges an existing bnwatch.json into the config, returning a short human summary of what moved across.

func (*Config) Keys

func (c *Config) Keys() []string

Keys lists every settable dotted key, for help output and shell completion.

func (*Config) PositionFor

func (c *Config) PositionFor(symbol string) (Position, bool)

PositionFor returns the recorded position only when it belongs to symbol. A position on one contract must not be applied to another after switching.

func (*Config) RemoveWatch

func (c *Config) RemoveWatch(symbol string) bool

RemoveWatch drops a symbol, reporting whether it changed.

func (*Config) Save

func (c *Config) Save() error

Save writes the config atomically with 0600 permissions, since it can hold push notification tokens.

func (*Config) Set

func (c *Config) Set(key, value string) error

Set parses value according to the target field's type. Lists accept either a comma separated string or a JSON array.

func (*Config) SetPath

func (c *Config) SetPath(p string)

SetPath overrides where Save writes.

type Endpoint

type Endpoint struct {
	// The json tags keep `niu endpoint show --json` in the same snake_case shape
	// as every other JSON output.
	REST string `toml:"rest" json:"rest"`
	WS   string `toml:"ws" json:"ws"`
}

Endpoint overrides the Binance origin entirely. Empty means "use the built-in mirror list plus proxy detection". Non-empty means the user runs their own reverse proxy; niu then skips mirror ranking.

type General

type General struct {
	Symbol   string  `toml:"symbol"`
	Interval float64 `toml:"interval"`
	Lang     string  `toml:"lang"`
	// Market is um, cm or spot. Empty is read as um.
	Market  string `toml:"market"`
	ASCII   bool   `toml:"ascii"`
	NoColor bool   `toml:"no_color"`
	// NoWS forces REST polling only. Some proxies complete the WebSocket
	// handshake and then forward nothing, and polling is the reliable fallback.
	NoWS bool `toml:"no_ws"`
	// GuideSeen records that the walkthrough has been shown once. The G key and
	// "niu guide" reopen it at any time.
	GuideSeen bool `toml:"guide_seen"`
}

type History

type History struct {
	Enabled       bool `toml:"enabled"`
	IntervalSec   int  `toml:"interval_sec"`
	RetentionDays int  `toml:"retention_days"`
}

type Hook

type Hook struct {
	Enabled bool   `toml:"enabled"`
	URL     string `toml:"url"`
}

type LLM added in v0.2.0

type LLM struct {
	// Provider is "openai" for any OpenAI-compatible HTTP endpoint, or "command"
	// to pipe the prompt into a local CLI such as codex, ollama or claude.
	Provider string `toml:"provider"`
	BaseURL  string `toml:"base_url"`
	Model    string `toml:"model"`
	// APIKey is stored in clear text in this file, which is created 0600. Prefer
	// APIKeyEnv or the NIU_LLM_API_KEY environment variable.
	APIKey    string `toml:"api_key"`
	APIKeyEnv string `toml:"api_key_env"`
	// Command is argv for the "command" provider; the prompt arrives on stdin.
	Command     []string `toml:"command"`
	Temperature float64  `toml:"temperature"`
	MaxTokens   int      `toml:"max_tokens"`
	TimeoutSec  int      `toml:"timeout_sec"`
	// Proxy overrides the transport proxy for model calls only. Empty follows the
	// global proxy, "direct" forces a direct connection.
	Proxy string `toml:"proxy"`
}

LLM configures the optional analysis backend. Nothing here is required: with an empty provider every AI command explains how to fill it in.

type Level

type Level struct {
	Symbol string  `toml:"symbol"`
	Side   string  `toml:"side"`
	Price  float64 `toml:"price"`
}

Level is a manual price alert.

type Notify

type Notify struct {
	Desktop  bool     `toml:"desktop"`
	Bell     bool     `toml:"bell"`
	Telegram Telegram `toml:"telegram"`
	Bark     Bark     `toml:"bark"`
	Feishu   Hook     `toml:"feishu"`
	Dingtalk Hook     `toml:"dingtalk"`
	Webhook  Hook     `toml:"webhook"`
}

type Position

type Position struct {
	Symbol string  `toml:"symbol"`
	Side   string  `toml:"side"`
	Entry  float64 `toml:"entry"`
	Qty    float64 `toml:"qty"`
	Mode   string  `toml:"mode"`
	Margin float64 `toml:"margin"`
	Wallet float64 `toml:"wallet"`
	MMR    float64 `toml:"mmr"`
	Stop   float64 `toml:"stop"`
	Take   float64 `toml:"take"`
}

type Proxy

type Proxy struct {
	URL        string `toml:"url"`
	AutoDetect bool   `toml:"auto_detect"`
}

type Telegram

type Telegram struct {
	Enabled bool   `toml:"enabled"`
	Token   string `toml:"token"`
	ChatID  string `toml:"chat_id"`
}

type Watch

type Watch struct {
	Symbols []string            `toml:"symbols"`
	Aliases map[string][]string `toml:"aliases"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL