-
Notifications
You must be signed in to change notification settings - Fork 47
/
gotrade.go
104 lines (84 loc) · 1.93 KB
/
gotrade.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
package gotrade
import (
"time"
)
type DOHLCV interface {
D() time.Time
O() float64
H() float64
L() float64
C() float64
V() float64
}
type OHLCV interface {
O() float64
H() float64
L() float64
C() float64
V() float64
}
type OHLC interface {
O() float64
H() float64
L() float64
C() float64
}
type DOHLCVDataItem struct {
date time.Time
openPrice float64
highPrice float64
lowPrice float64
closePrice float64
volumePrice float64
}
func NewDOHLCVDataItem(date time.Time, openPrice float64, highPrice float64, lowPrice float64, closePrice float64, volume float64) *DOHLCVDataItem {
return &DOHLCVDataItem{date, openPrice, highPrice, lowPrice, closePrice, volume}
}
func (di *DOHLCVDataItem) D() time.Time {
return di.date
}
func (di *DOHLCVDataItem) O() float64 {
return di.openPrice
}
func (di *DOHLCVDataItem) H() float64 {
return di.highPrice
}
func (di *DOHLCVDataItem) L() float64 {
return di.lowPrice
}
func (di *DOHLCVDataItem) C() float64 {
return di.closePrice
}
func (di *DOHLCVDataItem) V() float64 {
return di.volumePrice
}
// A function that selects which data property to use from a DOHLCV data structure
type DOHLCVDataSelectionFunc func(dataItem DOHLCV) float64
// Close price DOHLCV data selector
func UseClosePrice(dataItem DOHLCV) float64 {
return dataItem.C()
}
// Open price DOHLCV data selector
func UseOpenPrice(dataItem DOHLCV) float64 {
return dataItem.O()
}
// High price DOHLCV data selector
func UseHighPrice(dataItem DOHLCV) float64 {
return dataItem.H()
}
// Low price DOHLCV data selector
func UseLowPrice(dataItem DOHLCV) float64 {
return dataItem.L()
}
// Volume DOHLCV data selector
func UseVolume(dataItem DOHLCV) float64 {
return dataItem.V()
}
// Consumer of DOHLCV Ticks
type DOHLCVTickReceiver interface {
ReceiveDOHLCVTick(tickData DOHLCV, streamBarIndex int)
}
// Consumer of a float tick
type TickReceiver interface {
ReceiveTick(tickData float64, streamBarIndex int)
}