forked from sklinkert/alphavantage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcash_flow.go
94 lines (88 loc) · 5.53 KB
/
cash_flow.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
89
90
91
92
93
94
package alphavantage
import (
"encoding/json"
"fmt"
)
type CashFlows struct {
Symbol string `json:"symbol"`
AnnualReports []AnnualReport `json:"annualReports"`
QuarterlyReports []QuarterlyReport `json:"quarterlyReports"`
}
type AnnualReport struct {
FiscalDateEnding string `json:"fiscalDateEnding"`
ReportedCurrency string `json:"reportedCurrency"`
OperatingCashflow float64 `json:"operatingCashflow"`
PaymentsForOperatingActivities float64 `json:"paymentsForOperatingActivities"`
ProceedsFromOperatingActivities float64 `json:"proceedsFromOperatingActivities"`
ChangeInOperatingLiabilities float64 `json:"changeInOperatingLiabilities"`
ChangeInOperatingAssets float64 `json:"changeInOperatingAssets"`
DepreciationDepletionAndAmortization float64 `json:"depreciationDepletionAndAmortization"`
CapitalExpenditures float64 `json:"capitalExpenditures"`
ChangeInReceivables float64 `json:"changeInReceivables"`
ChangeInInventory float64 `json:"changeInInventory"`
ProfitLoss float64 `json:"profitLoss"`
CashflowFromInvestment float64 `json:"cashflowFromInvestment"`
CashflowFromFinancing float64 `json:"cashflowFromFinancing"`
ProceedsFromRepaymentsOfShortTermDebt float64 `json:"proceedsFromRepaymentsOfShortTermDebt"`
PaymentsForRepurchaseOfCommonStock float64 `json:"paymentsForRepurchaseOfCommonStock"`
PaymentsForRepurchaseOfEquity float64 `json:"paymentsForRepurchaseOfEquity"`
PaymentsForRepurchaseOfPreferredStock float64 `json:"paymentsForRepurchaseOfPreferredStock"`
DividendPayout float64 `json:"dividendPayout"`
DividendPayoutCommonStock float64 `json:"dividendPayoutCommonStock"`
DividendPayoutPreferredStock float64 `json:"dividendPayoutPreferredStock"`
ProceedsFromIssuanceOfCommonStock float64 `json:"proceedsFromIssuanceOfCommonStock"`
ProceedsFromIssuanceOfLongTermDebt float64 `json:"proceedsFromIssuanceOfLongTermDebtAndCapitalSecuritiesNet"`
ProceedsFromIssuanceOfPreferredStock float64 `json:"proceedsFromIssuanceOfPreferredStock"`
ProceedsFromRepurchaseOfEquity float64 `json:"proceedsFromRepurchaseOfEquity"`
ProceedsFromSaleOfTreasuryStock float64 `json:"proceedsFromSaleOfTreasuryStock"`
ChangeInCashAndCashEquivalents float64 `json:"changeInCashAndCashEquivalents"`
ChangeInExchangeRate float64 `json:"changeInExchangeRate"`
NetIncome float64 `json:"netIncome"`
}
type QuarterlyReport struct {
FiscalDateEnding string `json:"fiscalDateEnding"`
ReportedCurrency string `json:"reportedCurrency"`
OperatingCashflow float64 `json:"operatingCashflow"`
PaymentsForOperatingActivities float64 `json:"paymentsForOperatingActivities"`
ProceedsFromOperatingActivities float64 `json:"proceedsFromOperatingActivities"`
ChangeInOperatingLiabilities float64 `json:"changeInOperatingLiabilities"`
ChangeInOperatingAssets float64 `json:"changeInOperatingAssets"`
DepreciationDepletionAndAmortization float64 `json:"depreciationDepletionAndAmortization"`
CapitalExpenditures float64 `json:"capitalExpenditures"`
ChangeInReceivables float64 `json:"changeInReceivables"`
ChangeInInventory float64 `json:"changeInInventory"`
ProfitLoss float64 `json:"profitLoss"`
CashflowFromInvestment float64 `json:"cashflowFromInvestment"`
CashflowFromFinancing float64 `json:"cashflowFromFinancing"`
ProceedsFromRepaymentsOfShortTermDebt float64 `json:"proceedsFromRepaymentsOfShortTermDebt"`
PaymentsForRepurchaseOfCommonStock float64 `json:"paymentsForRepurchaseOfCommonStock"`
PaymentsForRepurchaseOfEquity float64 `json:"paymentsForRepurchaseOfEquity"`
PaymentsForRepurchaseOfPreferredStock float64 `json:"paymentsForRepurchaseOfPreferredStock"`
DividendPayout float64 `json:"dividendPayout"`
DividendPayoutCommonStock float64 `json:"dividendPayoutCommonStock"`
DividendPayoutPreferredStock float64 `json:"dividendPayoutPreferredStock"`
ProceedsFromIssuanceOfCommonStock float64 `json:"proceedsFromIssuanceOfCommonStock"`
ProceedsFromIssuanceOfLongTermDebt float64 `json:"proceedsFromIssuanceOfLongTermDebtAndCapitalSecuritiesNet"`
ProceedsFromIssuanceOfPreferredStock float64 `json:"proceedsFromIssuanceOfPreferredStock"`
ProceedsFromRepurchaseOfEquity float64 `json:"proceedsFromRepurchaseOfEquity"`
ProceedsFromSaleOfTreasuryStock float64 `json:"proceedsFromSaleOfTreasuryStock"`
ChangeInCashAndCashEquivalents float64 `json:"changeInCashAndCashEquivalents"`
ChangeInExchangeRate float64 `json:"changeInExchangeRate"`
NetIncome float64 `json:"netIncome"`
}
func toCashFlows(buf []byte) (*CashFlows, error) {
cashFlows := &CashFlows{}
if err := json.Unmarshal(buf, cashFlows); err != nil {
return nil, fmt.Errorf("unable to unmarshal cash flows: %v", err)
}
return cashFlows, nil
}
func (c *Client) CashFlows(symbol string) (*CashFlows, error) {
const function = "CASH_FLOW"
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 toCashFlows(body)
}