examples

package
Version: v0.0.2-alpha.0...-0fc358b Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package examples contains different implementations of the strategies.

Index

Constants

This section is empty.

Variables

View Source
var DiscordIntegrationExample = strategies.IntervalStrategy{
	Model: strategies.StrategyModel{
		Name: "DiscordIntegrationExample",
		Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {

			discordBot, err := discordgo.New("Bot " + "YOUR-DISCORD-TOKEN")
			if err != nil {
				return err
			}

			go func() {
				err = discordBot.Open()
				if err != nil {
					return
				}
			}()

			time.Sleep(time.Second * 5)
			if err != nil {
				return err
			}

			return nil
		},
		OnUpdate: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
			_, err := discordBot.ChannelMessageSend("CHANNEL-ID", "OMG SOMETHING HAPPENING!!!!!")
			if err != nil {
				return err
			}
			return nil
		},
		OnError: func(err error) {
			logrus.Errorf("I Got an error %s", err)
			telegramBot.Stop()
		},
		TearDown: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
			err := discordBot.Close()
			if err != nil {
				return err
			}
			return nil
		},
	},
}

DiscordIntegrationExample sends messages to a specified discord channel.

View Source
var SlackIntegrationExample = strategies.IntervalStrategy{
	Model: strategies.StrategyModel{
		Name: "SlackIntegrationExample",
		Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {

			slackBot = slacker.NewClient("YOUR-TOKEN-HERE")
			slackBot.Init(func() {
				log.Println("Slack BOT Connected")
			})
			slackBot.Err(func(err string) {
				log.Println("Error during slack slackBot connection: ", err)
			})
			go func() {
				err := slackBot.Listen()
				if err != nil {
					log.Fatal(err)
				}
			}()
			return nil
		},
		OnUpdate: func([]exchanges.ExchangeWrapper, []*environment.Market) error {

			_, _, err := slackBot.Client.PostMessage("DESIRED-CHANNEL", "OMG something happening!!!!!", slack.PostMessageParameters{})
			return err
		},
		OnError: func(err error) {
			logrus.Errorf("I Got an error %s", err)
		},
	},
	Interval: time.Second * 10,
}

SlackIntegrationExample send messages to Slack as a strategy. RTM not supported (and usually not requested when trading, this is an automated slackBot).

View Source
var TelegramIntegrationExample = strategies.IntervalStrategy{
	Model: strategies.StrategyModel{
		Name: "TelegramIntegrationExample",
		Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
			telegramBot, err := tb.NewBot(tb.Settings{
				Token:  "YOUR-TELEGRAM-TOKEN",
				Poller: &tb.LongPoller{Timeout: 10 * time.Second},
			})

			if err != nil {
				return err
			}

			telegramBot.Start()
			return nil
		},
		OnUpdate: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
			telegramBot.Send(&tb.User{
				Username: "YOUR-USERNAME-GROUP-OR-USER",
			}, "OMG SOMETHING HAPPENING!!!!!", tb.SendOptions{})

			return nil
		},
		OnError: func(err error) {
			logrus.Errorf("I Got an error %s", err)
			telegramBot.Stop()
		},
		TearDown: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
			telegramBot.Stop()
			return nil
		},
	},
}

TelegramIntegrationExample send messages to Telegram as a strategy.

View Source
var Watch5Sec = strategies.IntervalStrategy{
	Model: strategies.StrategyModel{
		Name: "Watch5Sec",
		Setup: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			fmt.Println("Watch5Sec starting")
			return nil
		},
		OnUpdate: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			_, err := wrappers[0].GetMarketSummary(markets[0])
			if err != nil {
				return err
			}
			logrus.Info(markets)
			logrus.Info(wrappers)
			return nil
		},
		OnError: func(err error) {
			fmt.Println(err)
		},
		TearDown: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			fmt.Println("Watch5Sec exited")
			return nil
		},
	},
	Interval: time.Second * 5,
}

Watch5Sec prints out the info of the market every 5 seconds.

View Source
var Websocket = strategies.WebsocketStrategy{
	Model: strategies.StrategyModel{
		Name: "Websocket",
		Setup: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			for _, wrapper := range wrappers {
				err := wrapper.FeedConnect(markets)
				if err == exchanges.ErrWebsocketNotSupported || err == nil {
					continue
				}
				return err
			}
			return nil
		},
		OnUpdate: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {

			return nil
		},
		TearDown: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
			return nil
		},
		OnError: func(err error) {
			logrus.Error(err)
		},
	},
}

Websocket strategy

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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