Documentation ¶
Overview ¶
Package trade_knife will provide fundamental concept and utils to operate with financial time-series data.
Index ¶
- Constants
- Variables
- func AutoFiboRectracement(inHigh, inLow, inClose, ratios []float64, depth int, deviation float64) []map[float64]float64
- func HPFilter(values []float64, lambda float64) []float64
- func NewCandle(open, high, low, close, volume float64, openTime, closeTime time.Time, ...) (candle *Candle, err CandleError)
- func Plot(quote Quote, width, height vg.Length, extension string, tags []IndicatorTag) (io.WriterTo, error)
- type AutoFibo
- type BollingerBandsB
- 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
- 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 EnterCause
- type EnterChannel
- type EnterSignal
- type ExitCause
- type ExitChannel
- type ExitSignal
- type Hp
- type Indicator
- type IndicatorTag
- type Interval
- type LinearRegression
- type Ma
- type MarketType
- type PaperTrader
- func (pt *PaperTrader) Close(id string, exit float64, closeCandle *Candle)
- func (pt *PaperTrader) CloseWatcher()
- func (pt *PaperTrader) EntryWatcher()
- func (pt *PaperTrader) ExitWatcher()
- func (pt *PaperTrader) Open(id, symbol, base string, position PositionType, quote, entry, sl, tp float64, ...) *Trade
- func (pt *PaperTrader) Start() TradeError
- type PositionType
- type Quote
- func (q *Quote) AddIndicator(tag IndicatorTag, values []float64) error
- func (q Quote) Csv(indicators ...IndicatorTag) (csv string)
- func (q *Quote) Find(timestamp int64) (*Candle, int)
- func (q *Quote) Get(source Source) []float64
- func (q *Quote) IndicatorTags() []IndicatorTag
- func (q *Quote) Merge(target *Quote)
- func (q *Quote) RefreshBinance(apiKey, secretKey string) error
- func (q *Quote) ScoreByAbove(score float64, source Source)
- func (q *Quote) ScoreByBands(score float64, source Source)
- func (q *Quote) ScoreByBearish(score float64)
- func (q *Quote) ScoreByBelow(score float64, source Source)
- func (q *Quote) ScoreByBullish(score float64)
- func (q *Quote) ScoreByCross(score float64, fastSource, slowSource Source)
- func (q *Quote) ScoreByCrossDown(score float64, fastSource, slowSource Source)
- func (q *Quote) ScoreByCrossOver(score float64, fastSource, slowSource Source)
- func (q *Quote) ScoreByMiddle(score float64, source Source)
- func (q *Quote) ScoreBySupportResistance(score float64, source Source)
- func (q *Quote) ScoreByTouchDown(score float64, source Source)
- func (q *Quote) ScoreByTouchUp(score float64, source Source)
- func (q *Quote) Sort()
- func (q *Quote) Sync(open, high, low, close, volume float64, openTime, closeTime time.Time, ...) (candle *Candle, err CandleError)
- func (q *Quote) SyncBinance(update CandleChannel) (doneC chan struct{}, err error)
- func (q Quote) WriteToCsv(filename string, indicators ...IndicatorTag) error
- type Source
- type SourceError
- type StandardDeviation
- type Stoch
- type Trade
- type TradeError
- type TradeStatus
- type Trader
- type Trades
- type TradesChannel
Constants ¶
const ( // Intervals Interval1m = Interval("1m") Interval3m = Interval("3m") Interval5m = Interval("5m") Interval15m = Interval("15m") Interval30m = Interval("30m") Interval1h = Interval("1h") Interval2h = Interval("2h") Interval4h = Interval("4h") Interval6h = Interval("6h") Interval8h = Interval("8h") Interval12h = Interval("12h") Interval1d = Interval("1d") Interval3d = Interval("3d") Interval1w = Interval("1w") Interval1M = Interval("1M") // single sources SourceOpen = Source("open") SourceHigh = Source("high") SourceLow = Source("low") SourceClose = Source("close") SourceVolume = Source("volume") // double sources SourceOpenHigh = Source("oh2") SourceOpenLow = Source("ol2") SourceOpenClose = Source("oc2") SourceHighLow = Source("hl2") SourceHighClose = Source("hc2") SourceLowClose = Source("lc2") // triple sources SourceOpenHighLow = Source("ohl3") SourceOpenHighClose = Source("ohc3") SourceOpenLowClose = Source("olc3") SourceHighLowClose = Source("hlc3") // all together SourceOpenHighLowClose = Source("ohlc4") // Position types PositionBuy = PositionType("Buy") PositionSell = PositionType("Sell") // Trade statuses TradeStatusOpen = TradeStatus("Open") TradeStatusClose = TradeStatus("Close") // Exit signals ExitCauseStopLossTriggered = ExitCause("Stop loss") ExitCauseTakeProfitTriggered = ExitCause("Take profit") ExitCauseMarket = ExitCause("Market") // Market types MarketSpot = MarketType("Spot") MarketFutures = MarketType("Futures") MarketDelivery = MarketType("Delivery") )
Variables ¶
var ( ErrInvalidCandleData = errors.New("invalid data provided for candle").(CandleError) ErrNotEnoughCandles = errors.New("not enough candles to operate").(CandleError) ErrInvalidSource = errors.New("invalid source provided").(SourceError) )
Functions ¶
func AutoFiboRectracement ¶ added in v0.0.11
Types ¶
type AutoFibo ¶
type AutoFibo struct { Tag IndicatorTag `mapstructure:"tag"` Ratios []float64 `mapstructure:"ratios"` Deviation float64 `mapstructure:"deviation"` Depth int `mapstructure:"depth"` }
func (*AutoFibo) Is ¶ added in v0.0.12
func (af *AutoFibo) Is(tag IndicatorTag) bool
type BollingerBandsB ¶ added in v0.0.14
type BollingerBandsB struct { Tag IndicatorTag `mapstructure:"tag"` Std StandardDeviation `mapstructure:"standardDeviation"` }
func (*BollingerBandsB) Add ¶ added in v0.0.14
func (bbb *BollingerBandsB) Add(q *Quote, c *Candle) (ok bool)
func (*BollingerBandsB) Is ¶ added in v0.0.14
func (bbb *BollingerBandsB) Is(tag IndicatorTag) bool
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"` 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)
Add indicator value by the given name into the candle.
func (*Candle) CrossedOver ¶ added in v0.0.15
Check if fast source crossed over the slow source.
fastSource > slowSource prevfastSource <= prevslowSource
func (*Candle) CrossedUnder ¶ added in v0.0.15
Check if fast source crossed under the slow source.
fastSource < slowSource prevFastSource >= prevSlowSource
func (*Candle) Csv ¶
func (c *Candle) Csv(indicators ...IndicatorTag) (csv string)
Returns csv row of the candle.
func (*Candle) IsMiddle ¶ added in v0.0.15
Check if source is passed through middle of the candle
O >= source, H > source, L < source, C <= source,
func (*Candle) TouchedDown ¶ added in v0.0.15
Check if candle closed above the source but the Low shadow touched the source.
O,H,C > source L <= source
type CandleChannel ¶
type CandleChannel chan *Candle
type CandleError ¶
type CandleError error
type EnterCause ¶
type EnterCause string
type EnterChannel ¶
type EnterChannel chan EnterSignal
type EnterSignal ¶
type ExitChannel ¶
type ExitChannel chan ExitSignal
type ExitSignal ¶
type Hp ¶ added in v0.0.11
type Hp struct { Tag IndicatorTag `mapstructure:"tag"` Source Source `mapstructure:"source"` Lambda float64 `mapstructure:"lambda"` Length int `mapstructure:"length"` }
func (*Hp) Is ¶ added in v0.0.12
func (hp *Hp) Is(tag IndicatorTag) bool
type Indicator ¶ added in v0.0.11
type Indicator interface { Add(q *Quote, c *Candle) (ok bool) Is(tag IndicatorTag) bool }
type IndicatorTag ¶ added in v0.0.11
type IndicatorTag string
type Interval ¶
type Interval string
Interval is the timeframe concept and determines duration of each candle.
type LinearRegression ¶ added in v0.0.14
type LinearRegression struct { Tag IndicatorTag `mapstructure:"tag"` Source Source `mapstructure:"source"` InTimePeriod int `mapstructure:"period"` }
func (*LinearRegression) Add ¶ added in v0.0.14
func (lr *LinearRegression) Add(q *Quote, c *Candle) (ok bool)
func (*LinearRegression) Is ¶ added in v0.0.14
func (lr *LinearRegression) Is(tag IndicatorTag) bool
type Ma ¶ added in v0.0.11
type Ma struct { Tag IndicatorTag `mapstructure:"tag"` Source Source `mapstructure:"source"` Type talib.MaType `mapstructure:"type"` InTimePeriod int `mapstructure:"period"` }
func (*Ma) Is ¶ added in v0.0.12
func (ma *Ma) Is(tag IndicatorTag) bool
type MarketType ¶
type MarketType string
type PaperTrader ¶
type PaperTrader struct { Trades Trades BuyScoreTrigger float64 SellScoreTrigger float64 CloseOnOpposite bool Cross bool Debug bool // contains filtered or unexported fields }
PaperTrader exchange papertrade driver.
func NewPaperTrader ¶
func NewPaperTrader(candleChannel CandleChannel, entryChannel EnterChannel, buyscoreTrigger, sellscoreTrigger float64, closeOnOpposite, cross bool) *PaperTrader
Returns a pointer to fresh binance papertrade driver.
func (*PaperTrader) Close ¶
func (pt *PaperTrader) Close(id string, exit float64, closeCandle *Candle)
func (*PaperTrader) CloseWatcher ¶
func (pt *PaperTrader) CloseWatcher()
Watch for close signals and close the trade immediately.
func (*PaperTrader) EntryWatcher ¶
func (pt *PaperTrader) EntryWatcher()
Watch for entry signals and open proper positions.
func (*PaperTrader) ExitWatcher ¶
func (pt *PaperTrader) ExitWatcher()
Watch for exit signals and and fire proper close signals.
func (*PaperTrader) Open ¶
func (pt *PaperTrader) Open(id, symbol, base string, position PositionType, quote, entry, sl, tp float64, openCandle *Candle) *Trade
Create a new trade immediately.
func (*PaperTrader) Start ¶
func (pt *PaperTrader) Start() TradeError
Launch all watchers of the driver.
type PositionType ¶
type PositionType string
type Quote ¶
type Quote struct { Market MarketType Symbol string Interval Interval Candles []*Candle }
Quote is the group of candles and make time-series.
func NewQuoteFromBinance ¶
func NewQuoteFromBinance(apiKey, secretKey, symbol string, market MarketType, interval Interval, openTimestamp ...int64) (*Quote, error)
Fetches quote from binance market.
func NewQuoteFromCsv ¶
func NewQuoteFromCsv(filename string, market MarketType, symbol string, interval Interval) (*Quote, error)
Read quote from csv file.
func (*Quote) AddIndicator ¶
func (q *Quote) AddIndicator(tag IndicatorTag, values []float64) error
Add indicator values by the given tag into the quote.
func (Quote) Csv ¶
func (q Quote) Csv(indicators ...IndicatorTag) (csv string)
Returns csv formated string of whole quote.
func (*Quote) Find ¶
Search for a candle and it's index amoung Quote by it's symbol and provided timestamp.
func (*Quote) IndicatorTags ¶ added in v0.0.11
func (q *Quote) IndicatorTags() []IndicatorTag
Returns a list of indicators used in quote.
func (*Quote) RefreshBinance ¶
Fetch all candles after last candle including itself.
func (*Quote) ScoreByAbove ¶ added in v0.0.16
Score candles by checking if candles are above source.
func (*Quote) ScoreByBands ¶ added in v0.0.15
Score candles by checking touching and turning back into the band.
func (*Quote) ScoreByBearish ¶ added in v0.0.16
Score candles by if candle is bearish
func (*Quote) ScoreByBelow ¶ added in v0.0.16
Score candles by checking if candles are below source.
func (*Quote) ScoreByBullish ¶ added in v0.0.16
Score candles by checking if candles are bullish.
func (*Quote) ScoreByCross ¶ added in v0.0.15
Score candles by checking sources cross over/under condition on each of them.
func (*Quote) ScoreByCrossDown ¶ added in v0.0.16
Score candles by checking sources cross under condition on each of them.
func (*Quote) ScoreByCrossOver ¶ added in v0.0.16
Score candles by checking sources cross over condition on each of them.
func (*Quote) ScoreByMiddle ¶ added in v0.0.16
Score candles by checking if candles are middle of the source.
func (*Quote) ScoreBySupportResistance ¶ added in v0.0.15
Score candles by checking support/resistance line reaction.
func (*Quote) ScoreByTouchDown ¶ added in v0.0.16
Score candles by checking if candles are touching down source.
func (*Quote) ScoreByTouchUp ¶ added in v0.0.16
Score candles by checking if candles are touching up source.
func (*Quote) Sort ¶
func (q *Quote) Sort()
Run through the quote and reorder candles by the open time.
func (*Quote) Sync ¶
func (q *Quote) Sync(open, high, low, close, volume float64, openTime, closeTime time.Time, sCandle ...*Candle) (candle *Candle, err CandleError)
Search the quote for provided candle and update it if it exists, otherwise it will append to end of the quote.
If you want to update a candle directly then pass sCandle
func (*Quote) SyncBinance ¶
func (q *Quote) SyncBinance(update CandleChannel) (doneC chan struct{}, err error)
Will sync quote with latest binance kline info.
func (Quote) WriteToCsv ¶
func (q Quote) WriteToCsv(filename string, indicators ...IndicatorTag) error
Writes down whole quote into a csv file.
type SourceError ¶
type SourceError error
type StandardDeviation ¶ added in v0.0.14
type StandardDeviation struct { Tag IndicatorTag `mapstructure:"tag"` Source Source `mapstructure:"source"` InTimePeriod int `mapstructure:"period"` Deviation float64 `mapstructure:"deviation"` }
func (*StandardDeviation) Add ¶ added in v0.0.14
func (sd *StandardDeviation) Add(q *Quote, c *Candle) (ok bool)
func (*StandardDeviation) Is ¶ added in v0.0.14
func (sd *StandardDeviation) Is(tag IndicatorTag) bool
type Stoch ¶ added in v0.0.11
type Stoch struct { Tag IndicatorTag `mapstructure:"tag"` KTag IndicatorTag `mapstructure:"kTag"` DTag IndicatorTag `mapstructure:"dTag"` InFastKPeriod int `mapstructure:"kLength"` InSlowKPeriod int `mapstructure:"kSmoothing"` InKMaType talib.MaType `mapstructure:"kMaType"` InSlowDPeriod int `mapstructure:"dSmoothing"` InDMaType talib.MaType `mapstructure:"dMaType"` }
func (*Stoch) Is ¶ added in v0.0.12
func (s *Stoch) Is(tag IndicatorTag) bool
type Trade ¶
type Trade struct { Id string Driver string Symbol string Base string Quote float64 Amount 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 }
type TradeError ¶
type TradeError error
type TradeStatus ¶
type TradeStatus string
type Trader ¶
type Trader interface { Open(id, symbol, base string, position PositionType, quote, entry float64, sl, tp float64, openCandle *Candle) *Trade Close(id, exit float64, closeCandle *Candle) EntryWatcher() ExitWatcher() CloseWatcher() }
Interface to determine how a trader should implements.
type TradesChannel ¶
type TradesChannel chan *Trade
Source Files ¶
- auto_fibo_rectracement.go
- candle.go
- condition_above.go
- condition_bearish.go
- condition_below.go
- condition_bullish.go
- condition_crossover.go
- condition_crossunder.go
- condition_middle.go
- condition_touched_down.go
- condition_touched_up.go
- csv.go
- definitions.go
- fetcher_binance.go
- filter_hodrick_prescott.go
- indicator.go
- indicator_auto_fibo.go
- indicator_bollinger_bands_%b.go
- indicator_hp.go
- indicator_linear_rigression.go
- indicator_ma.go
- indicator_standard_deviation.go
- indicator_stoch.go
- interval.go
- paper_trader_binance.go
- plot.go
- quote.go
- source.go
- strategy_above.go
- strategy_bands.go
- strategy_bearish.go
- strategy_below.go
- strategy_bullish.go
- strategy_cross.go
- strategy_cross_down.go
- strategy_cross_up.go
- strategy_middle.go
- strategy_support_resistance.go
- strategy_touch_down.go
- strategy_touch_up.go
- trade.go