Documentation
¶
Index ¶
- Constants
- func SetGlobalTokenManager(tm TokenManager)
- type AccountBalance
- type AccountPosition
- type CancelStockOrderRequest
- type ChartCandle
- type Client
- func (c *Client) Authenticate(ctx context.Context, creds broker.Credentials) (*broker.Token, error)
- func (c *Client) CancelStockOrder(ctx context.Context, req CancelStockOrderRequest) (*OrderAck, error)
- func (c *Client) InquireBalance(ctx context.Context, exchange string) (*AccountBalance, error)
- func (c *Client) InquireDailyPrice(ctx context.Context, symbol, baseDate string) ([]ChartCandle, error)
- func (c *Client) InquireInstrumentInfo(ctx context.Context, symbol string) (*InstrumentInfo, error)
- func (c *Client) InquireMonthlyPrice(ctx context.Context, symbol, baseDate string) ([]ChartCandle, error)
- func (c *Client) InquireOrderExecutions(ctx context.Context, symbol string) ([]OrderExecution, error)
- func (c *Client) InquirePositions(ctx context.Context, queryType, exchange string) ([]AccountPosition, error)
- func (c *Client) InquirePrice(ctx context.Context, symbol string) (*DomesticQuote, error)
- func (c *Client) InquireUnsettledOrders(ctx context.Context, symbol string) ([]UnsettledOrder, error)
- func (c *Client) InquireWeeklyPrice(ctx context.Context, symbol, baseDate string) ([]ChartCandle, error)
- func (c *Client) ModifyStockOrder(ctx context.Context, req ModifyStockOrderRequest) (*OrderAck, error)
- func (c *Client) Name() string
- func (c *Client) PlaceStockOrder(ctx context.Context, req PlaceStockOrderRequest) (*OrderAck, error)
- func (c *Client) SetBaseURL(baseURL string)
- func (c *Client) SetCredentials(appKey, appSecret string)
- type DomesticQuote
- type FileTokenManager
- type InstrumentInfo
- type ModifyStockOrderRequest
- type OrderAck
- type OrderExecution
- type PlaceStockOrderRequest
- type RateLimiter
- type StockOrderSide
- type TokenManager
- type TokenResponse
- type UnsettledOrder
Constants ¶
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 NewClientWithTokenManager ¶
func NewClientWithTokenManager(sandbox bool, tm TokenManager) *Client
NewClientWithTokenManager creates a client with injected token manager.
func (*Client) Authenticate ¶
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 ¶
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 ¶
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 ¶
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) PlaceStockOrder ¶
func (c *Client) PlaceStockOrder(ctx context.Context, req PlaceStockOrderRequest) (*OrderAck, error)
PlaceStockOrder places kt10000 (buy) or kt10001 (sell).
func (*Client) SetBaseURL ¶
SetBaseURL overrides the API base URL. Primarily useful for tests or private/proxy deployments.
func (*Client) SetCredentials ¶
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) 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 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.
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.