Skip to content

Commit 805bb7b

Browse files
authored
Merge pull request #77 from saniales/develop
v0.0.2-alpha
2 parents bd21ce0 + da89ff9 commit 805bb7b

30 files changed

+2383
-1427
lines changed

.bot_config.yaml.example

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
1-
exchange_configs:
2-
- exchange: bittrex
3-
public_key: your_bittrex_public_key
4-
secret_key: your_bittrex_secret_key
5-
websocket_enabled: true
6-
- exchange: binance
7-
public_key: your_binance_public_key
8-
secret_key: your_binance_secret_key
9-
websocket_enabled: true
1+
simulation_mode: true
2+
exchange_configs:
103
- exchange: bitfinex
11-
public_key: your_bitfinex_public_key
12-
secret_key: your_bitfinex_secret_key
13-
websocket_enabled: true
4+
public_key: bitfinex_public_key
5+
secret_key: bitfinex_secret_key
6+
deposit_addresses:
7+
BTC : bitfinex_deposit_address_btc
8+
ETH: bitfinex_deposit_address_eth
9+
ZEC: bitfinex_deposit_address_zec
10+
fake_balances:
11+
BTC: 100
12+
ETH: 100
13+
ZEC: 100
14+
ETC: 100
15+
- exchange: hitbtc
16+
public_key: hitbtc_public_key
17+
secret_key: hitbtc_secret_key
18+
deposit_addresses:
19+
BTC : hitbtc_deposit_address_btc
20+
ETH: hitbtc_deposit_address_eth
21+
ZEC: hitbtc_deposit_address_zec
22+
fake_balances:
23+
BTC: 100
24+
ETH: 100
25+
ZEC: 100
26+
ETC: 100
1427
strategies:
15-
- strategy: your_strategy_name
28+
- strategy: strategy_name
1629
markets:
17-
- market: market_logical_name
30+
- market: ETH-BTC
1831
bindings:
19-
- exchange: bittrex
20-
market_name: market_name_on_bittrex
21-
- exchange: binance
22-
market_name: market_name_on_binance
2332
- exchange: bitfinex
24-
market_name: market_name_on_bitfinex
25-
- market: another_market_logical_name
33+
market_name: ETHBTC
34+
- exchange: hitbtc
35+
market_name: ETHBTC
36+
- market: ZEC-BTC
2637
bindings:
27-
- exchange: bittrex
28-
market_name: market_name_on_bittrex
29-
- exchange: binance
30-
market_name: market_name_on_binance
3138
- exchange: bitfinex
32-
market_name: market_name_on_bitfinex
39+
market_name: ZECBTC
40+
- exchange: hitbtc
41+
market_name: ZECBTC
42+
- market: ETC-BTC
43+
bindings:
44+
- exchange: bitfinex
45+
market_name: ETCBTC
46+
- exchange: hitbtc
47+
market_name: ETCBTC

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ _testmain.go
2626
golang-crypto-trading-bot
2727

2828
.bot_config.yaml
29-
.bot_config.yml
29+
.bot_config.yml
30+
31+
.vscode

README.md

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,114 @@
11
# golang-crypto-trading-bot
22

3+
[![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)
34
[![GoDoc](https://godoc.org/github.com/saniales/golang-crypto-trading-bot?status.svg)](https://godoc.org/github.com/saniales/golang-crypto-trading-bot)
45
[![Travis CI](https://img.shields.io/travis/saniales/golang-crypto-trading-bot.svg)]((https://travis-ci.org/saniales/golang-crypto-trading-bot))
56
[![GitHub release](https://img.shields.io/github/release/saniales/golang-crypto-trading-bot.svg)](https://github.com/saniales/golang-crypto-trading-bot/releases)
67
[![license](https://img.shields.io/github/license/saniales/golang-crypto-trading-bot.svg?maxAge=2592000)](https://github.com/saniales/golang-crypto-trading-bot/LICENSE)
78

8-
9-
A golang implementation of a console-based trading bot for cryptocurrency exchanges.
10-
11-
## Supported Exchanges
12-
Bittrex, Poloniex, Binance, Bitfinex and Kraken, other in progress.
9+
A golang implementation of a console-based trading bot for cryptocurrency exchanges.
1310

1411
## Usage
1512

1613
Download a release or directly build the code from this repository.
14+
1715
``` bash
18-
$ go get github.com/saniales/golang-crypto-trading-bot
16+
go get github.com/saniales/golang-crypto-trading-bot
1917
```
2018

2119
If you need to, you can create a strategy and bind it to the bot:
20+
2221
``` go
2322
import bot "github.com/saniales/golang-crypto-trading-bot/cmd"
2423

25-
bot.AddCustomStrategy(myStrategy)
26-
bot.Execute()
24+
func main() {
25+
bot.AddCustomStrategy(myStrategy)
26+
bot.Execute()
27+
}
2728
```
2829

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

31-
# Configuration file template
32+
## Simulation Mode
33+
34+
If enabled, the bot will do paper trading, as it will execute fake orders in a sandbox environment.
35+
36+
A Fake balance for each coin must be specified for each exchange if simulation mode is enabled.
37+
38+
## Supported Exchanges
39+
40+
| Exchange Name | REST Supported | Websocket Support |
41+
| ------------- |------------------ | ----------------- |
42+
| Bittrex | Yes | No |
43+
| Poloniex | Yes | Yes |
44+
| Kraken | Yes (no withdraw) | No |
45+
| Bitfinex | Yes | Yes |
46+
| Binance | Yes | Yes |
47+
| Kucoin | Yes | No |
48+
| HitBtc | Yes | Yes |
49+
50+
## Configuration file template
51+
3252
Create a configuration file from this example or run the `init` command of the compiled executable.
53+
3354
``` yaml
34-
exchange_configs:
35-
- exchange: bittrex
36-
public_key: your_bittrex_public_key
37-
secret_key: your_bittrex_secret_key
38-
websocket_enabled: true
39-
- exchange: binance
40-
public_key: your_binance_public_key
41-
secret_key: your_binance_secret_key
42-
websocket_enabled: true
55+
simulation_mode: true # if you want to enable simulation mode.
56+
exchange_configs:
4357
- exchange: bitfinex
44-
public_key: your_bitfinex_public_key
45-
secret_key: your_bitfinex_secret_key
46-
websocket_enabled: true
58+
public_key: bitfinex_public_key
59+
secret_key: bitfinex_secret_key
60+
deposit_addresses:
61+
BTC: bitfinex_deposit_address_btc
62+
ETH: bitfinex_deposit_address_eth
63+
ZEC: bitfinex_deposit_address_zec
64+
fake_balances: # used only if simulation mode is enabled, can be omitted if not enabled.
65+
BTC: 100
66+
ETH: 100
67+
ZEC: 100
68+
ETC: 100
69+
- exchange: hitbtc
70+
public_key: hitbtc_public_key
71+
secret_key: hitbtc_secret_key
72+
deposit_addresses:
73+
BTC : hitbtc_deposit_address_btc
74+
ETH: hitbtc_deposit_address_eth
75+
ZEC: hitbtc_deposit_address_zec
76+
fake_balances:
77+
BTC: 100
78+
ETH: 100
79+
ZEC: 100
80+
ETC: 100
4781
strategies:
48-
- strategy: your_strategy_name
82+
- strategy: strategy_name
4983
markets:
50-
- market: market_logical_name
84+
- market: ETH-BTC
85+
bindings:
86+
- exchange: bitfinex
87+
market_name: ETHBTC
88+
- exchange: hitbtc
89+
market_name: ETHBTC
90+
- market: ZEC-BTC
5191
bindings:
52-
- exchange: bittrex
53-
market_name: market_name_on_bittrex
54-
- exchange: binance
55-
market_name: market_name_on_binance
5692
- exchange: bitfinex
57-
market_name: market_name_on_bitfinex
58-
- market: another_market_logical_name
93+
market_name: ZECBTC
94+
- exchange: hitbtc
95+
market_name: ZECBTC
96+
- market: ETC-BTC
5997
bindings:
60-
- exchange: bittrex
61-
market_name: market_name_on_bittrex
62-
- exchange: binance
63-
market_name: market_name_on_binance
6498
- exchange: bitfinex
65-
market_name: market_name_on_bitfinex
99+
market_name: ETCBTC
100+
- exchange: hitbtc
101+
market_name: ETCBTC
66102
```
67103
68-
# Donate
104+
## Donate
105+
69106
Feel free to donate:
70107
71-
| METHOD | ADDRESS |
72-
|-------- |-------------------------------------------- |
73-
| Paypal | https://paypal.me/AlessandroSanino |
74-
| BTC | 1DVgmv6jkUiGrnuEv1swdGRyhQsZjX9MT3 |
75-
| XVG | DFstPiWFXjX8UCyUCxfeVpk6JkgaLBSNvS |
76-
| ETH | 0x2fe7bd8a41e91e9284aada0055dbb15ecececf02 |
77-
| USDT | 18obCEVmbT6MHXDcPoFwnUuCmkttLbK5Xo |
108+
| METHOD | ADDRESS |
109+
|-------- |-------------------------------------------- |
110+
| Paypal | https://paypal.me/AlessandroSanino |
111+
| BTC | 1DVgmv6jkUiGrnuEv1swdGRyhQsZjX9MT3 |
112+
| XVG | DFstPiWFXjX8UCyUCxfeVpk6JkgaLBSNvS |
113+
| ETH | 0x2fe7bd8a41e91e9284aada0055dbb15ecececf02 |
114+
| USDT | 18obCEVmbT6MHXDcPoFwnUuCmkttLbK5Xo |

bot_helpers/bot_helper.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,41 @@ package helpers
33
import (
44
"github.com/saniales/golang-crypto-trading-bot/environment"
55
"github.com/saniales/golang-crypto-trading-bot/exchanges"
6+
"github.com/shopspring/decimal"
67
)
78

89
//InitExchange initialize a new ExchangeWrapper binded to the specified exchange provided.
9-
func InitExchange(exchangeConfig environment.ExchangeConfig) exchanges.ExchangeWrapper {
10+
func InitExchange(exchangeConfig environment.ExchangeConfig, simulatedMode bool, fakeBalances map[string]decimal.Decimal, depositAddresses map[string]string) exchanges.ExchangeWrapper {
11+
if depositAddresses == nil && !simulatedMode {
12+
return nil
13+
}
14+
15+
var exch exchanges.ExchangeWrapper
1016
switch exchangeConfig.ExchangeName {
1117
case "bittrex":
12-
return exchanges.NewBittrexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
18+
exch = exchanges.NewBittrexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
1319
case "bittrexV2":
14-
return exchanges.NewBittrexV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
20+
exch = exchanges.NewBittrexV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
1521
case "poloniex":
16-
return exchanges.NewPoloniexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
22+
exch = exchanges.NewPoloniexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
1723
case "binance":
18-
return exchanges.NewBinanceWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
24+
exch = exchanges.NewBinanceWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
1925
case "bitfinex":
20-
return exchanges.NewBitfinexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
26+
exch = exchanges.NewBitfinexWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
2127
case "hitbtc":
22-
return exchanges.NewHitBtcV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey)
28+
exch = exchanges.NewHitBtcV2Wrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
29+
case "kucoin":
30+
exch = exchanges.NewKucoinWrapper(exchangeConfig.PublicKey, exchangeConfig.SecretKey, depositAddresses)
2331
default:
2432
return nil
2533
}
34+
35+
if simulatedMode {
36+
if fakeBalances == nil {
37+
return nil
38+
}
39+
exch = exchanges.NewExchangeWrapperSimulator(exch, fakeBalances)
40+
}
41+
42+
return exch
2643
}

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func initConfig() {
6666
fmt.Println()
6767
return
6868
}
69-
err = ioutil.WriteFile("./.gobot", content, 0666)
69+
err = ioutil.WriteFile("./.bot_config.yml", content, 0666)
7070
if err != nil {
7171
fmt.Print("Cannot write new configuration file")
7272
if GlobalFlags.Verbose > 0 {

cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ func init() {
5757
os.Exit(0)
5858
}()
5959

60-
RootCmd.PersistentFlags().CountVarP(&GlobalFlags.Verbose, "verbose", "v", "show verbose information when trading : use multiple times to increase verbosity level.")
61-
6260
RootCmd.Flags().BoolVarP(&rootFlags.Version, "version", "V", false, "show version information.")
61+
62+
RootCmd.PersistentFlags().CountVarP(&GlobalFlags.Verbose, "verbose", "v", "show verbose information when trading : use multiple times to increase verbosity level.")
6363
RootCmd.PersistentFlags().StringVar(&GlobalFlags.ConfigFile, "config-file", "./.bot_config.yaml", "Config file path (default : ./.bot_config.yaml)")
6464
}
6565

6666
func executeRootCommand(cmd *cobra.Command, args []string) {
6767
if rootFlags.Version {
68-
fmt.Printf("gobot v. %s\n", versionNumber)
68+
fmt.Printf("Golang Crypto Trading Bot v. %s\n", versionNumber)
6969
} else {
7070
cmd.Help()
7171
}

cmd/start.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"io/ioutil"
2121
"os"
22+
"strings"
2223

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

7879
fmt.Print("Getting markets cold info ... ")
7980
for _, strategyConf := range botConfig.Strategies {
8081
mkts := make([]*environment.Market, len(strategyConf.Markets))
8182
for i, mkt := range strategyConf.Markets {
83+
currencies := strings.SplitN(mkt.Name, "-", 2)
8284
mkts[i] = &environment.Market{
83-
Name: mkt.Name,
85+
Name: mkt.Name,
86+
BaseCurrency: currencies[0],
87+
MarketCurrency: currencies[1],
8488
}
8589

8690
mkts[i].ExchangeNames = make(map[string]string, len(wrappers))

environment/config.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
1515

1616
package environment
1717

18+
import (
19+
"github.com/shopspring/decimal"
20+
)
21+
1822
// ExchangeConfig Represents a configuration for an API Connection to an exchange.
1923
//
2024
// Can be used to generate an ExchangeWrapper.
2125
type ExchangeConfig struct {
22-
ExchangeName string `yaml:"exchange"` // Represents the exchange name.
23-
PublicKey string `yaml:"public_key"` // Represents the public key used to connect to Exchange API.
24-
SecretKey string `yaml:"secret_key"` // Represents the secret key used to connect to Exchange API.
25-
WebsocketEnabled bool `yaml:"websocket_enabled"` // Represents whether websocket communication is enabled for this exchange configuration or REST API is involved.
26+
ExchangeName string `yaml:"exchange"` // Represents the exchange name.
27+
PublicKey string `yaml:"public_key"` // Represents the public key used to connect to Exchange API.
28+
SecretKey string `yaml:"secret_key"` // Represents the secret key used to connect to Exchange API.
29+
DepositAddresses map[string]string `yaml:"deposit_addresses"` // Represents the bindings between coins and deposit address on the exchange.
30+
FakeBalances map[string]decimal.Decimal `yaml:"fake_balances"` // Used only in simulation mode, fake starting balance [coin:balance].
2631
}
2732

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

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

0 commit comments

Comments
 (0)