-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathincome_statements.go
88 lines (82 loc) · 4.43 KB
/
income_statements.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package alphavantage
import (
"encoding/json"
"fmt"
)
type IncomeStatements struct {
Symbol string `json:"symbol"`
AnnualReports []AnnualReport `json:"annualReports"`
QuarterlyReports []QuarterlyReport `json:"quarterlyReports"`
}
type AnnualReport struct {
FiscalDateEnding string `json:"fiscalDateEnding"`
ReportedCurrency string `json:"reportedCurrency"`
GrossProfit AVInt `json:"grossProfit"`
TotalRevenue AVInt `json:"totalRevenue"`
CostOfRevenue AVInt `json:"costOfRevenue"`
CostOfGoodsAndServicesSold AVInt `json:"costofGoodsAndServicesSold"`
OperatingIncome AVInt `json:"operatingIncome"`
SellingGeneralAndAdministrative AVInt `json:"sellingGeneralAndAdministrative"`
ResearchAndDevelopment AVInt `json:"researchAndDevelopment"`
OperatingExpenses AVInt `json:"operatingExpenses"`
InvestmentIncomeNet AVInt `json:"investmentIncomeNet"` // Have to handle case where value is "None"
NetInterestIncome AVInt `json:"netInterestIncome"`
InterestIncome AVInt `json:"interestIncome"`
InterestExpense AVInt `json:"interestExpense"`
NonInterestIncome AVInt `json:"nonInterestIncome"`
OtherNonOperatingIncome AVInt `json:"otherNonOperatingIncome"`
Depreciation AVInt `json:"depreciation"`
DepreciationAndAmortization AVInt `json:"depreciationAndAmortization"`
IncomeBeforeTax AVInt `json:"incomeBeforeTax"`
IncomeTaxExpense AVInt `json:"incomeTaxExpense"`
InterestAndDebtExpense AVInt `json:"interestAndDebtExpense"`
NetIncomeFromContinuingOperations AVInt `json:"netIncomeFromContinuingOperations"`
ComprehensiveIncomeNetOfTax AVInt `json:"comprehensiveIncomeNetOfTax"`
Ebit AVInt `json:"ebit"`
Ebitda AVInt `json:"ebitda"`
NetIncome AVInt `json:"netIncome"`
}
type QuarterlyReport struct {
FiscalDateEnding string `json:"fiscalDateEnding"`
ReportedCurrency string `json:"reportedCurrency"`
GrossProfit AVInt `json:"grossProfit"`
TotalRevenue AVInt `json:"totalRevenue"`
CostOfRevenue AVInt `json:"costOfRevenue"`
CostOfGoodsAndServicesSold AVInt `json:"costofGoodsAndServicesSold"`
OperatingIncome AVInt `json:"operatingIncome"`
SellingGeneralAndAdministrative AVInt `json:"sellingGeneralAndAdministrative"`
ResearchAndDevelopment AVInt `json:"researchAndDevelopment"`
OperatingExpenses AVInt `json:"operatingExpenses"`
InvestmentIncomeNet AVInt `json:"investmentIncomeNet"`
NetInterestIncome AVInt `json:"netInterestIncome"`
InterestIncome AVInt `json:"interestIncome"`
InterestExpense AVInt `json:"interestExpense"`
NonInterestIncome AVInt `json:"nonInterestIncome"`
OtherNonOperatingIncome AVInt `json:"otherNonOperatingIncome"`
Depreciation AVInt `json:"depreciation"`
DepreciationAndAmortization AVInt `json:"depreciationAndAmortization"`
IncomeBeforeTax AVInt `json:"incomeBeforeTax"`
IncomeTaxExpense AVInt `json:"incomeTaxExpense"`
InterestAndDebtExpense AVInt `json:"interestAndDebtExpense"`
NetIncomeFromContinuingOperations AVInt `json:"netIncomeFromContinuingOperations"`
ComprehensiveIncomeNetOfTax AVInt `json:"comprehensiveIncomeNetOfTax"`
Ebit AVInt `json:"ebit"`
Ebitda AVInt `json:"ebitda"`
NetIncome AVInt `json:"netIncome"`
}
func toIncomeStatements(buf []byte) (*IncomeStatements, error) {
incomeStatements := &IncomeStatements{}
if err := json.Unmarshal(buf, incomeStatements); err != nil {
return nil, err
}
return incomeStatements, nil
}
func (c *Client) IncomeStatements(symbol string) (*IncomeStatements, error) {
const function = "INCOME_STATEMENT"
url := fmt.Sprintf("%s/query?function=%s&symbol=%s&apikey=%s", baseURL, function, symbol, c.apiKey)
body, err := c.makeHTTPRequest(url)
if err != nil {
return nil, err
}
return toIncomeStatements(body)
}