Documentation ¶
Index ¶
- Variables
- func SeriesFromChart(chart Chart) *techan.TimeSeries
- func StartNotifications(in chan Notification)
- func StartServer(listen string, db *gorm.DB, conn *grpc.ClientConn)
- type Alert
- type AlertCondition
- type Candle
- type Chart
- func (chart *Chart) AddAlert(alert Alert) error
- func (chart Chart) Analyze()
- func (chart Chart) FindAlertIndex(id uint) (int, error)
- func (chart *Chart) InitializeCandles(client dataPb.DataClient)
- func (chart *Chart) RemoveAlert(alert Alert) error
- func (chart *Chart) StreamCandles(client dataPb.DataClient) error
- func (chart *Chart) UpdateAlert(alert Alert) error
- func (chart *Chart) UpdateCandle(candle *dataPb.Candle) error
- type Indicator
- type Input
- type Line
- type Notification
- type NotificationFrequency
- type Webhook
Constants ¶
This section is empty.
Variables ¶
var Charts = make(map[string]Chart)
Charts is a map of Charts keyed by `${exchange},${market},${timeframe}`
var Indicators = []Indicator{ Indicator{ Name: "Price", Inputs: []string{}, Outputs: []string{"price"}, Fn: func(inputs []float64, chart Chart) [][]float64 { var result [][]float64 for i := 0; i < len(chart.Candles); i++ { price := chart.Candles[i].C result = append(result, []float64{price}) } return result }, }, Indicator{ Name: "Horizontal Line", Inputs: []string{"value"}, Outputs: []string{"value"}, Fn: func(inputs []float64, chart Chart) [][]float64 { var result [][]float64 value := inputs[0] for i := 0; i < len(chart.Candles); i++ { result = append(result, []float64{value}) } return result }, }, Indicator{ Name: "Moving Average", Inputs: []string{"period"}, Outputs: []string{"value"}, Fn: func(inputs []float64, chart Chart) [][]float64 { var result [][]float64 period := int(inputs[0]) series := SeriesFromChart(chart) closePrices := techan.NewClosePriceIndicator(series) movingAverage := techan.NewSimpleMovingAverage(closePrices, period) log.Println(len(chart.Candles)) for i := 0; i < len(chart.Candles)-1; i++ { ma := movingAverage.Calculate(i) maf := ma.Float() result = append(result, []float64{maf}) } return result }, }, }
Indicators is a list of indicator definitions
Functions ¶
func SeriesFromChart ¶
func SeriesFromChart(chart Chart) *techan.TimeSeries
SeriesFromChart will create a techan.TimeSeries from a dexter.Chart
func StartNotifications ¶
func StartNotifications(in chan Notification)
StartNotifications listens for notification requests on a channel that it returns to the caller.
func StartServer ¶
func StartServer(listen string, db *gorm.DB, conn *grpc.ClientConn)
StartServer starts the gRPC service for alert management
Types ¶
type Alert ¶
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 }
Alert - describes market condition that should trigger a notification.
type AlertCondition ¶
type AlertCondition int
AlertCondition describes how lines can interact with each other.
const ( Crossing AlertCondition = iota + 1 CrossingUp CrossingDown GreaterThan LessThan EnteringChannel ExitingChannel InsideChannel OutsideChannel MovingUp MovingDown MovingUpPercent MovingDownPercent )
The different ways lines can interact with each other
type Chart ¶
type Chart struct { Exchange string Market string Timeframe string Candles []Candle Alerts []Alert }
Chart - a chart is used internally when managing dexter-data candlestick streams
func SetupChart ¶
func SetupChart(alert Alert, client dataPb.DataClient) Chart
SetupChart returns a chart instance for the given exchange, market and timeframe.
func (Chart) Analyze ¶
func (chart Chart) Analyze()
Analyze - Go through every alert set for the chart and check to see if any conditions have been met
func (Chart) FindAlertIndex ¶
FindAlertIndex - find an alert in a Chart by its database id
func (*Chart) InitializeCandles ¶
func (chart *Chart) InitializeCandles(client dataPb.DataClient)
InitializeCandles uses a dexter-data client to load an initial set of candles for this chart.
func (*Chart) RemoveAlert ¶
RemoveAlert - remove an Alert from a Chart
func (*Chart) StreamCandles ¶
func (chart *Chart) StreamCandles(client dataPb.DataClient) error
StreamCandles starts getting realtime candlestick updates and runs analysis on every updated candlestick.
func (*Chart) UpdateAlert ¶
UpdateAlert - update an Alert in a Chart
type Indicator ¶
type Indicator struct { Name string Inputs []string // Ideally, this would be a struct with all the params that the Pine Script input() function takes. // https://www.tradingview.com/pine-script-reference/#fun_input Outputs []string Fn func(inputs []float64, chart Chart) [][]float64 }
Indicator is a struct that describes the inputs and outputs of an Indicator and its calculation function.
func FindIndicatorByName ¶
FindIndicatorByName looks up an indicator by its name
type Input ¶
type Input struct { Name string `json:"name"` Type string `json:"type"` Default string `json:"default"` }
Input is a paremter for an indicator
type Line ¶
type Line struct { Name string `json:"name"` Inputs []float64 `json:"inputs"` Output string `json:"output"` }
Line is a line offered by an Indicator for comparison.
type Notification ¶
type Notification interface {
Send()
}
Notification is something that has a Send method.
type NotificationFrequency ¶
type NotificationFrequency int
NotificationFrequency - how often should an alert notification fire
const ( OnlyOnce NotificationFrequency = iota + 1 OncePerBar OncePerBarClose OncePerMinute )
The different frequencies of alert notifications