bdstockexchange

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

bdstockexchange

A Go library to fetch latest stock prices from Dhaka and Chittagong Stock Exchange (DSE & CSE).

Build Status Coverage Status Go Report Card License PkgGoDev

Import

import "github.com/diptomondal007/bdstockexchange"

Install

go get -u github.com/diptomondal007/bdstockexchange

Usage

const (
	// ASC constant to sort result array in ascending order
	ASC sortOrder = iota
	// DESC constant to sort result array in descending order
	DESC
)
const (
	// SortByTradingCode to sort the result by Company's Trade code
	SortByTradingCode sortBy = iota
	// SortByLTP to sort the result by the Last Trade Price
	SortByLTP
	// SortByOpeningPrice to sort the result by the Opening Price of that day
	SortByOpeningPrice
	// SortByHighPrice to sort the result by the Highest Price of the day
	SortByHighPrice
	// SortByLowPrice to sort the result by Lowest price of the day
	SortByLowPrice
	// SortByYCP to sort the result by Yesterday's Closing Price
	SortByYCP
	// SortByNumberOfTrades to sort the result by The Number of shares are traded on that day
	SortByNumberOfTrades
	// SortByValue to sort the result by the Value of the Company. The Value is in Million BDT.
	SortByValue
	// SortByVolumeOfShare to sort the result by the Number of shares of the company
	SortByVolumeOfShare
	// SortByPercentageChange ...
	SortByPercentageChange
	// SortByPriceChange to sort the result by the Change of Price of the Share
	SortByPriceChange
)
type CSE
type CSE struct {
}

CSE is a struct to access cse related methods

func NewCSE
func NewCSE() *CSE

NewCSE returns new CSE object

func (*CSE) GetAllListedCompanies
func (c *CSE) GetAllListedCompanies() ([]*Company, error)

GetAllListedCompanies returns all the companies listed in cse or error in case of any error

func (*CSE) GetAllListedCompaniesByCategory
func (c *CSE) GetAllListedCompaniesByCategory() ([]*CompanyListingByCategory, error)

GetAllListedCompaniesByCategory returns the listing of the companies by their category or an error in case of any error

func (*CSE) GetAllListedCompaniesByIndustry
func (c *CSE) GetAllListedCompaniesByIndustry() ([]*CompanyListingByIndustry, error)

GetAllListedCompaniesByIndustry returns list of companies with their industry type or error in case of any error

func (*CSE) GetAllWeeklyReports
func (c *CSE) GetAllWeeklyReports(year int) (*WeeklyReports, error)

GetAllWeeklyReports returns weekly reports pdf link for the input Year. the Year should be between current Year and 2018

func (*CSE) GetLatestPrices
func (c *CSE) GetLatestPrices(by sortBy, order sortOrder) ([]*CSEShare, error)

GetLatestPrices returns the array of latest share prices or error in case of any error It takes by which field the array should be sorted ex: SortByTradingCode and sort order ex: ASC It will return an error for if user tries to sort with a non existing file in the CSEShare model or invalid category name or invalid sort order

func (*CSE) GetMarketStatus
func (d *CSE) GetMarketStatus() (*CseMarketStatus, error)

GetMarketStatus returns the CseMarketStatus with is open/close

func (*CSE) GetMarketSummary
func (c *CSE) GetMarketSummary() (*Summary, error)

GetMarketSummary returns the summary with highest records till now and the historical market summary data

func (*CSE) GetPriceEarningRatio
func (c *CSE) GetPriceEarningRatio(day, month, year string) (*PriceEarningRatios, error)

GetPriceEarningRatio returns the price earning ratio data for listed companies as per input date. It takes day, month and Year as input ex : (03, 07, 2020) where 03 is the day and 07 is the month and 2020 is the Year. Don't forget to include 0 before single digit day or month

type CSEShare
type CSEShare struct {
	SL          int
	TradingCode string
	LTP         float64
	Open        float64
	High        float64
	Low         float64
	YCP         float64
	Trade       int64
	ValueInMN   float64
	Volume      int64
}

CSEShare is a model for a single company's latest price data provided by the cse website

type Company
type Company struct {
	CompanyName string
	TradingCode string
}
type CompanyListingByCategory
type CompanyListingByCategory struct {
	Category string
	List     []*Company
}
type CompanyListingByIndustry
type CompanyListingByIndustry struct {
	IndustryType string
	List         []*Company
}
type CseMarketStatus
type CseMarketStatus struct {
	IsOpen bool
}

CseMarketStatus holds the data for if market is open/close

type DSE
type DSE struct {
}

DSE is a struct to access dse related methods

func NewDSE
func NewDSE() *DSE

NewDSE returns new DSE object

func (*DSE) GetLatestPrices
func (d *DSE) GetLatestPrices(by sortBy, order sortOrder) ([]*DSEShare, error)

GetLatestPrices returns the array of latest share prices or error in case of any error It takes by which field the array should be sorted ex: SortByTradingCode and sort order ex: ASC It will return an error for if user tries to sort with a non existing file in the DSEShare model or invalid category name or invalid sort order

func (*DSE) GetLatestPricesByCategory
func (d *DSE) GetLatestPricesByCategory(categoryName string, by sortBy, order sortOrder) ([]*DSEShare, error)

GetLatestPricesByCategory returns the array of latest share prices of the input category or error in case of any error It takes a category name, by which field the array should be sorted ex: SortByTradingCode and sort order ex: ASC It will return an error for if user tries to sort with a non existing file in the DSEShare model or invalid category name or invalid sort order

func (*DSE) GetLatestPricesSortedByPercentageChange
func (d *DSE) GetLatestPricesSortedByPercentageChange() ([]*LatestPricesWithPercentage, error)

GetLatestPricesSortedByPercentageChange ...

func (*DSE) GetMarketStatus
func (d *DSE) GetMarketStatus() (*DseMarketStatus, error)

GetMarketStatus returns the DseMarketStatus with is open/close and last market update date time

type DSEShare
type DSEShare struct {
	ID          int     `json:"id"`
	TradingCode string  `json:"trading_code"`
	LTP         float64 `json:"ltp"`
	High        float64 `json:"high"`
	Low         float64 `json:"low"`
	CloseP      float64 `json:"close_p"`
	YCP         float64 `json:"ycp"`
	Change      float64 `json:"change"`
	Trade       int64   `json:"trade"`
	ValueInMN   float64 `json:"value"`
	Volume      int64   `json:"volume"`
}

DSEShare is a model for a single company's latest price data provided by the dse website

type DseMarketStatus
type DseMarketStatus struct {
	IsOpen        bool
	LastUpdatedOn struct {
		Date string
		Time string
	}
}

DseMarketStatus holds the data for if market is open/close and when was last updated

type LatestPricesWithPercentage
type LatestPricesWithPercentage struct {
	ID               int     `json:"id"`
	TradingCode      string  `json:"trading_code"`
	LTP              float64 `json:"ltp"`
	High             float64 `json:"high"`
	Low              float64 `json:"low"`
	CloseP           float64 `json:"close_p"`
	YCP              float64 `json:"ycp"`
	PercentageChange float64 `json:"percentage_change"`
	Trade            int64   `json:"trade"`
	ValueInMN        float64 `json:"value"`
	Volume           int64   `json:"volume"`
}

LatestPricesWithPercentage ...

type PriceEarningRatio
type PriceEarningRatio struct {
	SL            string
	TradingCode   string
	FinancialYear struct {
		From string
		To   string
	}
	EPSAsPerUpdatedUnAuditedAccounts struct {
		Quarter1 float64
		HalfYear float64
		Quarter3 float64
	}
	AnnualizedEPS                     float64
	EPSBasedOnLastAuditedAccounts     float64
	ClosePrice                        float64
	PERatioBasedOnAnnualizedEPS       float64
	PERatioBasedOnLastAuditedAccounts float64
}

PriceEarningRatio holds the data for a price earning ratio in selected date

type PriceEarningRatios
type PriceEarningRatios struct {
	Date                   string
	PriceEarningRatioArray []*PriceEarningRatio
}
type Summary
type Summary struct {
	HighestRecords      []*record
	HistoricalSummaries []*market
}

Summary holds the historical market summaries array and the record trading or highest records data

type WeeklyReports
type WeeklyReports struct {
	Year    int
	Reports []*report
}

WeeklyReports holds the weekly reports for a Year

Example

GetLatestPrices
package main

import (
	"github.com/diptomondal007/bdstockexchange"
	"log"
)

func main(){
	dse := bdstockexchange.NewDSE()
	arr, err := dse.GetLatestPrices(bdstockexchange.SortByHighPrice, bdstockexchange.ASC)
	if err != nil{
		// Do something with the error
		log.Println(err)
	}
	log.Println(arr[0].TradingCode)
}
GetLatestPricesByCategory
package main

import (
	"github.com/diptomondal007/bdstockexchange"
	"log"
)

func main(){
	dse := bdstockexchange.NewDSE()
	arr, err := dse.GetLatestPricesByCategory("A" ,bdstockexchange.SortByHighPrice, bdstockexchange.ASC)
	if err != nil{
		// Do something with the error
		log.Println(err)
	}
	log.Println(arr[0].TradingCode)
}
GetMarketSummary
package main

import (
	"log"

	"github.com/diptomondal007/bdstockexchange"
)

func main() {
	dse := bdstockexchange.NewDSE()
	ms, err := dse.GetMarketSummary()
	if err != nil {
		log.Println(err)
	}

	log.Println(ms.DseX.DSEXIndex)
}

License

bdstockexchange is released under the Apache 2.0 license. See LICENSE.txt

Documentation

Index

Constants

View Source
const (
	// ASC constant to sort result array in ascending order
	ASC sortOrder = iota
	// DESC constant to sort result array in descending order
	DESC
)
View Source
const (
	// SortByTradingCode to sort the result by Company's Trade code
	SortByTradingCode sortBy = iota
	// SortByLTP to sort the result by the Last Trade Price
	SortByLTP
	// SortByOpeningPrice to sort the result by the Opening Price of that day
	SortByOpeningPrice
	// SortByHighPrice to sort the result by the Highest Price of the day
	SortByHighPrice
	// SortByLowPrice to sort the result by Lowest price of the day
	SortByLowPrice
	// SortByYCP to sort the result by Yesterday's Closing Price
	SortByYCP
	// SortByNumberOfTrades to sort the result by The Number of shares are traded on that day
	SortByNumberOfTrades
	// SortByValue to sort the result by the Value of the Company. The Value is in Million BDT.
	SortByValue
	// SortByVolumeOfShare to sort the result by the Number of shares of the company
	SortByVolumeOfShare
	// SortByPercentageChange ...
	SortByPercentageChange
	// SortByPriceChange to sort the result by the Change of Price of the Share
	SortByPriceChange
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CSE

type CSE struct {
}

CSE is a struct to access cse related methods

func NewCSE

func NewCSE() *CSE

NewCSE returns new CSE object

func (*CSE) GetAllListedCompanies

func (c *CSE) GetAllListedCompanies() ([]*Company, error)

GetAllListedCompanies returns all the companies listed in cse or error in case of any error

func (*CSE) GetAllListedCompaniesByCategory

func (c *CSE) GetAllListedCompaniesByCategory() ([]*CompanyListingByCategory, error)

GetAllListedCompaniesByCategory returns the listing of the companies by their category or an error in case of any error

func (*CSE) GetAllListedCompaniesByIndustry

func (c *CSE) GetAllListedCompaniesByIndustry() ([]*CompanyListingByIndustry, error)

GetAllListedCompaniesByIndustry returns list of companies with their industry type or error in case of any error

func (*CSE) GetAllWeeklyReports

func (c *CSE) GetAllWeeklyReports(year int) (*WeeklyReports, error)

GetAllWeeklyReports returns weekly reports pdf link for the input Year. the Year should be between current Year and 2018

func (*CSE) GetLatestPrices

func (c *CSE) GetLatestPrices(by sortBy, order sortOrder) ([]*CSEShare, error)

GetLatestPrices returns the array of latest share prices or error in case of any error It takes by which field the array should be sorted ex: SortByTradingCode and sort order ex: ASC It will return an error for if user tries to sort with a non existing file in the CSEShare model or invalid category name or invalid sort order

func (*CSE) GetMarketStatus

func (c *CSE) GetMarketStatus() (*CseMarketStatus, error)

GetMarketStatus returns the CseMarketStatus with is open/close

func (*CSE) GetMarketSummary

func (c *CSE) GetMarketSummary() (*Summary, error)

GetMarketSummary returns the summary with highest records till now and the historical market summary data

func (*CSE) GetPriceEarningRatio

func (c *CSE) GetPriceEarningRatio(day, month, year string) (*PriceEarningRatios, error)

GetPriceEarningRatio returns the price earning ratio data for listed companies as per input date. It takes day, month and Year as input ex : (03, 07, 2020) where 03 is the day and 07 is the month and 2020 is the Year. Don't forget to include 0 before single digit day or month

type CSEShare

type CSEShare struct {
	SL          int
	TradingCode string
	LTP         float64
	Open        float64
	High        float64
	Low         float64
	YCP         float64
	Trade       int64
	ValueInMN   float64
	Volume      int64
}

CSEShare is a model for a single company's latest price data provided by the cse website

type Company

type Company struct {
	CompanyName string
	TradingCode string
}

Company ...

type CompanyListingByCategory

type CompanyListingByCategory struct {
	Category string
	List     []*Company
}

CompanyListingByCategory ...

type CompanyListingByIndustry

type CompanyListingByIndustry struct {
	IndustryType string
	List         []*Company
}

CompanyListingByIndustry ...

type CseMarketStatus

type CseMarketStatus struct {
	IsOpen bool
}

CseMarketStatus holds the data for if market is open/close

type DSE

type DSE struct {
}

DSE is a struct to access dse related methods

func NewDSE

func NewDSE() *DSE

NewDSE returns new DSE object

func (*DSE) GetLatestPrices

func (d *DSE) GetLatestPrices(by sortBy, order sortOrder) ([]*DSEShare, error)

GetLatestPrices returns the array of latest share prices or error in case of any error It takes by which field the array should be sorted ex: SortByTradingCode and sort order ex: ASC It will return an error for if user tries to sort with a non existing file in the DSEShare model or invalid category name or invalid sort order

func (*DSE) GetLatestPricesByCategory

func (d *DSE) GetLatestPricesByCategory(categoryName string, by sortBy, order sortOrder) ([]*DSEShare, error)

GetLatestPricesByCategory returns the array of latest share prices of the input category or error in case of any error It takes a category name, by which field the array should be sorted ex: SortByTradingCode and sort order ex: ASC It will return an error for if user tries to sort with a non existing file in the DSEShare model or invalid category name or invalid sort order

func (*DSE) GetLatestPricesSortedByPercentageChange

func (d *DSE) GetLatestPricesSortedByPercentageChange() ([]*LatestPricesWithPercentage, error)

GetLatestPricesSortedByPercentageChange ...

func (*DSE) GetMarketStatus

func (d *DSE) GetMarketStatus() (*DseMarketStatus, error)

GetMarketStatus returns the DseMarketStatus with is open/close and last market update date time

func (*DSE) GetMarketSummary

func (d *DSE) GetMarketSummary() (*MarketSummary, error)

GetMarketSummary returns the last updated market summary data

type DSEShare

type DSEShare struct {
	ID          int     `json:"id"`
	TradingCode string  `json:"trading_code"`
	LTP         float64 `json:"ltp"`
	High        float64 `json:"high"`
	Low         float64 `json:"low"`
	CloseP      float64 `json:"close_p"`
	YCP         float64 `json:"ycp"`
	Change      float64 `json:"change"`
	Trade       int64   `json:"trade"`
	ValueInMN   float64 `json:"value"`
	Volume      int64   `json:"volume"`
}

DSEShare is a model for a single company's latest price data provided by the dse website

type DseMarketStatus

type DseMarketStatus struct {
	IsOpen        bool
	LastUpdatedOn struct {
		Date string
		Time string
	}
}

DseMarketStatus holds the data for if market is open/close and when was last updated

type LatestPricesWithPercentage

type LatestPricesWithPercentage struct {
	ID               int     `json:"id"`
	TradingCode      string  `json:"trading_code"`
	LTP              float64 `json:"ltp"`
	High             float64 `json:"high"`
	Low              float64 `json:"low"`
	CloseP           float64 `json:"close_p"`
	YCP              float64 `json:"ycp"`
	PercentageChange float64 `json:"percentage_change"`
	Trade            int64   `json:"trade"`
	ValueInMN        float64 `json:"value"`
	Volume           int64   `json:"volume"`
}

LatestPricesWithPercentage ...

type MarketSummary

type MarketSummary struct {
	LastUpdatedOn struct {
		Date string `json:"date"`
		Time string `json:"time"`
	} `json:"last_updated_on"`

	DseX struct {
		DSEXIndex                 float64 `json:"dsex_index"`
		DSEXIndexChange           float64 `json:"dsex_index_change"`
		DSEXIndexChangePercentage float64 `json:"dsex_index_change_percentage"`
	} `json:"dsex"`

	Ds30 struct {
		DS30Index                 float64 `json:"ds30_index"`
		DS30IndexChange           float64 `json:"ds30_index_change"`
		DS30IndexChangePercentage float64 `json:"ds30_index_change_percentage"`
	} `json:"ds30"`

	DseS struct {
		DSESIndex                 float64 `json:"dses_index"`
		DSESIndexChange           float64 `json:"dses_index_change"`
		DSESIndexChangePercentage float64 `json:"dses_index_change_percentage"`
	} `json:"dses"`

	TotalTrade     int64   `json:""`
	TotalValueInMN float64 `json:""`
	TotalVolume    int64   `json:""`

	IssuesAdvanced  int32 `json:""`
	IssuesDeclined  int32 `json:""`
	IssuesUnchanged int32 `json:""`
}

MarketSummary holds the data for market summary like DSEX index details and total trades and so on

type PriceEarningRatio

type PriceEarningRatio struct {
	SL            string
	TradingCode   string
	FinancialYear struct {
		From string
		To   string
	}
	EPSAsPerUpdatedUnAuditedAccounts struct {
		Quarter1 float64
		HalfYear float64
		Quarter3 float64
	}
	AnnualizedEPS                     float64
	EPSBasedOnLastAuditedAccounts     float64
	ClosePrice                        float64
	PERatioBasedOnAnnualizedEPS       float64
	PERatioBasedOnLastAuditedAccounts float64
}

PriceEarningRatio holds the data for a price earning ratio in selected date

type PriceEarningRatios

type PriceEarningRatios struct {
	Date                   string
	PriceEarningRatioArray []*PriceEarningRatio
}

PriceEarningRatios ...

type Summary

type Summary struct {
	HighestRecords      []*record
	HistoricalSummaries []*market
}

Summary holds the historical market summaries array and the record trading or highest records data

type WeeklyReports

type WeeklyReports struct {
	Year    int
	Reports []*report
}

WeeklyReports holds the weekly reports for a Year

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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