-
Notifications
You must be signed in to change notification settings - Fork 0
/
candle.go
53 lines (47 loc) · 1.68 KB
/
candle.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
package quota
import (
"github.com/amir-the-h/okex"
"time"
)
// Candle is the main structure which contains a group of useful candlestick data.
type Candle struct {
Open float64 `json:"open"`
High float64 `json:"high"`
Low float64 `json:"low"`
Close float64 `json:"close"`
Volume float64 `json:"volume"`
Score float64 `json:"score"`
Symbol string `json:"symbol"`
BarSize okex.BarSize `json:"barSize"`
Indicators map[IndicatorTag]float64 `json:"indicators"`
OpenTime time.Time `json:"open_time"`
CloseTime time.Time `json:"close_time"`
Next *Candle `json:"-"`
Previous *Candle `json:"-"`
}
// NewCandle returns a pointer to a fresh candle with provided data.
func NewCandle(open, high, low, close, volume float64, symbol string, barSize okex.BarSize, openTime, closeTime time.Time, previous, next *Candle) (candle *Candle, err CandleError) {
if high < low || high < open || high < close || low > open || low > close {
err = ErrInvalidCandleData
return
}
candle = &Candle{
Open: open,
High: high,
Low: low,
Close: close,
Volume: volume,
Symbol: symbol,
BarSize: barSize,
OpenTime: openTime,
CloseTime: closeTime,
Indicators: make(map[IndicatorTag]float64),
Previous: previous,
Next: next,
}
return
}
// AddIndicator adds unimplementedIndicator value by the given name into the candle.
func (c *Candle) AddIndicator(tag IndicatorTag, value float64) {
c.Indicators[tag] = value
}