-
Notifications
You must be signed in to change notification settings - Fork 3
/
stocks_earnings_test.go
56 lines (46 loc) · 2.01 KB
/
stocks_earnings_test.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
package client
import (
"context"
"fmt"
"regexp"
"time"
)
func ExampleStockEarningsRequest_raw() {
ctx := context.TODO()
ser, err := StockEarnings().Symbol("AAPL").From("2022-01-01").To("2022-01-31").Raw(ctx)
if err != nil {
fmt.Print(err)
return
}
// Convert the response to a string if it's not already
serString := ser.String()
// Use regex to remove the "updated" key and its value so that the output is consistent between runs.
re := regexp.MustCompile(`,"updated":\[\d+\]`)
cleanedSerString := re.ReplaceAllString(serString, "")
fmt.Println(cleanedSerString)
// Output: {"s":"ok","symbol":["AAPL"],"fiscalYear":[2022],"fiscalQuarter":[1],"date":[1640926800],"reportDate":[1643259600],"reportTime":["after close"],"currency":["USD"],"reportedEPS":[2.1],"estimatedEPS":[1.89],"surpriseEPS":[0.21],"surpriseEPSpct":[0.1111]}
}
func ExampleStockEarningsRequest_packed() {
ctx := context.TODO()
ser, err := StockEarnings().Symbol("AAPL").From("2022-01-01").To("2022-01-31").Packed(ctx)
if err != nil {
fmt.Print(err)
return
}
ser.Updated = []int64{} // Delete the updated field so the string output does not change between runs.
fmt.Println(ser)
// Output: StockEarningsResponse{Symbol: [AAPL], FiscalYear: 2022, FiscalQuarter: 1, Date: [1640926800], ReportDate: [1643259600], ReportTime: [after close], Currency: [USD], ReportedEPS: [2.100000 ], EstimatedEPS: [1.890000 ], SurpriseEPS: [0.210000 ], SurpriseEPSpct: [0.111100 ], Updated: []}
}
func ExampleStockEarningsRequest_get() {
ctx := context.TODO()
ser, err := StockEarnings().Symbol("AAPL").From("2022-01-01").To("2022-01-31").Get(ctx)
if err != nil {
fmt.Print(err)
return
}
for _, report := range ser {
report.Updated = time.Time{}
fmt.Println(report)
}
// Output: StockEarningsReport{Symbol: "AAPL", FiscalYear: 2022, FiscalQuarter: 1, Date: "2021-12-31", ReportDate: "2022-01-27", ReportTime: "after close", Currency: "USD", ReportedEPS: 2.100000, EstimatedEPS: 1.890000, SurpriseEPS: 0.210000, SurpriseEPSPct: 0.111100, Updated: "nil"}
}