Documentation ¶
Overview ¶
Package quota will provide fundamental concept and utils to operate with financial time-series data, specially supports crypto-currencies.
Index ¶
- Constants
- Variables
- func NewCandle(open, high, low, close, volume float64, symbol string, barSize okex.BarSize, ...) (candle *Candle, err CandleError)
- type Candle
- func (c *Candle) AddIndicator(tag IndicatorTag, value float64)
- func (c *Candle) CrossedOver(fastSource, slowSource Source) bool
- func (c *Candle) CrossedUnder(fastSource, slowSource Source) bool
- func (c *Candle) Csv(indicators ...IndicatorTag) (csv string)
- func (c *Candle) Get(source Source) (float64, bool)
- func (c *Candle) IsAbove(source Source) bool
- func (c *Candle) IsBearish() bool
- func (c *Candle) IsBelow(source Source) bool
- func (c *Candle) IsBullish() bool
- func (c *Candle) IsMiddle(source Source) bool
- func (c *Candle) TouchedDown(source Source) bool
- func (c *Candle) TouchedUp(source Source) bool
- type CandleChannel
- type CandleError
- type EnterChannel
- type EnterSignal
- type ExitCause
- type ExitChannel
- type ExitSignal
- type Indicator
- type IndicatorTag
- type MarketType
- type PositionType
- type Quota
- func (q *Quota) AddIndicator(tag IndicatorTag, values []float64) error
- func (q *Quota) BarSize() okex.BarSize
- func (q *Quota) Csv(indicators ...IndicatorTag) (csv string)
- func (q *Quota) Find(timestamp int64) (*Candle, int)
- func (q *Quota) Get(source Source) []float64
- func (q *Quota) IndicatorTags() []IndicatorTag
- func (q *Quota) Merge(target *Quota)
- func (q *Quota) ScoreByAbove(source Source, score float64)
- func (q *Quota) ScoreByBands(source Source, score float64)
- func (q *Quota) ScoreByBearish(score float64)
- func (q *Quota) ScoreByBelow(source Source, score float64)
- func (q *Quota) ScoreByBullish(score float64)
- func (q *Quota) ScoreByCross(fastSource, slowSource Source, score float64)
- func (q *Quota) ScoreByCrossOver(fastSource, slowSource Source, score float64)
- func (q *Quota) ScoreByCrossUnder(fastSource, slowSource Source, score float64)
- func (q *Quota) ScoreByMiddle(source Source, score float64)
- func (q *Quota) ScoreBySupportResistance(source Source, score float64)
- func (q *Quota) ScoreByTouchDown(source Source, score float64)
- func (q *Quota) ScoreByTouchUp(source Source, score float64)
- func (q *Quota) Sort()
- func (q *Quota) Symbol() string
- func (q *Quota) Sync(open, high, low, close, volume float64, openTime, closeTime time.Time, ...) (candle *Candle, err CandleError)
- func (q *Quota) WriteToCsv(filename string, indicators ...IndicatorTag) error
- type Source
- type SourceError
- type Trade
- type TradeError
- type TradeStatus
- type Trader
- type Trades
- type TradesChannel
Constants ¶
const ( // SourceOpen determines open Source SourceOpen = Source("open") // SourceHigh determines open Source SourceHigh = Source("high") // SourceLow determines open Source SourceLow = Source("low") // SourceClose determines open Source SourceClose = Source("close") // SourceVolume determines open Source SourceVolume = Source("volume") // SourceOpenHigh determines oh2 Source SourceOpenHigh = Source("oh2") // SourceOpenLow determines ol2 Source SourceOpenLow = Source("ol2") // SourceOpenClose determines oc2 Source SourceOpenClose = Source("oc2") // SourceHighLow determines hl2 Source SourceHighLow = Source("hl2") // SourceHighClose determines hc2 Source SourceHighClose = Source("hc2") // SourceLowClose determines lc2 Source SourceLowClose = Source("lc2") // SourceOpenHighLow determines ohl3 Source SourceOpenHighLow = Source("ohl3") // SourceOpenHighClose determines ohc3 Source SourceOpenHighClose = Source("ohc3") // SourceOpenLowClose determines olc3 Source SourceOpenLowClose = Source("olc3") // SourceHighLowClose determines hlc3 Source SourceHighLowClose = Source("hlc3") // SourceOpenHighLowClose determines ohlc4 Source SourceOpenHighLowClose = Source("ohlc4") // PositionBuy determines buy PositionType PositionBuy = PositionType("Buy") // PositionSell determines sell PositionType PositionSell = PositionType("Sell") // TradeStatusOpen determines open TradeStatus TradeStatusOpen = TradeStatus("Open") // TradeStatusClose determines close TradeStatus TradeStatusClose = TradeStatus("Close") // ExitCauseStopLossTriggered determines stop loss triggered on trade. ExitCauseStopLossTriggered = ExitCause("Stop loss") // ExitCauseTakeProfitTriggered determines take profit triggered on trade. ExitCauseTakeProfitTriggered = ExitCause("Take profit") // ExitCauseMarket determines trade closed by market. ExitCauseMarket = ExitCause("Market") )
Variables ¶
var ( // ErrInvalidCandleData occurs on Candle operations. ErrInvalidCandleData = errors.New("invalid data provided for candle").(CandleError) // ErrNotEnoughCandles occurs when there is not enough Candle in Quota to operate. ErrNotEnoughCandles = errors.New("not enough candles to operate").(CandleError) )
Functions ¶
Types ¶
type Candle ¶
type Candle struct { Open float64 `json:"open"` High float64 `json:"high"` Low float64 `json:"low"` Close float64 `json:"close"` Volume float64 `json:"volume"` Score float64 `json:"score"` Symbol string `json:"symbol"` BarSize okex.BarSize `json:"barSize"` Indicators map[IndicatorTag]float64 `json:"indicators"` OpenTime time.Time `json:"open_time"` CloseTime time.Time `json:"close_time"` Next *Candle `json:"-"` Previous *Candle `json:"-"` }
Candle is the main structure which contains a group of useful candlestick data.
func (*Candle) AddIndicator ¶
func (c *Candle) AddIndicator(tag IndicatorTag, value float64)
AddIndicator adds unimplementedIndicator value by the given name into the candle.
func (*Candle) CrossedOver ¶
CrossedOver checks if fast source crossed over the slow source.
fastSource > slowSource prevFastSource <= prevSlowSource
func (*Candle) CrossedUnder ¶
CrossedUnder checks if fast source crossed under the slow source.
fastSource < slowSource prevFastSource >= prevSlowSource
func (*Candle) Csv ¶
func (c *Candle) Csv(indicators ...IndicatorTag) (csv string)
Csv returns csv row of the candle.
func (*Candle) IsMiddle ¶
IsMiddle checks if source is passed through middle of the candle.
O >= source H > source L < source C <= source
func (*Candle) TouchedDown ¶
TouchedDown checks if candle closed above the source but the Low shadow touched the source.
O,H,C > source L <= source
type EnterSignal ¶
type EnterSignal struct { Symbol string Score float64 Quote float64 TakeProfit float64 Stoploss float64 Cause string Candle Candle }
EnterSignal is a signal for entering into positions
type ExitSignal ¶
ExitSignal is a signal for exiting from positions
type Indicator ¶
type Indicator interface { Add(q *Quota, c *Candle) (ok bool) Is(tag IndicatorTag) bool }
Indicator indicates how an UnimplementedIndicator should be implemented.
type IndicatorTag ¶
type IndicatorTag string
IndicatorTag specifies each UnimplementedIndicator for others.
type Quota ¶
type Quota []*Candle
Quota is the group of candles and make time-series.
func NewQuoteFromCsv ¶
NewQuoteFromCsv reads quote from csv file.
func (*Quota) AddIndicator ¶
func (q *Quota) AddIndicator(tag IndicatorTag, values []float64) error
AddIndicator adds unimplementedIndicator values by the given tag into the quota.
func (*Quota) Csv ¶
func (q *Quota) Csv(indicators ...IndicatorTag) (csv string)
Csv returns csv formatted string of whole quote.
func (*Quota) Find ¶
Find searches for a candle, and its index among Quota by its symbol and provided timestamp.
func (*Quota) IndicatorTags ¶
func (q *Quota) IndicatorTags() []IndicatorTag
IndicatorTags returns a list of indicators used in quota.
func (*Quota) ScoreByAbove ¶
ScoreByAbove scores candles by checking if candles are above source.
func (*Quota) ScoreByBands ¶
ScoreByBands scores candles by checking touching and turning back into the band.
func (*Quota) ScoreByBearish ¶
ScoreByBearish scores candles by if candle is bearish
func (*Quota) ScoreByBelow ¶
ScoreByBelow scores candles by checking if candles are below source.
func (*Quota) ScoreByBullish ¶
ScoreByBullish scores candles by checking if candles are bullish.
func (*Quota) ScoreByCross ¶
ScoreByCross scores candles by checking sources both crosses over and under condition on each of them.
func (*Quota) ScoreByCrossOver ¶
ScoreByCrossOver scores candles by checking sources cross over condition on each of them.
func (*Quota) ScoreByCrossUnder ¶
ScoreByCrossUnder scores candles by checking sources cross under condition on each of them.
func (*Quota) ScoreByMiddle ¶
ScoreByMiddle scores candles by checking if candles are middle of the source.
func (*Quota) ScoreBySupportResistance ¶
ScoreBySupportResistance scores candles by checking support/resistance line reaction.
func (*Quota) ScoreByTouchDown ¶
ScoreByTouchDown scores candles by checking if candles are touching down source.
func (*Quota) ScoreByTouchUp ¶
ScoreByTouchUp scores candles by checking if candles are touching up source.
func (*Quota) Sort ¶
func (q *Quota) Sort()
Sort runs through the quota and reorder candles by the open time.
func (*Quota) Sync ¶
func (q *Quota) Sync(open, high, low, close, volume float64, openTime, closeTime time.Time, sCandle ...*Candle) (candle *Candle, err CandleError)
Sync searches the quota for provided candle and update it if it exists, otherwise, it will append to end of the quota.
If you want to update a candle directly then pass sCandle.
func (*Quota) WriteToCsv ¶
func (q *Quota) WriteToCsv(filename string, indicators ...IndicatorTag) error
WriteToCsv writes down whole quote into a csv file.
type Trade ¶
type Trade struct { ID string Coin string Base string Driver string Quote float64 Size float64 Entry float64 Exit float64 ProfitPrice float64 ProfitPercentage float64 StopLossPercent float64 StopLossPrice float64 TakeProfitPercent float64 TakeProfitPrice float64 Position PositionType Status TradeStatus OpenCandle *Candle CloseCandle *Candle OpenAt *time.Time CloseAt *time.Time }
Trade represents a real world trade
func NewTrade ¶
func NewTrade(id, driver, coin, base string, position PositionType, quote, entry, sl, tp float64, openCandle *Candle) *Trade
NewTrade returns a pointer to a fresh trade.
type Trader ¶
type Trader interface { Open(coin, base string, position PositionType, quote, entry, sl, tp float64, openCandle *Candle) *Trade Close(id string, exit float64, closeCandle *Candle) Start() TradeError EntryWatcher() ExitWatcher() CloseWatcher() }
Trader determines how a trader should be implemented.