Documentation
¶
Index ¶
- Constants
- func GetTokenManager() tokencache.Manager
- func OverseasRealtimeKey(exchange, symbol string) (string, error)
- type Client
- func (c *Client) Authenticate(ctx context.Context, creds broker.Credentials) (*broker.Token, error)
- func (c *Client) BuildOverseasTradeSubscriptions(ctx context.Context, nation, exchangeGroup string, maxRows int) ([]RealtimeSubscription, error)
- func (c *Client) BuildTradeSubscriptions(ctx context.Context) ([]RealtimeSubscription, error)
- func (c *Client) CallEndpoint(ctx context.Context, method, path, trCD string, request interface{}) (map[string]interface{}, error)
- func (c *Client) ConnectRealtime(ctx context.Context) (*RealtimeConn, error)
- func (c *Client) InquireBalance(ctx context.Context) (map[string]interface{}, []map[string]interface{}, error)
- func (c *Client) InquireChart(ctx context.Context, symbol, interval string, from, to time.Time, limit int) ([]map[string]interface{}, error)
- func (c *Client) InquireOverseasChart(ctx context.Context, symbol, exchange, interval string, from, to time.Time, ...) ([]map[string]interface{}, error)
- func (c *Client) InquireOverseasInstrument(ctx context.Context, symbol, exchange string) (map[string]interface{}, error)
- func (c *Client) InquireOverseasPrice(ctx context.Context, symbol, exchange string) (map[string]interface{}, error)
- func (c *Client) InquirePrice(ctx context.Context, symbol, exchange string) (map[string]interface{}, error)
- func (c *Client) ListOverseasStockMaster(ctx context.Context, nation, exchangeGroup string, maxRows int) ([]OverseasStockMaster, error)
- func (c *Client) ListStockMaster(ctx context.Context, gubun string) ([]StockMaster, error)
- func (c *Client) Name() string
- func (c *Client) SetBaseURL(baseURL string)
- func (c *Client) SetCredentials(appKey, appSecret string)
- func (c *Client) SetLogger(l *slog.Logger)
- func (c *Client) SetMACAddress(macAddress string)
- func (c *Client) SetWebSocketURL(wsURL string)
- type FileTokenManager
- type OverseasStockMaster
- type RealtimeConn
- func (r *RealtimeConn) Close() error
- func (r *RealtimeConn) Read(ctx context.Context) (*RealtimeMessage, error)
- func (r *RealtimeConn) Subscribe(ctx context.Context, trCD, trKey string) error
- func (r *RealtimeConn) SubscribeMany(ctx context.Context, subs []RealtimeSubscription) error
- func (r *RealtimeConn) Unsubscribe(ctx context.Context, trCD, trKey string) error
- type RealtimeMessage
- type RealtimeSubscription
- type StockMaster
Constants ¶
const ( // BaseURLReal is the LS Securities production REST domain. BaseURLReal = "https://openapi.ls-sec.co.kr:8080" // BaseURLSandbox is the LS Securities mock REST domain. LS currently uses // the same REST host and routes mock access by the issued app key. BaseURLSandbox = "https://openapi.ls-sec.co.kr:8080" // WebSocketURLReal is the LS Securities production realtime endpoint. WebSocketURLReal = "wss://openapi.ls-sec.co.kr:9443/websocket" // WebSocketURLSandbox is the LS Securities mock realtime endpoint. WebSocketURLSandbox = "wss://openapi.ls-sec.co.kr:29443/websocket" )
const ( PathOAuthToken = "/oauth2/token" PathStockMarket = "/stock/market-data" PathStockChart = "/stock/chart" PathStockAccount = "/stock/accno" PathStockOrder = "/stock/order" PathStockMisc = "/stock/etc" PathStockItemSearch = "/stock/item-search" PathStockInvestInfo = "/stock/investinfo" PathOverseasStockMarket = "/overseas-stock/market-data" PathOverseasStockChart = "/overseas-stock/chart" )
const ( TRStockQuote = "t1102" TRStockChart = "t8410" TRStockBalance = "t0424" TRStockOrder = "CSPAT00601" TRStockMaster = "t8436" TRForeignIndexHistory = "t3518" TRForeignIndexQuote = "t3521" TRRealtimeKOSPI = "S3_" TRRealtimeKOSDAQ = "K3_" TRRealtimeUnified = "US3" TRRealtimeNXT = "NS3" TROverseasStockQuote = "g3101" TROverseasStockInstrument = "g3104" TROverseasStockMaster = "g3190" TROverseasStockChart = "g3204" TRRealtimeOverseasTrade = "GSC" TRRealtimeOverseasQuote = "GSH" )
Variables ¶
This section is empty.
Functions ¶
func GetTokenManager ¶
func GetTokenManager() tokencache.Manager
GetTokenManager returns the package-global token manager.
func OverseasRealtimeKey ¶
OverseasRealtimeKey returns the fixed-width realtime key used by GSC/GSH.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an LS Securities OpenAPI REST/WebSocket client.
func NewClientWithTokenManager ¶
func NewClientWithTokenManager(sandbox bool, tm tokencache.Manager) *Client
NewClientWithTokenManager creates an LS OpenAPI client.
func (*Client) Authenticate ¶
Authenticate issues or reuses an LS OAuth token.
func (*Client) BuildOverseasTradeSubscriptions ¶
func (c *Client) BuildOverseasTradeSubscriptions(ctx context.Context, nation, exchangeGroup string, maxRows int) ([]RealtimeSubscription, error)
BuildOverseasTradeSubscriptions builds GSC subscriptions from g3190 overseas master rows.
func (*Client) BuildTradeSubscriptions ¶
func (c *Client) BuildTradeSubscriptions(ctx context.Context) ([]RealtimeSubscription, error)
BuildTradeSubscriptions builds S3_/K3_ subscriptions from t8436 stock master rows.
func (*Client) CallEndpoint ¶
func (c *Client) CallEndpoint(ctx context.Context, method, path, trCD string, request interface{}) (map[string]interface{}, error)
CallEndpoint executes an LS REST endpoint using a TR code and raw request body.
func (*Client) ConnectRealtime ¶
func (c *Client) ConnectRealtime(ctx context.Context) (*RealtimeConn, error)
ConnectRealtime opens a WebSocket connection to LS realtime.
func (*Client) InquireBalance ¶
func (c *Client) InquireBalance(ctx context.Context) (map[string]interface{}, []map[string]interface{}, error)
InquireBalance fetches t0424 account summary and position rows.
func (*Client) InquireChart ¶
func (c *Client) InquireChart(ctx context.Context, symbol, interval string, from, to time.Time, limit int) ([]map[string]interface{}, error)
InquireChart fetches t8410 day/week/month chart rows.
func (*Client) InquireOverseasChart ¶
func (c *Client) InquireOverseasChart(ctx context.Context, symbol, exchange, interval string, from, to time.Time, limit int) ([]map[string]interface{}, error)
InquireOverseasChart fetches g3204 day/week/month/year chart rows.
func (*Client) InquireOverseasInstrument ¶
func (c *Client) InquireOverseasInstrument(ctx context.Context, symbol, exchange string) (map[string]interface{}, error)
InquireOverseasInstrument returns raw g3104 response fields for an overseas stock.
func (*Client) InquireOverseasPrice ¶
func (c *Client) InquireOverseasPrice(ctx context.Context, symbol, exchange string) (map[string]interface{}, error)
InquireOverseasPrice returns raw g3101 response fields for an overseas stock.
func (*Client) InquirePrice ¶
func (c *Client) InquirePrice(ctx context.Context, symbol, exchange string) (map[string]interface{}, error)
InquirePrice returns raw t1102 response fields for a stock.
func (*Client) ListOverseasStockMaster ¶
func (c *Client) ListOverseasStockMaster(ctx context.Context, nation, exchangeGroup string, maxRows int) ([]OverseasStockMaster, error)
ListOverseasStockMaster fetches LS overseas stock master rows with g3190.
func (*Client) ListStockMaster ¶
ListStockMaster fetches LS stock master rows with t8436.
func (*Client) SetBaseURL ¶
SetBaseURL overrides the REST base URL. Tests use this for httptest servers.
func (*Client) SetCredentials ¶
SetCredentials stores LS app credentials for token refresh.
func (*Client) SetMACAddress ¶
SetMACAddress sets the optional mac_address header required for LS corporate accounts.
func (*Client) SetWebSocketURL ¶
SetWebSocketURL overrides the realtime WebSocket endpoint.
type FileTokenManager ¶
FileTokenManager stores LS OAuth 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.
type OverseasStockMaster ¶
type OverseasStockMaster struct {
KeySymbol string
Nation string
Exchange string
Symbol string
ISIN string
Name string
NameEn string
Currency string
Suspended bool
}
OverseasStockMaster is one g3190 overseas stock master row.
type RealtimeConn ¶
type RealtimeConn struct {
// contains filtered or unexported fields
}
RealtimeConn is an active LS realtime WebSocket connection.
func (*RealtimeConn) Close ¶
func (r *RealtimeConn) Close() error
Close closes the realtime WebSocket connection.
func (*RealtimeConn) Read ¶
func (r *RealtimeConn) Read(ctx context.Context) (*RealtimeMessage, error)
Read receives and decodes one realtime message.
func (*RealtimeConn) Subscribe ¶
func (r *RealtimeConn) Subscribe(ctx context.Context, trCD, trKey string) error
Subscribe registers one realtime TR/key pair.
func (*RealtimeConn) SubscribeMany ¶
func (r *RealtimeConn) SubscribeMany(ctx context.Context, subs []RealtimeSubscription) error
SubscribeMany registers multiple realtime TR/key pairs in order.
func (*RealtimeConn) Unsubscribe ¶
func (r *RealtimeConn) Unsubscribe(ctx context.Context, trCD, trKey string) error
Unsubscribe removes one realtime TR/key pair.
type RealtimeMessage ¶
type RealtimeMessage struct {
Header map[string]interface{} `json:"header,omitempty"`
Body map[string]interface{} `json:"body,omitempty"`
}
RealtimeMessage is one decoded LS WebSocket message.
type RealtimeSubscription ¶
RealtimeSubscription identifies one LS realtime registration request.