Skip to content

Commit

Permalink
Merge pull request #82 from saniales/develop
Browse files Browse the repository at this point in the history
Syncing with master
  • Loading branch information
saniales authored Dec 18, 2018
2 parents 805bb7b + 130d742 commit 3625f1f
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 177 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# golang-crypto-trading-bot
<p align="center"><img src="https://res.cloudinary.com/saniales-github/image/upload/v1541856660/saniales/golang-crypto-trading-bot/logo.png" width="360"></p>
<p align="center">
<a href="https://travis-ci.org/saniales/golang-crypto-trading-bot"><img src="https://img.shields.io/travis/saniales/golang-crypto-trading-bot.svg?branch=master" alt="Build Status"></img></a>
<a href="https://godoc.org/github.com/saniales/golang-crypto-trading-bot"><img src="https://godoc.org/github.com/saniales/golang-crypto-trading-bot?status.svg" alt="Godoc reference"></a>
<a href="https://github.com/saniales/golang-crypto-trading-bot/releases"><img src="https://img.shields.io/github/release/saniales/golang-crypto-trading-bot.svg" alt="Last Release"></a>
<a href="https://github.com/saniales/golang-crypto-trading-bot/LICENSE"><img src="https://img.shields.io/github/license/saniales/golang-crypto-trading-bot.svg?maxAge=2592000" alt="License"></a>
<a href="https://goreportcard.com/report/github.com/saniales/golang-crypto-trading-bot"><img src="https://goreportcard.com/badge/github.com/saniales/golang-crypto-trading-bot" alt="Goreportcard" /></a>
</p>

[![Go Report Card](https://goreportcard.com/badge/github.com/saniales/golang-crypto-trading-bot)](https://goreportcard.com/report/github.com/saniales/golang-crypto-trading-bot)
[![GoDoc](https://godoc.org/github.com/saniales/golang-crypto-trading-bot?status.svg)](https://godoc.org/github.com/saniales/golang-crypto-trading-bot)
[![Travis CI](https://img.shields.io/travis/saniales/golang-crypto-trading-bot.svg)]((https://travis-ci.org/saniales/golang-crypto-trading-bot))
[![GitHub release](https://img.shields.io/github/release/saniales/golang-crypto-trading-bot.svg)](https://github.com/saniales/golang-crypto-trading-bot/releases)
[![license](https://img.shields.io/github/license/saniales/golang-crypto-trading-bot.svg?maxAge=2592000)](https://github.com/saniales/golang-crypto-trading-bot/LICENSE)
# Golang Crypto Trading Bot

A golang implementation of a console-based trading bot for cryptocurrency exchanges.

Expand All @@ -22,7 +25,7 @@ If you need to, you can create a strategy and bind it to the bot:
import bot "github.com/saniales/golang-crypto-trading-bot/cmd"

func main() {
bot.AddCustomStrategy(myStrategy)
bot.AddCustomStrategy(examples.MyStrategy)
bot.Execute()
}
```
Expand Down
137 changes: 137 additions & 0 deletions examples/interval.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Copyright © 2017 Alessandro Sanino <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package examples

import (
"fmt"
"log"
"time"

"github.com/nlopes/slack"
"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/saniales/golang-crypto-trading-bot/exchanges"
"github.com/saniales/golang-crypto-trading-bot/strategies"
"github.com/shomali11/slacker"
"github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
)

// Watch5Sec prints out the info of the market every 5 seconds.
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,
}

var slackBot *slacker.Slacker

// SlackIntegrationExample send messages to Slack as a strategy.
// RTM not supported (and usually not requested when trading, this is an automated slackBot).
var SlackIntegrationExample = strategies.IntervalStrategy{
Model: strategies.StrategyModel{
Name: "SlackIntegrationExample",
Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
// connect slack token
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 {
//if updates has requirements
_, _, 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,
}

var telegramBot *tb.Bot

// TelegramIntegrationExample send messages to Telegram as a strategy.
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{})

/*
// Optionally it can have options
telegramBot.Send(tb.User{
Username: "YOUR-JOINED-GROUP-USERNAME",
}, "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
},
},
}
17 changes: 17 additions & 0 deletions examples/package-info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © 2017 Alessandro Sanino <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// Package examples contains different implementations of the strategies.
package examples
64 changes: 0 additions & 64 deletions examples/slack_integration.go

This file was deleted.

53 changes: 0 additions & 53 deletions examples/telegram_integration.go

This file was deleted.

34 changes: 16 additions & 18 deletions examples/watch.go → examples/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,38 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package strategies
package examples

import (
"fmt"
"time"

"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/saniales/golang-crypto-trading-bot/exchanges"
"github.com/saniales/golang-crypto-trading-bot/strategies"
"github.com/sirupsen/logrus"
)

// Watch5Min prints out the info of the market every 5 minutes.
var Watch5Min = strategies.IntervalStrategy{
// Websocket strategy
var Websocket = strategies.WebsocketStrategy{
Model: strategies.StrategyModel{
Name: "Watch5Min",
Name: "Websocket",
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].GetMarketSummary(markets[0])
if err != nil {
for _, wrapper := range wrappers {
err := wrapper.FeedConnect(markets)
if err == exchanges.ErrWebsocketNotSupported || err == nil {
continue
}
return err
}
fmt.Println(markets)
return nil
},
OnError: func(err error) {
fmt.Println(err)
OnUpdate: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
// do something
return nil
},
TearDown: func(wrappers []exchanges.ExchangeWrapper, markets []*environment.Market) error {
fmt.Println("Watch5Min exited")
return nil
},
OnError: func(err error) {
logrus.Error(err)
},
},
Interval: time.Minute * 5,
}
1 change: 1 addition & 0 deletions strategies/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (is IntervalStrategy) Apply(wrappers []exchanges.ExchangeWrapper, markets [
is.Model.OnError(err)
}
}

if !hasUpdateFunc {
_err := errors.New("OnUpdate func cannot be empty")
if hasErrorFunc {
Expand Down
Loading

0 comments on commit 3625f1f

Please sign in to comment.