indicator

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

* Copyright 2021 The Cerebro Authors * * Licensed under the GNU General Public License v3.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * <https:fsf.org/> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2021 The Cerebro Authors * * Licensed under the GNU General Public License v3.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * <https:fsf.org/> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2021 The Cerebro Authors * * Licensed under the GNU General Public License v3.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * <https:fsf.org/> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2021 The Cerebro Authors * * Licensed under the GNU General Public License v3.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * <https:fsf.org/> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOverDate = e.Error{Code: 1, Message: "raise unexpected error"}
)

Functions

func NewRsiIndicator

func NewRsiIndicator(period int) *rsiIndicator

func Resampler

func Resampler(last *Candle, tk Tick, compress time.Duration) error

Rasampler is resample for realtime tick data

func Rma

func Rma(period int, values []float64) []float64

Types

type Candle

type Candle struct {
	Date          time.Time  `json:"date"`
	Code          string     `json:"code"`
	Type          CandleType `gorm:"-"`
	Open          int64      `json:"open"`
	High          int64      `json:"high"`
	Low           int64      `json:"low"`
	Close         int64      `json:"close"`
	Volume        int64      `json:"volume"`
	Amount        int64      `json:"amount"`
	IndicateValue int64      `json:"indicateValue"`
}

func ResampleCandle

func ResampleCandle(compress time.Duration, tick ...Tick) Candle

type CandleBuffer

type CandleBuffer struct {
	// contains filtered or unexported fields
}

func NewCandleBuffer

func NewCandleBuffer(c []Candle) *CandleBuffer

func (*CandleBuffer) Cap

func (c *CandleBuffer) Cap() int

func (*CandleBuffer) Len

func (c *CandleBuffer) Len() int

func (*CandleBuffer) Less

func (c *CandleBuffer) Less(i, j int) bool

func (*CandleBuffer) Next

func (c *CandleBuffer) Next(n int) []Candle

func (*CandleBuffer) Read

func (c *CandleBuffer) Read(p []Candle) (n int, err error)

func (*CandleBuffer) Reset

func (c *CandleBuffer) Reset()

func (*CandleBuffer) Swap

func (c *CandleBuffer) Swap(i, j int)

func (*CandleBuffer) Truncate

func (c *CandleBuffer) Truncate(n int)

func (*CandleBuffer) Write

func (c *CandleBuffer) Write(p []Candle) (n int, err error)

type CandleType

type CandleType int
const (
	Min CandleType = iota + 1
	Min3
	Min5
	Min15
	Min60
	Day
)

func (CandleType) Duration

func (c CandleType) Duration() time.Duration

type Candles

type Candles []Candle

func Resample

func Resample(tk []Tick, compress time.Duration) Candles

func (Candles) BollingerBand

func (c Candles) BollingerBand(period int) (bottom []Indicate[float64], mid []Indicate[float64], top []Indicate[float64])

calculate bollinger band with candle period is the number of candles to calculate the mean and standard deviation of the candle period must be greater than 1 and day

func (Candles) Envelope

func (c Candles) Envelope(period int, up, down float64) (sma, upper, lower []Indicate[float64])

Envelope indicator, period (number) up,down percentage

func (Candles) Len

func (c Candles) Len() int

func (Candles) Less

func (c Candles) Less(i, j int) bool

func (Candles) MACD

func (c Candles) MACD(fast, slow, signal int) (macdLine []Indicate[float64], signalLine []Indicate[float64])

func (Candles) Mean

func (c Candles) Mean() float64

func (Candles) StandardDeviation

func (c Candles) StandardDeviation() float64

func (Candles) StochasticFast

func (c Candles) StochasticFast(k, d, period int) (K, D []Indicate[float64])

func (Candles) StochasticSlow

func (c Candles) StochasticSlow(k, d, period int) (K, D []Indicate[float64])

func (Candles) Swap

func (c Candles) Swap(i, j int)

func (Candles) VolumeRatio

func (c Candles) VolumeRatio(nday int) []Indicate[float64]

type Indicate

type Indicate[T comparable] struct {
	Data    T
	Date    time.Time
	RawData float64 `json:"rawData,omitempty"`
}

type Indicator

type Indicator struct {
	// contains filtered or unexported fields
}

func CombineWithF

func CombineWithF(minimumWait time.Duration, f func(v ...float64) float64, indicators ...Indicator) Indicator

func (Indicator) Filter

func (s Indicator) Filter(f func(value Packet) bool) Indicator

func (Indicator) LargeThen

func (s Indicator) LargeThen(i Indicator)

func (Indicator) Mean

func (s Indicator) Mean(d time.Duration) Indicator

Mean is average of tick

func (Indicator) ROI

func (s Indicator) ROI(d time.Duration) Indicator

Roi is rate of increase or decrease per duration Roi is calculated by (end - start) / start * 100 (%) return every tick

func (Indicator) Transaction

func (s Indicator) Transaction(f func(v Packet))

type InternalIndicator

type InternalIndicator interface {
	Value
	Start(tick <-chan Tick)
}

InternalIndicator only for internal use

func NewValue

func NewValue(ctx context.Context, candles Candles) InternalIndicator

type Packet

type Packet struct {
	Tick    Tick
	Value   float64
	Candles Candles
}

type Spread

type Spread string
const (
	Bid Spread = "bid"
	Ask Spread = "ask"
)

type Tick

type Tick struct {
	Date      time.Time         `json:"date"`
	Code      string            `json:"code"`
	AskBid    Spread            `json:"askBid"`
	DiffRate  float64           `json:"diffRate"`
	Price     int64             `json:"price"`
	AccVolume int64             `json:"accVolume"`
	Volume    int64             `json:"volume"`
	Metadata  map[string]string `json:"metadata"`
}

type Ticks

type Ticks []Tick

func (Ticks) Len

func (t Ticks) Len() int

func (Ticks) Less

func (t Ticks) Less(i, j int) bool

func (Ticks) Mean

func (t Ticks) Mean() float64

func (Ticks) StandardDeviation

func (t Ticks) StandardDeviation() float64

func (Ticks) Swap

func (t Ticks) Swap(i, j int)

type TradeHistory

type TradeHistory struct {
	Date        time.Time `json:"date"`
	Code        string    `json:"code"`
	ASKBID      string    `json:"askbid"`
	Price       float64   `json:"price"`
	Volume      float64   `json:"volume"`
	PrevPrice   float64   `json:"prevPrice"`
	ChangePrice float64   `json:"changePrice"`
	ID          int64     `json:"id"`
}

type Value

type Value interface {
	Volume() Indicator
	Price() Indicator
	Filter(f func(Tick) bool) Value
}

Jump to

Keyboard shortcuts

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