kis

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseURLReal is the production base URL
	BaseURLReal = "https://openapi.koreainvestment.com:9443"
	// BaseURLSandbox is the sandbox base URL
	BaseURLSandbox = "https://openapivts.koreainvestment.com:29443"
)
View Source
const (
	PathPrefixUAPI      = "/uapi"
	PathPrefixUAPISlash = "/uapi/"
)

KIS REST endpoint path constants.

View Source
const (
	PathDomesticStockInquirePrice               = "/uapi/domestic-stock/v1/quotations/inquire-price"
	PathDomesticStockInquireDailyPrice          = "/uapi/domestic-stock/v1/quotations/inquire-daily-price"
	PathDomesticStockInquireDailyItemChartPrice = "/uapi/domestic-stock/v1/quotations/inquire-daily-itemchartprice"
	PathDomesticStockInquireAskingPriceExpCcn   = "/uapi/domestic-stock/v1/quotations/inquire-asking-price-exp-ccn"
	PathDomesticStockInquireCcnl                = "/uapi/domestic-stock/v1/quotations/inquire-ccnl"
	PathDomesticStockInquireTimeItemConclusion  = "/uapi/domestic-stock/v1/quotations/inquire-time-itemconclusion"
	PathDomesticStockInquireMember              = "/uapi/domestic-stock/v1/quotations/inquire-member"
	PathDomesticStockInquireIndexPrice          = "/uapi/domestic-stock/v1/quotations/inquire-index-price"
	PathDomesticStockInquireIndexDailyPrice     = "/uapi/domestic-stock/v1/quotations/inquire-index-daily-price"
	PathDomesticStockInquireDailyIndexChart     = "/uapi/domestic-stock/v1/quotations/inquire-daily-indexchartprice"
	PathDomesticStockSearchStockInfo            = "/uapi/domestic-stock/v1/quotations/search-stock-info"
	PathDomesticStockSearchInfo                 = "/uapi/domestic-stock/v1/quotations/search-info"
	PathDomesticStockVolumeRank                 = "/uapi/domestic-stock/v1/quotations/volume-rank"
	PathDomesticStockRankingMarketCap           = "/uapi/domestic-stock/v1/ranking/market-cap"
	PathDomesticStockRankingFluctuation         = "/uapi/domestic-stock/v1/ranking/fluctuation"
	PathDomesticStockFinancialRatio             = "/uapi/domestic-stock/v1/finance/financial-ratio"
	PathDomesticStockDividend                   = "/uapi/domestic-stock/v1/ksdinfo/dividend"
)
View Source
const (
	PathDomesticStockTradingInquireBalance           = "/uapi/domestic-stock/v1/trading/inquire-balance"
	PathDomesticStockTradingInquirePsblRvseCncl      = "/uapi/domestic-stock/v1/trading/inquire-psbl-rvsecncl"
	PathDomesticStockTradingInquireDailyCcld         = "/uapi/domestic-stock/v1/trading/inquire-daily-ccld"
	PathDomesticStockTradingInquirePsblOrder         = "/uapi/domestic-stock/v1/trading/inquire-psbl-order"
	PathDomesticStockTradingInquirePeriodTradeProfit = "/uapi/domestic-stock/v1/trading/inquire-period-trade-profit"
	PathDomesticStockTradingOrderCash                = "/uapi/domestic-stock/v1/trading/order-cash"
	PathDomesticStockTradingOrderRvseCncl            = "/uapi/domestic-stock/v1/trading/order-rvsecncl"
)
View Source
const (
	PathOverseasPricePrice                  = "/uapi/overseas-price/v1/quotations/price"
	PathOverseasPriceInquireDailyChartPrice = "/uapi/overseas-price/v1/quotations/inquire-daily-chartprice"
	PathOverseasPriceDailyPrice             = "/uapi/overseas-price/v1/quotations/dailyprice"
	PathOverseasPricePriceDetail            = "/uapi/overseas-price/v1/quotations/price-detail"
	PathOverseasPriceInquireCcnl            = "/uapi/overseas-price/v1/quotations/inquire-ccnl"
	PathOverseasPriceInquireTimeItemChart   = "/uapi/overseas-price/v1/quotations/inquire-time-itemchartprice"
	PathOverseasPriceSearchInfo             = "/uapi/overseas-price/v1/quotations/search-info"
	PathOverseasStockRankingUpdownRate      = "/uapi/overseas-stock/v1/ranking/updown-rate"
	PathOverseasStockTradingInquireBalance  = "/uapi/overseas-stock/v1/trading/inquire-balance"
	PathOverseasStockTradingInquirePsAmount = "/uapi/overseas-stock/v1/trading/inquire-psamount"
	PathOverseasStockTradingInquireCcnl     = "/uapi/overseas-stock/v1/trading/inquire-ccnl"
	PathOverseasStockTradingOrder           = "/uapi/overseas-stock/v1/trading/order"
	PathOverseasStockTradingOrderRvseCncl   = "/uapi/overseas-stock/v1/trading/order-rvsecncl"
)
View Source
const (
	PathDomesticBondInquirePrice      = "/uapi/domestic-bond/v1/quotations/inquire-price"
	PathDomesticBondInquireDailyPrice = "/uapi/domestic-bond/v1/quotations/inquire-daily-price"
	PathDomesticBondSearchBondInfo    = "/uapi/domestic-bond/v1/quotations/search-bond-info"
	PathDomesticBondAvgUnit           = "/uapi/domestic-bond/v1/quotations/avg-unit"
	PathDomesticBondInquireBalance    = "/uapi/domestic-bond/v1/trading/inquire-balance"
	PathETFETNComponentStockPrice     = "/uapi/etfetn/v1/quotations/inquire-component-stock-price"
)

Variables

This section is empty.

Functions

func DocumentedEndpointRequestFactoryCount added in v0.8.2

func DocumentedEndpointRequestFactoryCount() int

DocumentedEndpointRequestFactoryCount returns the number of typed documented endpoint requests.

func DocumentedRequestFields added in v0.8.0

func DocumentedRequestFields(v interface{}) (map[string]string, error)

DocumentedRequestFields normalizes documented request structs/maps into endpoint fields.

func GetTokenManager

func GetTokenManager() tokencache.Manager

GetTokenManager returns the global token manager. The default implementation is file-backed.

func NewDocumentedEndpointRequest added in v0.8.2

func NewDocumentedEndpointRequest(path string) interface{}

NewDocumentedEndpointRequest returns a typed request object for the endpoint path.

func ResolveOverseasOrderTRID added in v0.8.0

func ResolveOverseasOrderTRID(exchangeCode, side string, sandbox bool) (string, error)

ResolveOverseasOrderTRID returns documented TR_ID for overseas order endpoints.

func ResolveOverseasRvseCnclTRID added in v0.8.0

func ResolveOverseasRvseCnclTRID(exchangeCode string, sandbox bool) (string, error)

ResolveOverseasRvseCnclTRID returns documented TR_ID for overseas revise/cancel endpoints.

Types

type Client

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

Client is the KIS HTTP client

func NewClientWithTokenManager

func NewClientWithTokenManager(sandbox bool, tokenManager tokencache.Manager) *Client

NewClientWithTokenManager creates a new KIS client with an injected token manager. When tokenManager is nil, the global default manager is used.

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context, creds broker.Credentials) (*broker.Token, error)

Authenticate authenticates with KIS and returns a token

func (*Client) BootstrapMasterSymbols

func (c *Client) BootstrapMasterSymbols(ctx context.Context) (int, error)

BootstrapMasterSymbols downloads and parses KIS master symbol files once per process.

func (*Client) CallDocumentedEndpointInto added in v0.8.0

func (c *Client) CallDocumentedEndpointInto(
	ctx context.Context,
	method string,
	path string,
	trID string,
	fields map[string]string,
	result interface{},
) error

CallDocumentedEndpointInto calls a documented KIS endpoint and decodes into result. result should be a pointer to a struct response type.

func (*Client) Name

func (c *Client) Name() string

Name returns the broker name

func (*Client) ReloadMasterSymbols

func (c *Client) ReloadMasterSymbols(ctx context.Context) (int, error)

ReloadMasterSymbols force-reloads master symbols even when already loaded.

func (*Client) ResolveTRID added in v0.8.0

func (c *Client) ResolveTRID(realTRID, virtualTRID string) string

ResolveTRID picks the environment-appropriate TR_ID from documented real/virtual IDs. It returns empty string when no usable TR_ID exists.

func (*Client) SetCredentials

func (c *Client) SetCredentials(appKey, appSecret string)

SetCredentials sets the app key and secret, and binds the client to the shared per-app-key limiter so sibling Clients don't collectively exceed KIS's TPS quota.

func (*Client) SetLogger added in v0.13.0

func (c *Client) SetLogger(l *slog.Logger)

SetLogger sets the logger for the client.

type FileTokenManager

type FileTokenManager struct {
	*filetoken.Manager
}

FileTokenManager stores tokens in memory and persists them to disk.

func NewFileTokenManager

func NewFileTokenManager() *FileTokenManager

NewFileTokenManager creates the default file-backed token manager.

func NewFileTokenManagerWithDir

func NewFileTokenManagerWithDir(dir string) *FileTokenManager

NewFileTokenManagerWithDir creates a file-backed token manager with an optional fixed directory. When dir is empty, the default directory resolution is used.

type MasterSymbol

type MasterSymbol struct {
	Symbol          string
	Market          string
	Name            string
	NameEn          string
	Exchange        string
	Currency        string
	Country         string
	ProductType     string
	ProductTypeCode string
	SecurityGroup   string
	IsListed        bool
}

MasterSymbol is a parsed symbol record from KIS master files (.mst/.cod).

func LookupMasterSymbol

func LookupMasterSymbol(market, symbol string) (MasterSymbol, bool)

LookupMasterSymbol returns a symbol record from preloaded master files.

type TokenResponse

type TokenResponse struct {
	AccessToken           string `json:"access_token"`
	AccessTokenExpired    string `json:"access_token_token_expired"`
	TokenType             string `json:"token_type"`
	ExpiresIn             int    `json:"expires_in"`
	AccessTokenExpiresStr string `json:"access_token_expires"`
}

TokenResponse represents the KIS token response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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