Skip to content

Commit

Permalink
Merge pull request #77 from saniales/develop
Browse files Browse the repository at this point in the history
v0.0.2-alpha
  • Loading branch information
saniales authored Nov 5, 2018
2 parents bd21ce0 + da89ff9 commit 805bb7b
Show file tree
Hide file tree
Showing 30 changed files with 2,383 additions and 1,427 deletions.
65 changes: 40 additions & 25 deletions .bot_config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
exchange_configs:
- exchange: bittrex
public_key: your_bittrex_public_key
secret_key: your_bittrex_secret_key
websocket_enabled: true
- exchange: binance
public_key: your_binance_public_key
secret_key: your_binance_secret_key
websocket_enabled: true
simulation_mode: true
exchange_configs:
- exchange: bitfinex
public_key: your_bitfinex_public_key
secret_key: your_bitfinex_secret_key
websocket_enabled: true
public_key: bitfinex_public_key
secret_key: bitfinex_secret_key
deposit_addresses:
BTC : bitfinex_deposit_address_btc
ETH: bitfinex_deposit_address_eth
ZEC: bitfinex_deposit_address_zec
fake_balances:
BTC: 100
ETH: 100
ZEC: 100
ETC: 100
- exchange: hitbtc
public_key: hitbtc_public_key
secret_key: hitbtc_secret_key
deposit_addresses:
BTC : hitbtc_deposit_address_btc
ETH: hitbtc_deposit_address_eth
ZEC: hitbtc_deposit_address_zec
fake_balances:
BTC: 100
ETH: 100
ZEC: 100
ETC: 100
strategies:
- strategy: your_strategy_name
- strategy: strategy_name
markets:
- market: market_logical_name
- market: ETH-BTC
bindings:
- exchange: bittrex
market_name: market_name_on_bittrex
- exchange: binance
market_name: market_name_on_binance
- exchange: bitfinex
market_name: market_name_on_bitfinex
- market: another_market_logical_name
market_name: ETHBTC
- exchange: hitbtc
market_name: ETHBTC
- market: ZEC-BTC
bindings:
- exchange: bittrex
market_name: market_name_on_bittrex
- exchange: binance
market_name: market_name_on_binance
- exchange: bitfinex
market_name: market_name_on_bitfinex
market_name: ZECBTC
- exchange: hitbtc
market_name: ZECBTC
- market: ETC-BTC
bindings:
- exchange: bitfinex
market_name: ETCBTC
- exchange: hitbtc
market_name: ETCBTC
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ _testmain.go
golang-crypto-trading-bot

.bot_config.yaml
.bot_config.yml
.bot_config.yml

.vscode
121 changes: 79 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,114 @@
# golang-crypto-trading-bot

[![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)


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

## Supported Exchanges
Bittrex, Poloniex, Binance, Bitfinex and Kraken, other in progress.
A golang implementation of a console-based trading bot for cryptocurrency exchanges.

## Usage

Download a release or directly build the code from this repository.

``` bash
$ go get github.com/saniales/golang-crypto-trading-bot
go get github.com/saniales/golang-crypto-trading-bot
```

If you need to, you can create a strategy and bind it to the bot:

``` go
import bot "github.com/saniales/golang-crypto-trading-bot/cmd"

bot.AddCustomStrategy(myStrategy)
bot.Execute()
func main() {
bot.AddCustomStrategy(myStrategy)
bot.Execute()
}
```

For strategy reference see the [Godoc documentation](https://godoc.org/github.com/saniales/golang-crypto-trading-bot).

# Configuration file template
## Simulation Mode

If enabled, the bot will do paper trading, as it will execute fake orders in a sandbox environment.

A Fake balance for each coin must be specified for each exchange if simulation mode is enabled.

## Supported Exchanges

| Exchange Name | REST Supported | Websocket Support |
| ------------- |------------------ | ----------------- |
| Bittrex | Yes | No |
| Poloniex | Yes | Yes |
| Kraken | Yes (no withdraw) | No |
| Bitfinex | Yes | Yes |
| Binance | Yes | Yes |
| Kucoin | Yes | No |
| HitBtc | Yes | Yes |

## Configuration file template

Create a configuration file from this example or run the `init` command of the compiled executable.

``` yaml
exchange_configs:
- exchange: bittrex
public_key: your_bittrex_public_key
secret_key: your_bittrex_secret_key
websocket_enabled: true
- exchange: binance
public_key: your_binance_public_key
secret_key: your_binance_secret_key
websocket_enabled: true
simulation_mode: true # if you want to enable simulation mode.
exchange_configs:
- exchange: bitfinex
public_key: your_bitfinex_public_key
secret_key: your_bitfinex_secret_key
websocket_enabled: true
public_key: bitfinex_public_key
secret_key: bitfinex_secret_key
deposit_addresses:
BTC: bitfinex_deposit_address_btc
ETH: bitfinex_deposit_address_eth
ZEC: bitfinex_deposit_address_zec
fake_balances: # used only if simulation mode is enabled, can be omitted if not enabled.
BTC: 100
ETH: 100
ZEC: 100
ETC: 100
- exchange: hitbtc
public_key: hitbtc_public_key
secret_key: hitbtc_secret_key
deposit_addresses:
BTC : hitbtc_deposit_address_btc
ETH: hitbtc_deposit_address_eth
ZEC: hitbtc_deposit_address_zec
fake_balances:
BTC: 100
ETH: 100
ZEC: 100
ETC: 100
strategies:
- strategy: your_strategy_name
- strategy: strategy_name
markets:
- market: market_logical_name
- market: ETH-BTC
bindings:
- exchange: bitfinex
market_name: ETHBTC
- exchange: hitbtc
market_name: ETHBTC
- market: ZEC-BTC
bindings:
- exchange: bittrex
market_name: market_name_on_bittrex
- exchange: binance
market_name: market_name_on_binance
- exchange: bitfinex
market_name: market_name_on_bitfinex
- market: another_market_logical_name
market_name: ZECBTC
- exchange: hitbtc
market_name: ZECBTC
- market: ETC-BTC
bindings:
- exchange: bittrex
market_name: market_name_on_bittrex
- exchange: binance
market_name: market_name_on_binance
- exchange: bitfinex
market_name: market_name_on_bitfinex
market_name: ETCBTC
- exchange: hitbtc
market_name: ETCBTC
```
# Donate
## Donate
Feel free to donate:
| METHOD | ADDRESS |
|-------- |-------------------------------------------- |
| Paypal | https://paypal.me/AlessandroSanino |
| BTC | 1DVgmv6jkUiGrnuEv1swdGRyhQsZjX9MT3 |
| XVG | DFstPiWFXjX8UCyUCxfeVpk6JkgaLBSNvS |
| ETH | 0x2fe7bd8a41e91e9284aada0055dbb15ecececf02 |
| USDT | 18obCEVmbT6MHXDcPoFwnUuCmkttLbK5Xo |
| METHOD | ADDRESS |
|-------- |-------------------------------------------- |
| Paypal | https://paypal.me/AlessandroSanino |
| BTC | 1DVgmv6jkUiGrnuEv1swdGRyhQsZjX9MT3 |
| XVG | DFstPiWFXjX8UCyUCxfeVpk6JkgaLBSNvS |
| ETH | 0x2fe7bd8a41e91e9284aada0055dbb15ecececf02 |
| USDT | 18obCEVmbT6MHXDcPoFwnUuCmkttLbK5Xo |
31 changes: 24 additions & 7 deletions bot_helpers/bot_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,41 @@ package helpers
import (
"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/saniales/golang-crypto-trading-bot/exchanges"
"github.com/shopspring/decimal"
)

//InitExchange initialize a new ExchangeWrapper binded to the specified exchange provided.
func InitExchange(exchangeConfig environment.ExchangeConfig) exchanges.ExchangeWrapper {
func InitExchange(exchangeConfig environment.ExchangeConfig, simulatedMode bool, fakeBalances map[string]decimal.Decimal, depositAddresses map[string]string) exchanges.ExchangeWrapper {
if depositAddresses == nil && !simulatedMode {
return nil
}

var exch exchanges.ExchangeWrapper
switch exchangeConfig.ExchangeName {
case "bittrex":
return exchanges.NewBittrexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
exch = exchanges.NewBittrexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
case "bittrexV2":
return exchanges.NewBittrexV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
exch = exchanges.NewBittrexV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
case "poloniex":
return exchanges.NewPoloniexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
exch = exchanges.NewPoloniexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
case "binance":
return exchanges.NewBinanceWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
exch = exchanges.NewBinanceWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
case "bitfinex":
return exchanges.NewBitfinexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
exch = exchanges.NewBitfinexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
case "hitbtc":
return exchanges.NewHitBtcV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
exch = exchanges.NewHitBtcV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
case "kucoin":
exch = exchanges.NewKucoinWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
default:
return nil
}

if simulatedMode {
if fakeBalances == nil {
return nil
}
exch = exchanges.NewExchangeWrapperSimulator(exch, fakeBalances)
}

return exch
}
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func initConfig() {
fmt.Println()
return
}
err = ioutil.WriteFile("./.gobot", content, 0666)
err = ioutil.WriteFile("./.bot_config.yml", content, 0666)
if err != nil {
fmt.Print("Cannot write new configuration file")
if GlobalFlags.Verbose > 0 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ func init() {
os.Exit(0)
}()

RootCmd.PersistentFlags().CountVarP(&GlobalFlags.Verbose, "verbose", "v", "show verbose information when trading : use multiple times to increase verbosity level.")

RootCmd.Flags().BoolVarP(&rootFlags.Version, "version", "V", false, "show version information.")

RootCmd.PersistentFlags().CountVarP(&GlobalFlags.Verbose, "verbose", "v", "show verbose information when trading : use multiple times to increase verbosity level.")
RootCmd.PersistentFlags().StringVar(&GlobalFlags.ConfigFile, "config-file", "./.bot_config.yaml", "Config file path (default : ./.bot_config.yaml)")
}

func executeRootCommand(cmd *cobra.Command, args []string) {
if rootFlags.Version {
fmt.Printf("gobot v. %s\n", versionNumber)
fmt.Printf("Golang Crypto Trading Bot v. %s\n", versionNumber)
} else {
cmd.Help()
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"

helpers "github.com/saniales/golang-crypto-trading-bot/bot_helpers"
"github.com/saniales/golang-crypto-trading-bot/environment"
Expand Down Expand Up @@ -71,16 +72,19 @@ func executeStartCommand(cmd *cobra.Command, args []string) {
fmt.Print("Getting exchange info ... ")
wrappers := make([]exchanges.ExchangeWrapper, len(botConfig.ExchangeConfigs))
for i, config := range botConfig.ExchangeConfigs {
wrappers[i] = helpers.InitExchange(config)
wrappers[i] = helpers.InitExchange(config, botConfig.SimulationModeOn, config.FakeBalances, config.DepositAddresses)
}
fmt.Println("DONE")

fmt.Print("Getting markets cold info ... ")
for _, strategyConf := range botConfig.Strategies {
mkts := make([]*environment.Market, len(strategyConf.Markets))
for i, mkt := range strategyConf.Markets {
currencies := strings.SplitN(mkt.Name, "-", 2)
mkts[i] = &environment.Market{
Name: mkt.Name,
Name: mkt.Name,
BaseCurrency: currencies[0],
MarketCurrency: currencies[1],
}

mkts[i].ExchangeNames = make(map[string]string, len(wrappers))
Expand Down
18 changes: 12 additions & 6 deletions environment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@

package environment

import (
"github.com/shopspring/decimal"
)

// ExchangeConfig Represents a configuration for an API Connection to an exchange.
//
// Can be used to generate an ExchangeWrapper.
type ExchangeConfig struct {
ExchangeName string `yaml:"exchange"` // Represents the exchange name.
PublicKey string `yaml:"public_key"` // Represents the public key used to connect to Exchange API.
SecretKey string `yaml:"secret_key"` // Represents the secret key used to connect to Exchange API.
WebsocketEnabled bool `yaml:"websocket_enabled"` // Represents whether websocket communication is enabled for this exchange configuration or REST API is involved.
ExchangeName string `yaml:"exchange"` // Represents the exchange name.
PublicKey string `yaml:"public_key"` // Represents the public key used to connect to Exchange API.
SecretKey string `yaml:"secret_key"` // Represents the secret key used to connect to Exchange API.
DepositAddresses map[string]string `yaml:"deposit_addresses"` // Represents the bindings between coins and deposit address on the exchange.
FakeBalances map[string]decimal.Decimal `yaml:"fake_balances"` // Used only in simulation mode, fake starting balance [coin:balance].
}

// StrategyConfig contains where a strategy will be applied in the specified exchange.
Expand All @@ -45,6 +50,7 @@ type ExchangeBindingsConfig struct {

// BotConfig contains all config data of the bot, which can be also loaded from config file.
type BotConfig struct {
ExchangeConfigs []ExchangeConfig `yaml:"exchange_configs"` // Represents the current exchange configuration.
Strategies []StrategyConfig `yaml:"strategies"` // Represents the current strategies adopted by the bot.
SimulationModeOn bool `yaml:"simulation_mode"` // if true, do not create real orders and do not get real balance
ExchangeConfigs []ExchangeConfig `yaml:"exchange_configs"` // Represents the current exchange configuration.
Strategies []StrategyConfig `yaml:"strategies"` // Represents the current strategies adopted by the bot.
}
Loading

0 comments on commit 805bb7b

Please sign in to comment.