Documentation
¶
Overview ¶
Package brmarket fetches B3 (the Brazilian stock exchange) market-index composition over HTTP.
The entry point is GetSharesForIndex, which returns the constituents and theoretical weights of a B3 index such as IBOV. GetSharesForIndexContext is the context-aware variant. Supported indexes are the IndexType constants (IBOV, IBXX, ... BDRX); use ParseIndexType to turn a symbol string into an IndexType, or IndexType.String to go the other way.
Every fetch performs a live HTTP request against B3's public IndexComposition endpoint, so it requires network access and may fail with network, status, or decoding errors. Errors are wrapped and can be matched with errors.Is against ErrIndexNotFound, ErrUnexpectedStatus, and ErrUnexpectedResponse.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrIndexNotFound is returned when a symbol does not match a supported B3 index. ErrIndexNotFound = errors.New("brmarket: index not found") // ErrUnexpectedStatus is returned when B3 responds with a non-200 HTTP status. ErrUnexpectedStatus = errors.New("brmarket: unexpected HTTP status") // ErrUnexpectedResponse is returned when B3 responds 200 but the body is not a // recognizable index composition (for example a WAF/HTML page or an error // envelope that decodes into an empty result). ErrUnexpectedResponse = errors.New("brmarket: unexpected response body") )
Sentinel errors returned by this package. Match them with errors.Is.
Functions ¶
This section is empty.
Types ¶
type B3IndexInfo ¶
type B3IndexInfo struct {
BizSts BizStatus `json:"BizSts"`
Index IndexMeta `json:"Index"`
UnderlyingList []Constituent `json:"UnderlyingList"`
Msg Message `json:"Msg"`
}
B3IndexInfo is the index-composition payload returned by B3.
func GetSharesForIndex ¶
func GetSharesForIndex(index string) (B3IndexInfo, error)
GetSharesForIndex returns the B3 index composition for the given index symbol (for example "IBOV", or brmarket.IBOV.String()). Only Brazilian indexes are supported; an unsupported symbol yields ErrIndexNotFound.
It performs a live HTTP request with a default timeout. Use GetSharesForIndexContext when you need to control cancellation or deadlines.
func GetSharesForIndexContext ¶
func GetSharesForIndexContext(ctx context.Context, index string) (B3IndexInfo, error)
GetSharesForIndexContext is like GetSharesForIndex but honors the provided context for cancellation and deadlines.
type BizStatus ¶
type BizStatus struct {
Cd string `json:"cd"`
}
BizStatus carries B3's business-status code for the response.
type Constituent ¶
type Constituent struct {
IndexTheoreticalQty float64 `json:"indexTheoreticalQty"`
IndxCmpnPctg float64 `json:"indxCmpnPctg"`
Symb string `json:"symb"`
Desc string `json:"desc"`
}
Constituent is a single security that makes up an index, with its theoretical quantity and percentage weight.
type IndexType ¶
type IndexType int
IndexType identifies a B3 (the Brazilian stock exchange) market index.
const ( IBOV IndexType = iota IBXX IBXL IBRA IGCX ITAG IGNM IGCT IDIV MLCX IVBX ICO2 ISEE ICON IEEX IFNC IMOB INDX IMAT UTIL IFIX BDRX // Added in v2.1.0. When you add a constant here, add a matching entry to // indexNames below; the round-trip test enforces they stay in sync. SMLL IFIL GPTW IDVR IBLV IBSD IBHB )
The B3 indexes this package can fetch. The zero value is IBOV.
func IndexFromString
deprecated
func ParseIndexType ¶
ParseIndexType returns the IndexType for a B3 symbol such as "IBOV". It returns ErrIndexNotFound (wrapped) if the symbol is not a supported index.
func (IndexType) String ¶
String returns the B3 symbol for the index, e.g. "IBOV". It never panics: values outside the known range render as "IndexType(<n>)", matching the convention used by stringer-generated code (fmt may call String implicitly).
Example ¶
package main
import (
"fmt"
"github.com/cesarvspr/brmarket/v2"
)
func main() {
fmt.Println(brmarket.IBOV)
fmt.Println(brmarket.BDRX)
}
Output: IBOV BDRX