Documentation
¶
Index ¶
- Constants
- func DocumentedEndpointRequestFactoryCount() int
- func DocumentedRequestFields(v interface{}) (map[string]string, error)
- func GetTokenManager() tokencache.Manager
- func NewDocumentedEndpointRequest(path string) interface{}
- func ResolveOverseasOrderTRID(exchangeCode, side string, sandbox bool) (string, error)
- func ResolveOverseasRvseCnclTRID(exchangeCode string, sandbox bool) (string, error)
- 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)
- func (c *Client) SetLogger(l *slog.Logger)
- type FileTokenManager
- type MasterSymbol
- 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 DocumentedRequestFields ¶ added in v0.8.0
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
ResolveOverseasOrderTRID returns documented TR_ID for overseas order 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 ¶
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, and binds the client to the shared per-app-key limiter so sibling Clients don't collectively exceed KIS's TPS quota.
type FileTokenManager ¶
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