-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmodels.go
More file actions
153 lines (127 loc) · 3.17 KB
/
models.go
File metadata and controls
153 lines (127 loc) · 3.17 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package dexter
import (
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
)
/*
// Indicator - metadata for a technical analysis function
type Indicator struct {
gorm.Model
Name string
Implementation string // native or pinescript
Source string // pinescript source code
Inputs postgres.Jsonb // the parameters this indicator takes
/*
{
value: "integer"
}
ex:
{ value: 3 }
alternatively...
period
input [ 1 ]
output [ [ 1.34 ] ]
horizontal line
input [ 1.23 ]
output [ [ 1.234 ] ]
stochastics
input [ 1, 2, 3 ] (K, D, Smooth)
output [
[3, 4]
[5, 6]
]
*/
/*
Lines postgres.Jsonb // the lines this indicator offers
Styles postgres.Jsonb // unused for now but anything that's drawn gets to set visual parameters of its own
}
type IndicatorInput []float64
type IndicatorOutput [][]float64
type IndicatorFn func(IndicatorInput) IndicatorOutput
*/
// Line is a line offered by an Indicator for comparison.
type Line struct {
Name string `json:"name"`
Inputs []float64 `json:"inputs"`
Output string `json:"output"`
}
/*
Note that indicators that only have one line (like HorizontalLine) don't need to
list any lines in the UI. Maybe in the database, it'll have a Default line to
make it so that I don't need to create a special case for Indicators that have
only one line on the server side.
*/
// Input is a paremter for an indicator
type Input struct {
Name string `json:"name"`
Type string `json:"type"`
Default string `json:"default"`
}
// AlertCondition describes how lines can interact with each other.
type AlertCondition int
// The different ways lines can interact with each other
const (
Crossing AlertCondition = iota + 1
CrossingUp
CrossingDown
GreaterThan
LessThan
EnteringChannel
ExitingChannel
InsideChannel
OutsideChannel
MovingUp
MovingDown
MovingUpPercent
MovingDownPercent
)
// NotificationFrequency - how often should an alert notification fire
type NotificationFrequency int
// The different frequencies of alert notifications
const (
OnlyOnce NotificationFrequency = iota + 1
OncePerBar
OncePerBarClose
OncePerMinute
)
// Alert - describes market condition that should trigger a notification.
type Alert struct {
gorm.Model
Exchange string
Market string
Timeframe string
ExternalID uint64
LineA postgres.Jsonb // Line
/*
{
name: "Horizontal Line",
inputs: [ 10000 ],
output: "default"
}
{
name: "Simple Moving Average",
inputs: [ 10 ], // 10 period MA
output: "default" // Some indicators have more than one output, but default is a synonym for the 0th index
}
*/
Condition AlertCondition
LineB postgres.Jsonb // Line
Frequency NotificationFrequency
MessageBody string
Webhook Webhook
}
// Webhook - a URL to request to when an Alert is triggered.
type Webhook struct {
gorm.Model
AlertID uint
Method string
URL string
Body string
}
/*
drop table webhooks;
drop table indicators;
drop table indicator_specs;
drop table alerts;
drop table charts;
*/