kiwoom

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BaseURLReal is Kiwoom production REST domain.
	BaseURLReal = "https://api.kiwoom.com"
	// BaseURLSandbox is Kiwoom mock REST domain.
	BaseURLSandbox = "https://mockapi.kiwoom.com"
)
View Source
const (
	PathPrefixAPI      = "/api"
	PathPrefixAPISlash = "/api/"
)

Kiwoom REST path prefixes.

View Source
const (
	PathStockInfo   = "/api/dostk/stkinfo"
	PathMarketCond  = "/api/dostk/mrkcond"
	PathForeignInst = "/api/dostk/frgnistt"
	PathRankingInfo = "/api/dostk/rkinfo"
	PathSector      = "/api/dostk/sect"
	PathELW         = "/api/dostk/elw"
	PathETF         = "/api/dostk/etf"
	PathTheme       = "/api/dostk/thme"
	PathSLB         = "/api/dostk/slb"
	PathShortSell   = "/api/dostk/shsa"
	PathAccount     = "/api/dostk/acnt"
	PathChart       = "/api/dostk/chart"
	PathOrder       = "/api/dostk/ordr"
	PathCreditOrder = "/api/dostk/crdordr"
	PathWebSocket   = "/api/dostk/websocket"
)

Kiwoom endpoint paths.

View Source
const (
	APIIDDomesticQuote                = "ka10001"
	APIIDDomesticExecutionInfo        = "ka10003"
	APIIDDomesticOrderBook            = "ka10004"
	APIIDInstrumentInfo               = "ka10100"
	APIIDInvestorByStock              = "ka10059"
	APIIDSectorCurrent                = "ka20001"
	APIIDSectorByPrice                = "ka20002"
	APIIDVolumeRank                   = "ka10030"
	APIIDChangeRateRank               = "ka10027"
	APIIDELWDetail                    = "ka30012"
	APIIDAccountBalance               = "kt00005"
	APIIDAccountPositions             = "kt00018"
	APIIDUnsettledOrders              = "ka10075"
	APIIDOrderExecutions              = "ka10076"
	APIIDAccountDepositDetail         = "kt00001"
	APIIDAccountOrderExecutionDetail  = "kt00007"
	APIIDAccountOrderExecutionStatus  = "kt00009"
	APIIDAccountOrderableWithdrawable = "kt00010"
	APIIDAccountMarginDetail          = "kt00013"
	APIIDTickChart                    = "ka10079"
	APIIDInvestorByStockChart         = "ka10060"
	APIIDDailyChart                   = "ka10081"
	APIIDWeeklyChart                  = "ka10082"
	APIIDMonthlyChart                 = "ka10083"
	APIIDPlaceBuyOrder                = "kt10000"
	APIIDPlaceSellOrder               = "kt10001"
	APIIDModifyOrder                  = "kt10002"
	APIIDCancelOrder                  = "kt10003"
)

Kiwoom API IDs used by implemented functions.

Variables

This section is empty.

Functions

func SetGlobalTokenManager

func SetGlobalTokenManager(tm TokenManager)

SetGlobalTokenManager overrides the global token manager implementation.

Types

type AccountBalance

type AccountBalance struct {
	Deposit              float64
	DepositD1            float64
	DepositD2            float64
	OrderableAmount      float64
	WithdrawableAmount   float64
	UnsettledStockAmount float64
	StockBuyTotalAmount  float64
	EvaluationTotal      float64
	TotalProfitLoss      float64
	TotalProfitLossRate  float64
	PresumedAssetAmount  float64
	CreditLoanTotal      float64
	ReturnMsg            string
	ReturnCode           int
}

AccountBalance is a typed subset of kt00005 response.

type AccountPosition

type AccountPosition struct {
	StockCode        string
	StockName        string
	RemainingQty     int64
	TradableQty      int64
	TodayBuyQty      int64
	TodaySellQty     int64
	PurchasePrice    float64
	CurrentPrice     float64
	PurchaseAmount   float64
	EvaluationAmount float64
	EvaluationProfit float64
	ProfitRate       float64
	WeightRate       float64
	CreditLoanDate   string
}

AccountPosition is a typed position row from kt00018.

type CancelStockOrderRequest

type CancelStockOrderRequest struct {
	Exchange   string
	OriginalID string
	Symbol     string
	CancelQty  int64
}

CancelStockOrderRequest is input for kt10003.

type ChartCandle

type ChartCandle struct {
	Date   time.Time
	Open   float64
	High   float64
	Low    float64
	Close  float64
	Volume int64
}

ChartCandle is a normalized candle row from ka10081/ka10082/ka10083.

type Client

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

Client is a Kiwoom HTTP client with token caching and API-id routing.

func NewClient

func NewClient(sandbox bool) *Client

NewClient creates a new Kiwoom client.

func NewClientWithTokenManager

func NewClientWithTokenManager(sandbox bool, tm TokenManager) *Client

NewClientWithTokenManager creates a client with injected token manager.

func (*Client) Authenticate

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

Authenticate issues or reuses an OAuth token.

func (*Client) CallCustom added in v0.6.0

func (c *Client) CallCustom(ctx context.Context, apiID, path string, body map[string]interface{}) (map[string]interface{}, error)

CallCustom exposes a typed Kiwoom REST call for APIs not yet wrapped in this client.

func (*Client) CancelStockOrder

func (c *Client) CancelStockOrder(ctx context.Context, req CancelStockOrderRequest) (*OrderAck, error)

CancelStockOrder cancels order through kt10003.

func (*Client) InquireBalance

func (c *Client) InquireBalance(ctx context.Context, exchange string) (*AccountBalance, error)

InquireBalance fetches kt00005.

func (*Client) InquireBondPositions added in v0.6.0

func (c *Client) InquireBondPositions(ctx context.Context, exchange string) ([]AccountPosition, error)

InquireBondPositions is a convenience wrapper for bond holdings.

func (*Client) InquireChangeRateRank added in v0.6.0

func (c *Client) InquireChangeRateRank(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireChangeRateRank fetches domestic change-rate ranking via ka10027.

func (*Client) InquireDailyPrice

func (c *Client) InquireDailyPrice(ctx context.Context, symbol, baseDate string) ([]ChartCandle, error)

InquireDailyPrice fetches daily candles from ka10081.

func (*Client) InquireDepositDetail added in v0.6.0

func (c *Client) InquireDepositDetail(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireDepositDetail fetches account deposit detail via kt00001.

func (*Client) InquireELWDetail added in v0.6.0

func (c *Client) InquireELWDetail(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireELWDetail fetches ELW/ETF-related detail via ka30012.

func (*Client) InquireExecutionInfo added in v0.6.0

func (c *Client) InquireExecutionInfo(ctx context.Context, symbol string) (map[string]interface{}, error)

InquireExecutionInfo fetches domestic execution info via ka10003.

func (*Client) InquireInstrumentInfo

func (c *Client) InquireInstrumentInfo(ctx context.Context, symbol string) (*InstrumentInfo, error)

InquireInstrumentInfo fetches ka10100.

func (*Client) InquireInvestorByStock added in v0.6.0

func (c *Client) InquireInvestorByStock(ctx context.Context, symbol string, body map[string]interface{}) (map[string]interface{}, error)

InquireInvestorByStock fetches investor trend by stock via ka10059.

func (*Client) InquireInvestorByStockChart added in v0.6.0

func (c *Client) InquireInvestorByStockChart(ctx context.Context, symbol string, body map[string]interface{}) (map[string]interface{}, error)

InquireInvestorByStockChart fetches investor trend chart via ka10060.

func (*Client) InquireMarginDetail added in v0.6.0

func (c *Client) InquireMarginDetail(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireMarginDetail fetches margin detail via kt00013.

func (*Client) InquireMonthlyPrice

func (c *Client) InquireMonthlyPrice(ctx context.Context, symbol, baseDate string) ([]ChartCandle, error)

InquireMonthlyPrice fetches monthly candles from ka10083.

func (*Client) InquireOrderBook added in v0.6.0

func (c *Client) InquireOrderBook(ctx context.Context, symbol string) (map[string]interface{}, error)

InquireOrderBook fetches domestic orderbook/remaining sizes via ka10004.

func (*Client) InquireOrderExecutionDetail added in v0.6.0

func (c *Client) InquireOrderExecutionDetail(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireOrderExecutionDetail fetches detailed order/fill history via kt00007.

func (*Client) InquireOrderExecutionStatus added in v0.6.0

func (c *Client) InquireOrderExecutionStatus(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireOrderExecutionStatus fetches order/fill status via kt00009.

func (*Client) InquireOrderExecutions

func (c *Client) InquireOrderExecutions(ctx context.Context, symbol string) ([]OrderExecution, error)

InquireOrderExecutions fetches ka10076.

func (*Client) InquireOrderExecutionsByExchange added in v0.6.0

func (c *Client) InquireOrderExecutionsByExchange(ctx context.Context, symbol, exchangeType string) ([]OrderExecution, error)

InquireOrderExecutionsByExchange fetches execution rows with explicit exchange scope.

func (*Client) InquireOrderableWithdrawable added in v0.6.0

func (c *Client) InquireOrderableWithdrawable(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireOrderableWithdrawable fetches orderable/withdrawable amounts via kt00010.

func (*Client) InquirePositions

func (c *Client) InquirePositions(ctx context.Context, queryType, exchange string) ([]AccountPosition, error)

InquirePositions fetches kt00018.

func (*Client) InquirePositionsByAsset added in v0.6.0

func (c *Client) InquirePositionsByAsset(ctx context.Context, queryType, exchange, stockBondType string) ([]AccountPosition, error)

InquirePositionsByAsset fetches positions with optional stock/bond filter (e.g. 1=stock, 2=bond).

func (*Client) InquirePrice

func (c *Client) InquirePrice(ctx context.Context, symbol string) (*DomesticQuote, error)

InquirePrice fetches ka10001 and returns typed quote fields.

func (*Client) InquireSectorByPrice added in v0.6.0

func (c *Client) InquireSectorByPrice(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireSectorByPrice fetches sector-by-price data via ka20002.

func (*Client) InquireSectorCurrent added in v0.6.0

func (c *Client) InquireSectorCurrent(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireSectorCurrent fetches sector current quote via ka20001.

func (*Client) InquireTickChart added in v0.6.0

func (c *Client) InquireTickChart(ctx context.Context, symbol, baseDate string) (map[string]interface{}, error)

InquireTickChart fetches domestic tick chart via ka10079.

func (*Client) InquireUnsettledOrders

func (c *Client) InquireUnsettledOrders(ctx context.Context, symbol string) ([]UnsettledOrder, error)

InquireUnsettledOrders fetches ka10075.

func (*Client) InquireUnsettledOrdersByExchange added in v0.6.0

func (c *Client) InquireUnsettledOrdersByExchange(ctx context.Context, symbol, exchangeType string) ([]UnsettledOrder, error)

InquireUnsettledOrdersByExchange fetches unsettled orders with explicit exchange scope.

func (*Client) InquireVolumeRank added in v0.6.0

func (c *Client) InquireVolumeRank(ctx context.Context, body map[string]interface{}) (map[string]interface{}, error)

InquireVolumeRank fetches domestic volume ranking via ka10030.

func (*Client) InquireWeeklyPrice

func (c *Client) InquireWeeklyPrice(ctx context.Context, symbol, baseDate string) ([]ChartCandle, error)

InquireWeeklyPrice fetches weekly candles from ka10082.

func (*Client) ModifyStockOrder

func (c *Client) ModifyStockOrder(ctx context.Context, req ModifyStockOrderRequest) (*OrderAck, error)

ModifyStockOrder modifies order through kt10002.

func (*Client) Name

func (c *Client) Name() string

Name returns broker name.

func (*Client) PlaceStockOrder

func (c *Client) PlaceStockOrder(ctx context.Context, req PlaceStockOrderRequest) (*OrderAck, error)

PlaceStockOrder places kt10000 (buy) or kt10001 (sell).

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string)

SetBaseURL overrides the API base URL. Primarily useful for tests or private/proxy deployments.

func (*Client) SetCredentials

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

SetCredentials sets app credentials on this client.

type DomesticQuote

type DomesticQuote struct {
	Symbol     string
	Name       string
	Price      float64
	Open       float64
	High       float64
	Low        float64
	BasePrice  float64
	UpperLimit float64
	LowerLimit float64
	Change     float64
	ChangeRate float64
	Volume     int64
	ReturnMsg  string
	ReturnCode int
}

DomesticQuote is a typed subset of ka10001 response.

type FileTokenManager

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

FileTokenManager stores tokens in memory and on 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 manager with optional fixed directory.

func (*FileTokenManager) GetToken

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

GetToken returns the cached token if still valid.

func (*FileTokenManager) SetToken

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

SetToken stores the token in memory and on disk.

func (*FileTokenManager) WaitForAuth

func (tm *FileTokenManager) WaitForAuth(appKey string)

WaitForAuth enforces per-appkey token issuance limits.

type InstrumentInfo

type InstrumentInfo struct {
	Code       string
	Name       string
	ListCount  int64
	RegDay     string
	State      string
	MarketCode string
	MarketName string
	SectorName string
	ReturnMsg  string
	ReturnCode int
}

InstrumentInfo is a typed subset of ka10100 response.

type ModifyStockOrderRequest

type ModifyStockOrderRequest struct {
	Exchange       string
	OriginalID     string
	Symbol         string
	ModifyQty      int64
	ModifyPrice    string
	ConditionPrice string
}

ModifyStockOrderRequest is input for kt10002.

type OrderAck

type OrderAck struct {
	OrderNumber string
	ReturnMsg   string
	ReturnCode  int
}

OrderAck represents order ack payload from kt10000/1/2/3.

type OrderExecution

type OrderExecution struct {
	OrderNumber    string
	StockCode      string
	OrderSideText  string
	ExecutionPrice float64
	ExecutionQty   int64
	OrderTime      string
	OrderStatus    string
	ExchangeCode   string
	ExchangeText   string
}

OrderExecution is a typed row from ka10076.

type PlaceStockOrderRequest

type PlaceStockOrderRequest struct {
	Side           StockOrderSide
	Exchange       string
	Symbol         string
	Quantity       int64
	OrderPrice     string
	TradeType      string
	ConditionPrice string
}

PlaceStockOrderRequest is input for kt10000/kt10001.

type StockOrderSide

type StockOrderSide string

StockOrderSide indicates buy/sell for order placement.

const (
	StockOrderSideBuy  StockOrderSide = "buy"
	StockOrderSideSell StockOrderSide = "sell"
)

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.

func GetTokenManager

func GetTokenManager() TokenManager

GetTokenManager returns the global token manager.

type TokenResponse

type TokenResponse struct {
	ExpiresDT  string      `json:"expires_dt"`
	TokenType  string      `json:"token_type"`
	Token      string      `json:"token"`
	ReturnCode interface{} `json:"return_code"`
	ReturnMsg  string      `json:"return_msg"`
}

TokenResponse is Kiwoom OAuth token response.

type UnsettledOrder

type UnsettledOrder struct {
	OrderNumber    string
	StockCode      string
	OrderStatus    string
	OrderQty       int64
	UnsettledQty   int64
	OrderPrice     float64
	ConcludedPrice float64
	OrderSideText  string
	ExchangeCode   string
	ExchangeText   string
	ReturnMsg      string
	ReturnCode     int
}

UnsettledOrder is a typed row from ka10075.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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