kiwoom

package
v0.4.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: 16 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"
)

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) 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) InquireDailyPrice

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

InquireDailyPrice fetches daily candles from ka10081.

func (*Client) InquireInstrumentInfo

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

InquireInstrumentInfo fetches ka10100.

func (*Client) InquireMonthlyPrice

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

InquireMonthlyPrice fetches monthly candles from ka10083.

func (*Client) InquireOrderExecutions

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

InquireOrderExecutions fetches ka10076.

func (*Client) InquirePositions

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

InquirePositions fetches kt00018.

func (*Client) InquirePrice

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

InquirePrice fetches ka10001 and returns typed quote fields.

func (*Client) InquireUnsettledOrders

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

InquireUnsettledOrders fetches ka10075.

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 RateLimiter

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

RateLimiter implements a token-bucket rate limiter.

func NewRateLimiter

func NewRateLimiter(maxPerSecond float64) *RateLimiter

NewRateLimiter creates a new limiter with maxPerSecond throughput.

func (*RateLimiter) Wait

func (rl *RateLimiter) Wait()

Wait blocks until one token is available.

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