Documentation
¶
Index ¶
- Constants
- func DocumentedEndpointRequestFactoryCount() int
- func DocumentedEndpointResponseFactoryCount() int
- func DocumentedRequestFields(v interface{}) (map[string]string, error)
- func NewDocumentedEndpointRequest(path string) interface{}
- func ParseKISDate(s string) (time.Time, error)
- func ParseKISDateTime(date, t string) (time.Time, error)
- func ResolveOverseasOrderTRID(exchangeCode, side string, sandbox bool) (string, error)
- func ResolveOverseasRvseCnclTRID(exchangeCode string, sandbox bool) (string, error)
- func SetGlobalTokenManager(tm TokenManager)
- type BondBalanceOutput
- type BondPriceOutput
- type Client
- func (c *Client) Authenticate(ctx context.Context, creds broker.Credentials) (*broker.Token, error)
- func (c *Client) BootstrapMasterSymbols(ctx context.Context) (int, error)
- func (c *Client) CallDocumentedEndpointInto(ctx context.Context, method string, path string, trID string, ...) error
- func (c *Client) Name() string
- func (c *Client) ReloadMasterSymbols(ctx context.Context) (int, error)
- func (c *Client) ResolveTRID(realTRID, virtualTRID string) string
- func (c *Client) SetCredentials(appKey, appSecret string)
- type DocumentedEndpointResponse
- type DocumentedResponseBase
- type DocumentedSlice
- type DomesticDailyCcldItem
- type ErrorResponse
- type FileTokenManager
- type MasterSymbol
- type OverseasCcnlItem
- type OverseasPriceOutput
- type OverseasProductBasicInfoOutput
- type ProductBasicInfoOutput
- type StockBalanceOutput
- type StockBalanceSummary
- type StockBasicInfoOutput
- type StockDailyPriceOutput
- type StockPriceOutput
- type StockRvseCnclCandidate
- type TokenManager
- type TokenResponse
Constants ¶
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" )
const ( PathPrefixUAPI = "/uapi" PathPrefixUAPISlash = "/uapi/" )
KIS REST endpoint path constants.
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" )
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" )
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" )
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
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 ¶
ParseKISDate parses KIS date strings (YYYYMMDD)
func ParseKISDateTime ¶
ParseKISDateTime parses KIS datetime strings.
func ResolveOverseasOrderTRID ¶ added in v0.8.0
ResolveOverseasOrderTRID returns documented TR_ID for overseas order endpoints.
func ResolveOverseasRvseCnclTRID ¶ added in v0.8.0
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 BondBalanceOutput ¶
type BondBalanceOutput = kisspecs.KISDomesticBondV1TradingInquireBalanceOutputItem
type BondPriceOutput ¶
type BondPriceOutput = kisspecs.KISDomesticBondV1QuotationsInquirePriceOutputItem
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the KIS HTTP 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 ¶
Authenticate authenticates with KIS and returns a token
func (*Client) BootstrapMasterSymbols ¶
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) ReloadMasterSymbols ¶
ReloadMasterSymbols force-reloads master symbols even when already loaded.
func (*Client) ResolveTRID ¶ added in v0.8.0
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 ¶
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 DomesticDailyCcldItem ¶
type DomesticDailyCcldItem = kisspecs.KISDomesticStockV1TradingInquireDailyCcldOutput1Item
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 ¶
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 OverseasCcnlItem ¶
type OverseasCcnlItem = kisspecs.KISOverseasStockV1TradingInquireCcnlOutputItem
type OverseasPriceOutput ¶
type OverseasPriceOutput = kisspecs.KISOverseasPriceV1QuotationsPriceDetailOutputItem
type OverseasProductBasicInfoOutput ¶
type OverseasProductBasicInfoOutput = kisspecs.KISOverseasPriceV1QuotationsSearchInfoOutputItem
type ProductBasicInfoOutput ¶
type ProductBasicInfoOutput = kisspecs.KISDomesticStockV1QuotationsSearchInfoOutputItem
type StockBalanceOutput ¶
type StockBalanceOutput = kisspecs.KISDomesticStockV1TradingInquireBalanceOutput1Item
type StockBalanceSummary ¶
type StockBalanceSummary = kisspecs.KISDomesticStockV1TradingInquireBalanceOutput2Item
type StockBasicInfoOutput ¶
type StockBasicInfoOutput = kisspecs.KISDomesticStockV1QuotationsSearchStockInfoOutputItem
type StockDailyPriceOutput ¶
type StockDailyPriceOutput = kisspecs.KISDomesticStockV1QuotationsInquireDailyPriceOutputItem
type StockPriceOutput ¶
type StockPriceOutput = kisspecs.KISDomesticStockV1QuotationsInquirePriceOutputItem
Legacy KIS DTO aliases. Keep these names stable while sourcing fields from generated documented endpoint types.
type StockRvseCnclCandidate ¶
type StockRvseCnclCandidate = kisspecs.KISDomesticStockV1TradingInquirePsblRvsecnclOutputItem
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