Version: v0.0.1-alpha Latest Latest

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

Go to latest
Published: Jul 20, 2018 License: GPL-3.0 Imports: 8 Imported by: 0



Package strategies contains all strategies which can be used by the bot. They may use one or more algorithms.



This section is empty.


This section is empty.


func AddCustomStrategy

func AddCustomStrategy(s Strategy)

AddCustomStrategy adds a strategy to the available set.

func ApplyAllStrategies

func ApplyAllStrategies(wrappers []exchanges.ExchangeWrapper)

ApplyAllStrategies applies all matched strategies concurrently.

func MatchWithMarkets

func MatchWithMarkets(strategyName string, markets []*environment.Market) error

MatchWithMarkets matches a strategy with the markets.


type IntervalStrategy

type IntervalStrategy struct {
	Model    StrategyModel
	Interval time.Duration

IntervalStrategy is an interval based strategy.

func (IntervalStrategy) Apply

func (is IntervalStrategy) Apply(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market)

Apply executes Cyclically the On Update, basing on provided interval.

func (IntervalStrategy) Name

func (is IntervalStrategy) Name() string

Name returns the name of the strategy.

func (IntervalStrategy) String

func (is IntervalStrategy) String() string

String returns a string representation of the object.

type Strategy

type Strategy interface {
	Name() string                                             // Name returns the name of the strategy.
	Apply([]exchanges.ExchangeWrapper, []*environment.Market) // Apply applies the strategy when called, using the specified wrapper.

Strategy represents a generic strategy.

var Watch5Min Strategy = IntervalStrategy{
	Model: StrategyModel{
		Name: "Watch5Min",
		Setup: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			fmt.Println("Watch5Min starting")
			return nil
		OnUpdate: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			_, err := wrappers[0].GetTicker(markets[0])
			if err != nil {
				return err
			return nil
		OnError: func(err error) {
		TearDown: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			fmt.Println("Watch5Min exited")
			return nil
	Interval: time.Minute * 5,

Watch5Min prints out the info of the market every 5 minutes.

type StrategyFunc

type StrategyFunc func([]exchanges.ExchangeWrapper, []*environment.Market) error

StrategyFunc represents a standard function binded to a strategy model execution.

Can define a Setup, TearDown and Update behaviour.

type StrategyModel

type StrategyModel struct {
	Name     string
	Setup    StrategyFunc
	TearDown StrategyFunc
	OnUpdate StrategyFunc
	OnError  func(error)

StrategyModel represents a strategy model used by strategies.

type Tactic

type Tactic struct {
	Markets  []*environment.Market
	Strategy Strategy

Tactic represents the effective appliance of a strategy.

func (*Tactic) Execute

func (t *Tactic) Execute(wrappers []exchanges.ExchangeWrapper)

Execute executes effectively a tactic.

Jump to

Keyboard shortcuts

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