server

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package server provides a ready-to-use HTTP API server that can be wired with any github.com/smallfish06/krsec/pkg/broker.Broker implementation.

Use New to create a server with externally supplied broker instances, then call Server.Run to start listening. The server exposes REST endpoints for quotes, orders, accounts, instruments, and an auto-generated OpenAPI spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultKISProxyCachePolicy added in v0.15.0

func DefaultKISProxyCachePolicy(req KISProxyCacheRequest) (time.Duration, bool)

DefaultKISProxyCachePolicy caches public KIS quotation/reference endpoints and excludes trading, order, and auth-style endpoints.

func RunFromConfigFile added in v0.7.0

func RunFromConfigFile(path string) error

RunFromConfigFile loads a config.yaml and starts the server. This is the simplest way to embed krsec in another project.

func RunFromConfigFileWithLogger added in v0.13.0

func RunFromConfigFileWithLogger(path string, logger *slog.Logger) error

RunFromConfigFileWithLogger loads a config.yaml and starts the server with a custom logger.

Types

type Account

type Account struct {
	ID          string
	Name        string
	Broker      string
	Sandbox     bool
	Credentials broker.Credentials
}

Account describes an externally supplied account/broker binding.

type KISProxyCacheOptions added in v0.15.0

type KISProxyCacheOptions struct {
	Policy         KISProxyCachePolicy
	MaxEntries     int
	StaleRetention time.Duration
}

KISProxyCacheOptions configures the in-process KIS proxy cache.

type KISProxyCachePolicy added in v0.15.0

type KISProxyCachePolicy func(KISProxyCacheRequest) (time.Duration, bool)

KISProxyCachePolicy decides whether a KIS proxy request should be cached and returns its soft TTL when cacheable.

type KISProxyCacheRequest added in v0.15.0

type KISProxyCacheRequest struct {
	Method    string
	Path      string
	TRID      string
	AccountID string
	Params    map[string]string
}

KISProxyCacheRequest describes a normalized KIS proxy request for cache policy decisions. Params is a copy and can be inspected or modified by policy code.

type KISProxyRateLimitOptions added in v0.16.0

type KISProxyRateLimitOptions struct {
	Disabled          bool
	RequestsPerSecond float64
	Burst             int
}

KISProxyRateLimitOptions configures outbound KIS upstream throttling.

type Options

type Options struct {
	Host              string
	Port              int
	Accounts          []Account
	Brokers           map[string]broker.Broker // account_id -> broker implementation
	Logger            *slog.Logger             // optional structured logger; nil uses slog.Default()
	KISProxyCache     KISProxyCacheOptions
	KISProxyRateLimit KISProxyRateLimitOptions
}

Options configures the public API server. External users can provide their own broker implementations through Brokers.

type Server

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

Server wraps the internal HTTP server and exposes a stable public API.

func New

func New(opts Options) *Server

New creates a server with externally supplied broker implementations.

func (*Server) App

func (s *Server) App() *fuego.Server

App returns the underlying Fuego server for embedding or custom route composition.

func (*Server) Run

func (s *Server) Run() error

Run starts the HTTP server.

Jump to

Keyboard shortcuts

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