/
historical.go
105 lines (98 loc) · 4.39 KB
/
historical.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
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) 2019 The iexcloud developers. All rights reserved.
// Project site: https://github.com/goinvest/iexcloud
// Use of this source code is governed by a MIT-style license that
// can be found in the LICENSE file for the project.
package iex
// HistoricalTimeFrame enum for selecting time frame of historical data
type HistoricalTimeFrame string
const (
// OneMonthHistorical One month (default) historically adjusted market-wide data
OneMonthHistorical HistoricalTimeFrame = "1m"
// ThreeMonthHistorical Three months historically adjusted market-wide data
ThreeMonthHistorical HistoricalTimeFrame = "3m"
// SixMonthHistorical Six months historically adjusted market-wide data
SixMonthHistorical HistoricalTimeFrame = "6m"
// OneYearHistorical One year historically adjusted market-wide data
OneYearHistorical HistoricalTimeFrame = "1y"
// TwoYearHistorical Two year historically adjusted market-wide data
TwoYearHistorical HistoricalTimeFrame = "2y"
// FiveYearHistorical Five year historically adjusted market-wide data
FiveYearHistorical HistoricalTimeFrame = "5y"
// YearToDateHistorical Year to date historically adjusted market-wide data
YearToDateHistorical HistoricalTimeFrame = "ytd"
// MaxHistorical All available historically adjusted market-wide data up to 15 years
MaxHistorical HistoricalTimeFrame = "max"
)
// Valid Determines if HistoricalTimeFrame is a defined constant
func (htf HistoricalTimeFrame) Valid() bool {
switch htf {
case OneMonthHistorical, ThreeMonthHistorical,
SixMonthHistorical, OneYearHistorical,
TwoYearHistorical, FiveYearHistorical,
YearToDateHistorical, MaxHistorical:
return true
default:
return false
}
}
// IntradayHistoricalDataPoint Represents a single intraday data point for a stock
type IntradayHistoricalDataPoint struct {
Date string `json:"date"`
Minute string `json:"minute"`
Label string `json:"label"`
High float64 `json:"high"`
Low float64 `json:"low"`
Average float64 `json:"average"`
Volume int `json:"volume"`
Notional float64 `json:"notional"`
NumberOfTrades int `json:"numberOfTrades"`
MarketHigh float64 `json:"marketHigh"`
MarketLow float64 `json:"marketLow"`
MarketAverage float64 `json:"marketAverage"`
MarketVolume int `json:"marketVolume"`
MarketNotional float64 `json:"marketNotional"`
MarketNumberOfTrades int `json:"marketNumberOfTrades"`
Open float64 `json:"open"`
Close float64 `json:"close"`
MarketOpen float64 `json:"marketOpen"`
MarketClose float64 `json:"marketClose"`
ChangeOverTime float64 `json:"changeOverTime"`
MarketChangeOverTime float64 `json:"marketChangeOverTime"`
}
// HistoricalOptions optional query params to pass to historical endpoint
// If values are false or 0 they aren't passed.
type HistoricalOptions struct {
ChartCloseOnly bool `url:"chartCloseOnly,omitempty"`
ChartSimplify bool `url:"chartSimplify,omitempty"`
ChartInterval int `url:"chartInterval,omitempty"`
ChangeFromClose bool `url:"changeFromClose,omitempty"`
ChartLast int `url:"chartLast,omitempty"`
}
// IntradayHistoricalOptions optional query params to pass to intraday historical endpoint
// If values are false or 0 they aren't passed.
type IntradayHistoricalOptions struct {
ChartIEXOnly bool `url:"chartIEXOnly,omitempty"`
ChartReset bool `url:"chartReset,omitempty"`
ChartSimplify bool `url:"chartSimplify,omitempty"`
ChartInterval int `url:"chartInterval,omitempty"`
ChangeFromClose bool `url:"changeFromClose,omitempty"`
ChartLast int `url:"chartLast,omitempty"`
}
// HistoricalDataPoint Represents a single historical data point for a stock
type HistoricalDataPoint struct {
Date string `json:"date"`
Open float64 `json:"open"`
Close float64 `json:"close"`
High float64 `json:"high"`
Low float64 `json:"low"`
Volume int `json:"volume"`
UOpen float64 `json:"uOpen"`
UClose float64 `json:"uClose"`
UHigh float64 `json:"uHigh"`
ULow float64 `json:"uLow"`
UVolume int `json:"uVolume"`
Change float64 `json:"change"`
ChangePercent float64 `json:"changePercent"`
Label string `json:"label"`
ChangeOverTime float64 `json:"changeOverTime"`
}