kis

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 23 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 DocumentedEndpointResponseFactoryCount added in v0.8.0

func DocumentedEndpointResponseFactoryCount() int

DocumentedEndpointResponseFactoryCount returns the number of typed documented endpoint responses.

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 NewDocumentedEndpointRequest added in v0.8.2

func NewDocumentedEndpointRequest(path string) interface{}

NewDocumentedEndpointRequest returns a typed request object for the endpoint path.

func ParseKISDate

func ParseKISDate(s string) (time.Time, error)

ParseKISDate parses KIS date strings (YYYYMMDD)

func ParseKISDateTime

func ParseKISDateTime(date, t string) (time.Time, error)

ParseKISDateTime parses KIS datetime strings.

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.

func SetGlobalTokenManager

func SetGlobalTokenManager(tm TokenManager)

SetGlobalTokenManager overrides the global token manager implementation. If tm is nil, the default file-backed manager is used.

Types

type Client

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

Client is the KIS HTTP client

func NewClient

func NewClient(sandbox bool) *Client

NewClient creates a new KIS client

func NewClientWithTokenManager

func NewClientWithTokenManager(sandbox bool, tokenManager TokenManager) *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

type DocumentedEndpointResponse added in v0.8.0

type DocumentedEndpointResponse = kisspecs.DocumentedEndpointResponse

DocumentedEndpointResponse is the typed response contract for documented KIS endpoints.

func NewDocumentedEndpointResponse added in v0.8.0

func NewDocumentedEndpointResponse(path string) DocumentedEndpointResponse

NewDocumentedEndpointResponse returns a typed response object for the endpoint path.

type DocumentedResponseBase added in v0.8.0

type DocumentedResponseBase = kisspecs.DocumentedResponseBase

DocumentedResponseBase holds common KIS response status fields.

type DocumentedSlice added in v0.8.0

type DocumentedSlice[T any] = kisspecs.DocumentedSlice[T]

DocumentedSlice accepts both object and array payloads and normalizes them to a typed slice.

type ErrorResponse

type ErrorResponse = kisspecs.DocumentedResponseBase

ErrorResponse represents KIS API error response. Kept as a thin alias for compatibility.

type FileTokenManager

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

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.

func (*FileTokenManager) GetToken

func (tm *FileTokenManager) GetToken(appKey string) (string, time.Time, bool)

GetToken returns the cached token for the given appkey Returns (token, expiresAt, found)

func (*FileTokenManager) SetToken

func (tm *FileTokenManager) SetToken(appKey, token string, expiresAt time.Time) error

SetToken stores the token for the given appkey (in memory and on disk)

func (*FileTokenManager) WaitForAuth

func (tm *FileTokenManager) WaitForAuth(appKey string)

WaitForAuth enforces the per-appkey token issuance rate limit (1/minute)

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 StockPriceOutput

Legacy KIS DTO aliases. Keep these names stable while sourcing fields from generated documented endpoint types.

type TokenManager

type TokenManager interface {
	GetToken(appKey string) (string, time.Time, bool)
	SetToken(appKey, token string, expiresAt time.Time) error
	WaitForAuth(appKey string)
}

TokenManager defines token cache and token-issuance throttling behavior. Custom implementations can be injected into Client/Adapter constructors.

func GetTokenManager

func GetTokenManager() TokenManager

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

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