config

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Client custom http client
	Client *http.Client

	HttpURL         string           `env:"LONGBRIDGE_HTTP_URL,LONGPORT_HTTP_URL" yaml:"http_url" toml:"http_url"`
	HTTPTimeout     time.Duration    `env:"LONGBRIDGE_HTTP_TIMEOUT,LONGPORT_HTTP_TIMEOUT" yaml:"http_timeout" toml:"http_timeout"`
	AppKey          string           `env:"LONGBRIDGE_APP_KEY,LONGPORT_APP_KEY" yaml:"app_key" toml:"app_key"`
	AppSecret       string           `env:"LONGBRIDGE_APP_SECRET,LONGPORT_APP_SECRET" yaml:"app_secret" toml:"app_secret"`
	AccessToken     string           `env:"LONGBRIDGE_ACCESS_TOKEN,LONGPORT_ACCESS_TOKEN" yaml:"access_token" toml:"access_token"`
	TradeUrl        string           `env:"LONGBRIDGE_TRADE_URL,LONGPORT_TRADE_URL" yaml:"trade_url" toml:"trade_url"`
	QuoteUrl        string           `env:"LONGBRIDGE_QUOTE_URL,LONGPORT_QUOTE_URL" yaml:"quote_url" toml:"quote_url"`
	EnableOvernight bool             `env:"LONGPORT_ENABLE_OVERNIGHT" yaml:"enable_overnight" toml:"enable_overnight"`
	Language        openapi.Language `env:"LONGPORT_LANGUAGE" yaml:"language" toml:"language"`

	LogLevel string `env:"LONGBRIDGE_LOG_LEVEL,LONGPORT_LOG_LEVEL" yaml:"log_level" toml:"log_level"`

	// OAuthClient is set when using OAuth 2.0 with auto-refresh (see WithOAuthClient).
	OAuthClient *oauth.OAuth

	// longbridge protocol config
	AuthTimeout    time.Duration `env:"LONGBRIDGE_AUTH_TIMEOUT,LONGPORT_AUTH_TIMEOUT" yaml:"auth_timeout" toml:"auth_timeout"`
	Timeout        time.Duration `env:"LONGBRIDGE_TIMEOUT,LONGPORT_TIMEOUT" yaml:"timeout" toml:"timeout"`
	WriteQueueSize int           `env:"LONGBRIDGE_WRITE_QUEUE_SIZE,LONGPORT_WRITE_QUEUE_SIZE" yaml:"write_queue_size" toml:"write_queue_size"`
	ReadQueueSize  int           `env:"LONGBRIDGE_READ_QUEUE_SIZE,LONGPORT_READ_QUEUE_SIZE" yaml:"read_queue_size" toml:"read_queue_size"`
	ReadBufferSize int           `env:"LONGBRIDGE_READ_BUFFER_SIZE,LONGPORT_READ_BUFFER_SIZE" yaml:"read_buffer_size" toml:"read_buffer_size"`
	MinGzipSize    int           `env:"LONGBRIDGE_MIN_GZIP_SIZE,LONGPORT_MIN_GZIP_SIZE" yaml:"min_gzip_size" toml:"min_gzip_size"`
	Region         Region        `env:"LONGPORT_REGION" yaml:"region" toml:"region"`
	// contains filtered or unexported fields
}

Config store Longbridge config

func New

func New(opts ...Option) (configData *Config, err error)

func NewFormEnv deprecated

func NewFormEnv() (*Config, error)

Deprecated: NewFormEnv to create config from environment variables

func (*Config) Logger

func (c *Config) Logger() log.Logger

func (*Config) SetLogger

func (c *Config) SetLogger(l log.Logger)

type ConfigType

type ConfigType string
const (
	ConfigTypeEnv  ConfigType = ".env"
	ConfigTypeYAML ConfigType = ".yaml"
	ConfigTypeTOML ConfigType = ".toml"
)

type EnvConfig

type EnvConfig struct {
}

func (*EnvConfig) GetConfig

func (c *EnvConfig) GetConfig(_ *Options) (data *Config, err error)

type IConfig

type IConfig interface {
	GetConfig(opts *Options) (*Config, error)
}

type Option

type Option func(*Options)

func WithConfigKey

func WithConfigKey(appKey string, appSecret string, accessToken string) Option

WithConfigKey config appKey, appSecret, accessToken

func WithFilePath

func WithFilePath(filePath string) Option

WithFilePath config path

func WithOAuthClient

func WithOAuthClient(o *oauth.OAuth) Option

WithOAuthClient configures the client to use OAuth 2.0 with the given OAuth client. The token is refreshed automatically. Call oauth.Build(ctx) before creating config. Usage (like Rust SDK):

o := oauth.New("client-id").OnOpenURL(func(url string) { ... })
if err := o.Build(ctx); err != nil { ... }
cfg, _ := config.New(config.WithOAuthClient(o))

type Options

type Options struct {
	// contains filtered or unexported fields
}

type Region

type Region string
var (
	RegionCN Region = "cn"
)

type TOMLConfig

type TOMLConfig struct {
}

func (*TOMLConfig) GetConfig

func (c *TOMLConfig) GetConfig(opts *Options) (*Config, error)

type YAMLConfig

type YAMLConfig struct {
}

func (*YAMLConfig) GetConfig

func (c *YAMLConfig) GetConfig(opts *Options) (*Config, error)

Jump to

Keyboard shortcuts

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