Documentation
¶
Overview ¶
Package config is config.yml, the configuration of the controller (cmd/controller) and of the migrations (cmd/migrator): what they need to start and to reach PostgreSQL. Every other setting, the agents, the users, Telegram and the prompts, is in the database.
The file is read once, at the start, with the ${VAR} of the environment expanded anywhere in it, eg: the password of the database and the key of the secrets, which stay out of the file (see configs/config.example.yml). The text is expanded before the YAML is read (gobox/config), so a ${VAR} stays between single quotes, eg: a password starting with @ or holding " #".
Index ¶
Constants ¶
const OutputWait = time.Second
OutputWait is how long the controller waits for the output of a process once it exited, eg: held by a process out of its group, such as the X server a script of the bridge starts in a session of its own (see controller.Supervisor): each phase of the stop, the agents then the services, may take that long beyond its stop_timeout.
Variables ¶
var ErrInvalid = errors.New("config: invalid")
ErrInvalid is the error of a configuration that can't be used.
var Kinds = []string{"llm", "trend", "momentum", "breakout", "intraday"}
Kinds are the kinds of agents, of the binaries the controller launches.
Functions ¶
This section is empty.
Types ¶
type Agents ¶
type Agents struct {
// API is the address of the internal API the agents fetch their settings
// from and persist through, on the loopback: never published.
API string `mapstructure:"api"`
// Dir is the working directory of the agents, eg: the root of the
// repository for go run.
Dir string `mapstructure:"dir"`
// Commands is the command of each kind, eg: go run ./agents/llm/llmagent,
// or /app/bin/llmagent in the container.
Commands map[string]string `mapstructure:"commands"`
// Env holds the variables of their environment besides PATH, HOME, USER,
// LOGNAME, TZ, LANG, LC_ALL and TMPDIR, eg: GOCACHE=/tmp/go-cache for go
// run: never a secret, they get theirs from the controller. The services
// don't get it.
Env Env `mapstructure:"env"`
// StopTimeout is how long an agent stopped has before it is killed.
StopTimeout time.Duration `mapstructure:"stop_timeout"`
}
Agents is how the controller runs the agents of the database.
type Backtest ¶
type Backtest struct {
Concurrency int `mapstructure:"concurrency"`
Dir string `mapstructure:"dir"`
MaxPeriodDays int `mapstructure:"max_period_days"`
MaxRuns int `mapstructure:"max_runs"`
LLMMaxCalls int `mapstructure:"llm_max_calls"`
LLMMaxCost float64 `mapstructure:"llm_max_cost"`
LLMPrices map[string]LLMPrice `mapstructure:"llm_prices"`
}
Backtest is how the controller runs the backtests of the dashboard: each run a process of the command of the kind of its agent (see Agents), apart from the agents trading, never a broker. Concurrency runs at once at most (2 by default); Dir keeps their candles and files (data/backtests by default, under Agents.Dir when relative); MaxPeriodDays bounds the period of a batch (366 by default) and MaxRuns its runs (40). For the agents of a language model, the defaults of the ceilings of a run: LLMMaxCalls calls of the model (300) and LLMMaxCost dollars (5, see LLMPrices: unknown without the price of the model, the calls bound it then).
type Bootstrap ¶
type Bootstrap struct {
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
}
Bootstrap is the first user of the dashboard, created by the controller while the database has none: its password hashed, then unused. Remove the variables of the password once in.
type Config ¶
type Config struct {
// Listen is the address of the web dashboard, eg: 0.0.0.0:8080.
Listen string `mapstructure:"listen"`
Database Database `mapstructure:"database"`
Migrations Migrations `mapstructure:"migrations"`
// SecretsKey is the key of the secrets kept in the database, the API keys
// and the tokens, encrypted with AES-256-GCM: 32 bytes in standard base64,
// eg: from `head -c 32 /dev/urandom | base64`. Lost, the secrets have to be
// set again.
SecretsKey string `mapstructure:"secrets_key"`
Bootstrap Bootstrap `mapstructure:"bootstrap"`
UI UI `mapstructure:"ui"`
Agents Agents `mapstructure:"agents"`
Services []Service `mapstructure:"services"`
Log Log `mapstructure:"log"`
Backtest Backtest `mapstructure:"backtest"`
// ShutdownTimeout is the whole stop of the controller, from the signal
// to its exit: the agents stopped (agents.stop_timeout), then the
// services (their stop_timeout); whatever still runs once it passed is
// killed. Who stops the controller waits for it longer, eg: the
// stop_grace_period of the compose, or tools/automator.sh. By default,
// agents.stop_timeout plus the longest stop_timeout of the services plus
// shutdownMargin; never under them plus shutdownSlack.
ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout"`
// Warnings are the ${VAR} of the file that weren't set, taken as empty,
// by Load: the ones it can't do without fail it instead, see checkUnset.
Warnings []string `mapstructure:"-"`
}
Config is the configuration of config.yml.
func (*Config) StopTimeouts ¶
StopTimeouts returns how long the stops of the agents and of the services take at most, one after the other: agents.stop_timeout plus the longest stop_timeout of the services.
type Database ¶
type Database struct {
// DSN is the URL of the database, eg:
// postgres://xtrader:${XTRADER_DB_PASSWORD}@localhost:5432/xtrader?sslmode=disable
DSN string `mapstructure:"dsn"`
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
// LogLevel is the one of the queries logged: silent, error or warn (the
// slow ones), their values left out.
LogLevel string `mapstructure:"log_level"`
}
Database is the connection to PostgreSQL.
type Env ¶
type Env []string
Env is the environment of a process of config.yml, NAME=value each: a list, as the names of the variables keep their case there, not as the keys of a map.
type LLMPrice ¶
type LLMPrice struct {
Input float64 `mapstructure:"input" json:"input"`
Output float64 `mapstructure:"output" json:"output"`
}
LLMPrice is the price of a model, by its name, in dollars per million tokens of its input and of its output, to estimate the cost of a backtest.
type Log ¶
type Log struct {
Level string `mapstructure:"level"`
}
Log is the logging of the controller.
type Migrations ¶
Migrations are the directories of the SQL files of cmd/migrator.
type Service ¶
type Service struct {
Name string `mapstructure:"name"`
Exec string `mapstructure:"exec"`
Args []string `mapstructure:"args"`
Env Env `mapstructure:"env"`
Restart bool `mapstructure:"restart"`
Health string `mapstructure:"health"`
Wait time.Duration `mapstructure:"wait"`
StopTimeout time.Duration `mapstructure:"stop_timeout"`
}
Service is a process the agents need, eg: tools/mt5bridge on the host, launched before them from Dir of Agents and stopped after them: once Health, a URL, answers, whatever its status, it is up, or after Wait at most (3 minutes by default). One answering already isn't launched, nor stopped. StopTimeout is how long it has to exit once interrupted before it is killed (10 seconds by default). Its environment is the base one of the agents (PATH, HOME, USER, LOGNAME, TZ, LANG, LC_ALL and TMPDIR) plus Env, never the Env of Agents.
type UI ¶
type UI struct {
Dir string `mapstructure:"dir"`
Version string `mapstructure:"version"`
// TrustedProxies are the reverse proxies in front of the dashboard, IPs or
// CIDRs, eg: ngrok on the host: only the X-Forwarded-For and
// X-Forwarded-Proto of a request coming from one of them are believed, for
// the address of the client (the logs and the limits of the logins) and
// its HTTPS. The loopback by default.
TrustedProxies []string `mapstructure:"trusted_proxies"`
}
UI is the bundle of the web dashboard: a local build, eg: web/dist, or else a release, latest by default.