dexter

package module
v0.0.0-...-66e1502 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2020 License: MIT Imports: 19 Imported by: 0

README

dexter

A microservice for market alerts

https://whiteblock.github.io/dexter/

Quick Start

  1. docker-compose up
  2. cd demo
  3. npm install
  4. npm start

open browser to https://localhost:3000/ and enjoy your streaming stats

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Charts = make(map[string]Chart)

Charts is a map of Charts keyed by `${exchange},${market},${timeframe}`

View Source
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.

func (Alert) Compare

func (alert Alert) Compare(chart Chart) bool

Compare checks an alerts conditions and returns true if the conditions are met.

func (Alert) Send

func (alert Alert) Send()

Send an alert which currently means fire a webhook

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 Candle

type Candle struct {
	Timestamp uint64
	O         float64
	H         float64
	L         float64
	C         float64
	V         float64
}

Candle [timestamp, open, high, low, close, volume]

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) AddAlert

func (chart *Chart) AddAlert(alert Alert) error

AddAlert - adds an Alert to a Chart

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

func (chart Chart) FindAlertIndex(id uint) (int, error)

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

func (chart *Chart) RemoveAlert(alert Alert) error

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

func (chart *Chart) UpdateAlert(alert Alert) error

UpdateAlert - update an Alert in a Chart

func (*Chart) UpdateCandle

func (chart *Chart) UpdateCandle(candle *dataPb.Candle) error

UpdateCandle - Update the price data of 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

func FindIndicatorByName(name string) (Indicator, error)

FindIndicatorByName looks up an indicator by its name

func (Indicator) FindIndexOfOutput

func (indicator Indicator) FindIndexOfOutput(name string) (int, error)

FindIndexOfOutput lets you know which index of the output array contains the line you're looking for

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

type Webhook

type Webhook struct {
	gorm.Model
	AlertID uint
	Method  string
	URL     string
	Body    string
}

Webhook - a URL to request to when an Alert is triggered.

func (Webhook) Send

func (w Webhook) Send()

Send will make the HTTP request described by the webhook.

Directories

Path Synopsis
api
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL