Help us shape the future of Go! Take the 2026 Go Developer Survey

toss

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathOAuthToken       = "/oauth2/token" //nolint:gosec // G101: URL path constant, not a credential
	PathAccounts         = "/api/v1/accounts"
	PathPrices           = "/api/v1/prices"
	PathCandles          = "/api/v1/candles"
	PathStocks           = "/api/v1/stocks"
	PathHoldings         = "/api/v1/holdings"
	PathOrders           = "/api/v1/orders"
	PathBuyingPower      = "/api/v1/buying-power"
	PathSellableQuantity = "/api/v1/sellable-quantity"
	PathCommissions      = "/api/v1/commissions"
)
View Source
const (
	// BaseURLReal is the Toss Securities production Open API domain.
	BaseURLReal = "https://openapi.tossinvest.com"
)

Variables

This section is empty.

Functions

func GetTokenManager

func GetTokenManager() tokencache.Manager

GetTokenManager returns the package-global token manager.

func RateLimitGroup

func RateLimitGroup(method, path string) string

RateLimitGroup returns the Toss rate-limit group for a documented operation.

Types

type Account

type Account struct {
	AccountNo   string `json:"accountNo"`
	AccountSeq  int64  `json:"accountSeq"`
	AccountType string `json:"accountType"`
}

type BuyingPowerResponse

type BuyingPowerResponse struct {
	Currency        string `json:"currency"`
	CashBuyingPower string `json:"cashBuyingPower"`
}

type Candle

type Candle struct {
	Timestamp  string `json:"timestamp"`
	OpenPrice  string `json:"openPrice"`
	HighPrice  string `json:"highPrice"`
	LowPrice   string `json:"lowPrice"`
	ClosePrice string `json:"closePrice"`
	Volume     string `json:"volume"`
	Currency   string `json:"currency"`
}

type CandlePageResponse

type CandlePageResponse struct {
	Candles    []Candle `json:"candles"`
	NextBefore *string  `json:"nextBefore"`
}

type Client

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

Client is a Toss Securities Open API REST client.

func NewClientWithTokenManager

func NewClientWithTokenManager(sandbox bool, tm tokencache.Manager) *Client

NewClientWithTokenManager creates a Toss Open API client.

func (*Client) Authenticate

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

Authenticate issues or reuses a Toss OAuth token.

func (*Client) CallEndpoint

func (c *Client) CallEndpoint(ctx context.Context, method, path, accountSeq string, query map[string]any, body any) (map[string]any, error)

CallEndpoint executes a Toss endpoint and decodes the response as an untyped object.

func (*Client) CancelOrder

func (c *Client) CancelOrder(ctx context.Context, accountSeq, orderID string) (OrderOperationResponse, error)

func (*Client) CreateOrder

func (c *Client) CreateOrder(ctx context.Context, accountSeq string, body map[string]any) (OrderResponse, error)

func (*Client) GetAccounts

func (c *Client) GetAccounts(ctx context.Context) ([]Account, error)

func (*Client) GetBuyingPower

func (c *Client) GetBuyingPower(ctx context.Context, accountSeq, currency string) (BuyingPowerResponse, error)

func (*Client) GetCandles

func (c *Client) GetCandles(ctx context.Context, symbol, interval string, count int, before string, adjusted bool) (CandlePageResponse, error)

func (*Client) GetCommissions

func (c *Client) GetCommissions(ctx context.Context, accountSeq string) ([]Commission, error)

func (*Client) GetHoldings

func (c *Client) GetHoldings(ctx context.Context, accountSeq, symbol string) (HoldingsOverview, error)

func (*Client) GetOrder

func (c *Client) GetOrder(ctx context.Context, accountSeq, orderID string) (Order, error)

func (*Client) GetOrders

func (c *Client) GetOrders(ctx context.Context, accountSeq string, query map[string]any) (PaginatedOrderResponse, error)

func (*Client) GetPrices

func (c *Client) GetPrices(ctx context.Context, symbols ...string) ([]PriceResponse, error)

func (*Client) GetSellableQuantity

func (c *Client) GetSellableQuantity(ctx context.Context, accountSeq, symbol string) (SellableQuantityResponse, error)

func (*Client) GetStocks

func (c *Client) GetStocks(ctx context.Context, symbols ...string) ([]StockInfo, error)

func (*Client) ModifyOrder

func (c *Client) ModifyOrder(ctx context.Context, accountSeq, orderID string, body map[string]any) (OrderOperationResponse, error)

func (*Client) Name

func (c *Client) Name() string

Name returns broker 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 Toss client credentials for token refresh.

func (*Client) SetLogger

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

SetLogger sets the client logger.

type Commission

type Commission struct {
	MarketCountry  string  `json:"marketCountry"`
	CommissionRate string  `json:"commissionRate"`
	StartDate      *string `json:"startDate"`
	EndDate        *string `json:"endDate"`
}

type Cost

type Cost struct {
	Commission *string `json:"commission"`
	Tax        *string `json:"tax"`
}

type DailyProfitLoss

type DailyProfitLoss struct {
	Amount string `json:"amount"`
	Rate   string `json:"rate"`
}

type FileTokenManager

type FileTokenManager struct {
	*filetoken.Manager
}

FileTokenManager stores Toss 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 HoldingMarketValue

type HoldingMarketValue struct {
	PurchaseAmount  string `json:"purchaseAmount"`
	Amount          string `json:"amount"`
	AmountAfterCost string `json:"amountAfterCost"`
}

type HoldingProfitLoss

type HoldingProfitLoss struct {
	Amount          string `json:"amount"`
	AmountAfterCost string `json:"amountAfterCost"`
	Rate            string `json:"rate"`
	RateAfterCost   string `json:"rateAfterCost"`
}

type HoldingsItem

type HoldingsItem struct {
	Symbol               string             `json:"symbol"`
	Name                 string             `json:"name"`
	MarketCountry        string             `json:"marketCountry"`
	Currency             string             `json:"currency"`
	Quantity             string             `json:"quantity"`
	LastPrice            string             `json:"lastPrice"`
	AveragePurchasePrice string             `json:"averagePurchasePrice"`
	MarketValue          HoldingMarketValue `json:"marketValue"`
	ProfitLoss           HoldingProfitLoss  `json:"profitLoss"`
	DailyProfitLoss      DailyProfitLoss    `json:"dailyProfitLoss"`
	Cost                 Cost               `json:"cost"`
}

type HoldingsOverview

type HoldingsOverview struct {
	TotalPurchaseAmount MultiCurrencyAmount     `json:"totalPurchaseAmount"`
	MarketValue         OverviewMarketValue     `json:"marketValue"`
	ProfitLoss          OverviewProfitLoss      `json:"profitLoss"`
	DailyProfitLoss     OverviewDailyProfitLoss `json:"dailyProfitLoss"`
	Items               []HoldingsItem          `json:"items"`
}

type KrMarketDetail

type KrMarketDetail struct {
	LiquidationTrading  bool  `json:"liquidationTrading"`
	NXTSupported        bool  `json:"nxtSupported"`
	KRXTradingSuspended bool  `json:"krxTradingSuspended"`
	NXTTradingSuspended *bool `json:"nxtTradingSuspended"`
}

type MultiCurrencyAmount

type MultiCurrencyAmount struct {
	KRW string  `json:"krw"`
	USD *string `json:"usd"`
}

type Order

type Order struct {
	OrderID     string         `json:"orderId"`
	Symbol      string         `json:"symbol"`
	Side        string         `json:"side"`
	OrderType   string         `json:"orderType"`
	TimeInForce string         `json:"timeInForce"`
	Status      string         `json:"status"`
	Price       *string        `json:"price"`
	Quantity    string         `json:"quantity"`
	OrderAmount *string        `json:"orderAmount"`
	Currency    string         `json:"currency"`
	OrderedAt   string         `json:"orderedAt"`
	CanceledAt  *string        `json:"canceledAt"`
	Execution   OrderExecution `json:"execution"`
}

type OrderExecution

type OrderExecution struct {
	FilledQuantity     string  `json:"filledQuantity"`
	AverageFilledPrice *string `json:"averageFilledPrice"`
	FilledAmount       *string `json:"filledAmount"`
	Commission         *string `json:"commission"`
	Tax                *string `json:"tax"`
	FilledAt           *string `json:"filledAt"`
	SettlementDate     *string `json:"settlementDate"`
}

type OrderOperationResponse

type OrderOperationResponse struct {
	OrderID string `json:"orderId"`
}

type OrderResponse

type OrderResponse struct {
	OrderID       string  `json:"orderId"`
	ClientOrderID *string `json:"clientOrderId"`
}

type OverviewDailyProfitLoss

type OverviewDailyProfitLoss struct {
	Amount MultiCurrencyAmount `json:"amount"`
	Rate   string              `json:"rate"`
}

type OverviewMarketValue

type OverviewMarketValue struct {
	Amount          MultiCurrencyAmount `json:"amount"`
	AmountAfterCost MultiCurrencyAmount `json:"amountAfterCost"`
}

type OverviewProfitLoss

type OverviewProfitLoss struct {
	Amount          MultiCurrencyAmount `json:"amount"`
	AmountAfterCost MultiCurrencyAmount `json:"amountAfterCost"`
	Rate            string              `json:"rate"`
	RateAfterCost   string              `json:"rateAfterCost"`
}

type PaginatedOrderResponse

type PaginatedOrderResponse struct {
	Orders     []Order `json:"orders"`
	NextCursor *string `json:"nextCursor"`
	HasNext    bool    `json:"hasNext"`
}

type PriceResponse

type PriceResponse struct {
	Symbol    string  `json:"symbol"`
	Timestamp *string `json:"timestamp"`
	LastPrice string  `json:"lastPrice"`
	Currency  string  `json:"currency"`
}

type SellableQuantityResponse

type SellableQuantityResponse struct {
	SellableQuantity string `json:"sellableQuantity"`
}

type StockInfo

type StockInfo struct {
	Symbol             string          `json:"symbol"`
	Name               string          `json:"name"`
	EnglishName        string          `json:"englishName"`
	ISINCode           string          `json:"isinCode"`
	Market             string          `json:"market"`
	SecurityType       string          `json:"securityType"`
	IsCommonShare      bool            `json:"isCommonShare"`
	Status             string          `json:"status"`
	Currency           string          `json:"currency"`
	ListDate           *string         `json:"listDate"`
	DelistDate         *string         `json:"delistDate"`
	SharesOutstanding  string          `json:"sharesOutstanding"`
	LeverageFactor     *string         `json:"leverageFactor"`
	KoreanMarketDetail *KrMarketDetail `json:"koreanMarketDetail"`
}

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int64  `json:"expires_in"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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