ls

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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"
)
View Source
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

func OverseasRealtimeKey(exchange, symbol string) (string, error)

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

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

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

func (c *Client) ListStockMaster(ctx context.Context, gubun string) ([]StockMaster, error)

ListStockMaster fetches LS stock master rows with t8436.

func (*Client) Name

func (c *Client) Name() string

Name returns the broker display name.

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string)

SetBaseURL overrides the REST base URL. Tests use this for httptest servers.

func (*Client) SetCredentials

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

SetCredentials stores LS app credentials for token refresh.

func (*Client) SetLogger

func (c *Client) SetLogger(l *slog.Logger)

SetLogger sets the client logger.

func (*Client) SetMACAddress

func (c *Client) SetMACAddress(macAddress string)

SetMACAddress sets the optional mac_address header required for LS corporate accounts.

func (*Client) SetWebSocketURL

func (c *Client) SetWebSocketURL(wsURL string)

SetWebSocketURL overrides the realtime WebSocket endpoint.

type FileTokenManager

type FileTokenManager struct {
	*filetoken.Manager
}

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

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

type RealtimeSubscription struct {
	TRCode string
	TRKey  string
}

RealtimeSubscription identifies one LS realtime registration request.

type StockMaster

type StockMaster struct {
	Name       string
	Symbol     string
	MarketCode string
	ETFType    string
	UpperLimit float64
	LowerLimit float64
	PrevClose  float64
}

StockMaster is one t8436 stock master row.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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