From fc6809621b9b9e5daed2c7c4df1a06636d1710aa Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Sat, 19 Mar 2016 16:10:39 +1100 Subject: [PATCH] Made slight amendments to interface code, ran gofmt. --- anxhttp.go | 53 ++++++++---------------- bitfinexhttp.go | 27 ++++++------ bitstamphttp.go | 27 ++++++------ brightonpeakhttp.go | 28 ++++++------- btcchttp.go | 30 +++++++------- btcehttp.go | 37 +++++++++-------- btcmarkets.go | 31 +++++++------- coinbasehttp.go | 28 ++++++------- geminihttp.go | 29 ++++++------- huobihttp.go | 30 +++++++------- interfaces.go | 12 +++--- itbithttp.go | 30 +++++++------- kraken.go | 31 +++++++------- lakebtchttp.go | 32 +++++++-------- localbitcoinshttp.go | 32 +++++++-------- main.go | 97 +++++++++++++++++++++----------------------- okcoinhttp.go | 29 ++++++------- poloniexhttp.go | 30 +++++++------- 18 files changed, 297 insertions(+), 316 deletions(-) diff --git a/anxhttp.go b/anxhttp.go index a749ab6494f..05dbbb956b5 100644 --- a/anxhttp.go +++ b/anxhttp.go @@ -100,45 +100,28 @@ func (a *ANX) SetDefaults() { a.RESTPollingDelay = 10 } - - -/// -func (a *ANX) InterfaceSetDefaults() { - a.Name = "ANX" - a.Enabled = true - a.TakerFee = 0.6 - a.MakerFee = 0.3 - a.Verbose = false - a.Websocket = false - println("This is working using interfaces") - a.RESTPollingDelay = 10 -} -/// - - //Setup is run on startup to setup exchange with config values -func (a *ANX) Setup(exch Exchanges) { - if !exch.Enabled { - a.SetEnabled(false) - } else { - a.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - a.SetAPIKeys(exch.APIKey, exch.APISecret) - a.RESTPollingDelay = exch.RESTPollingDelay - a.Verbose = exch.Verbose - a.Websocket = exch.Websocket - a.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - a.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - a.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } +func (a *ANX) Setup(exch Exchanges) { + if !exch.Enabled { + a.SetEnabled(false) + } else { + a.Enabled = true + a.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + a.SetAPIKeys(exch.APIKey, exch.APISecret) + a.RESTPollingDelay = exch.RESTPollingDelay + a.Verbose = exch.Verbose + a.Websocket = exch.Websocket + a.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + a.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + a.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } } + //Start is run if exchange is enabled, after Setup -func(a *ANX) Start() { - if(a.Enabled) { - go a.Run() - } +func (a *ANX) Start() { + go a.Run() } - func (a *ANX) GetName() string { return a.Name } @@ -151,8 +134,6 @@ func (a *ANX) IsEnabled() bool { return a.Enabled } - - func (a *ANX) SetAPIKeys(apiKey, apiSecret string) { if !a.AuthenticatedAPISupport { return diff --git a/bitfinexhttp.go b/bitfinexhttp.go index b120d5eb773..6052d96a19e 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -196,22 +196,23 @@ func (b *Bitfinex) GetName() string { } func (b *Bitfinex) Setup(exch Exchanges) { - if !exch.Enabled { - b.SetEnabled(false) - } else { - b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - b.SetAPIKeys(exch.APIKey, exch.APISecret) - b.RESTPollingDelay = exch.RESTPollingDelay - b.Verbose = exch.Verbose - b.Websocket = exch.Websocket - b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } + if !exch.Enabled { + b.SetEnabled(false) + } else { + b.Enabled = true + b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + b.SetAPIKeys(exch.APIKey, exch.APISecret) + b.RESTPollingDelay = exch.RESTPollingDelay + b.Verbose = exch.Verbose + b.Websocket = exch.Websocket + b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } } func (b *Bitfinex) Start() { - go b.Run() + go b.Run() } func (b *Bitfinex) SetEnabled(enabled bool) { diff --git a/bitstamphttp.go b/bitstamphttp.go index 7648863f1ce..efd5dcdc9bb 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -146,7 +146,7 @@ func (b *Bitstamp) SetDefaults() { } func (b *Bitstamp) Start() { - go b.Run() + go b.Run() } func (b *Bitstamp) GetName() string { @@ -154,18 +154,19 @@ func (b *Bitstamp) GetName() string { } func (b *Bitstamp) Setup(exch Exchanges) { - if !exch.Enabled { - b.SetEnabled(false) - } else { - b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - b.SetAPIKeys(exch.ClientID, exch.APIKey, exch.APISecret) - b.RESTPollingDelay = exch.RESTPollingDelay - b.Verbose = exch.Verbose - b.Websocket = exch.Websocket - b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } + if !exch.Enabled { + b.SetEnabled(false) + } else { + b.Enabled = true + b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + b.SetAPIKeys(exch.ClientID, exch.APIKey, exch.APISecret) + b.RESTPollingDelay = exch.RESTPollingDelay + b.Verbose = exch.Verbose + b.Websocket = exch.Websocket + b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } } func (b *Bitstamp) SetEnabled(enabled bool) { diff --git a/brightonpeakhttp.go b/brightonpeakhttp.go index 469df746691..1f47f154100 100644 --- a/brightonpeakhttp.go +++ b/brightonpeakhttp.go @@ -46,25 +46,25 @@ func (b *BrightonPeak) SetEnabled(enabled bool) { } func (b *BrightonPeak) Setup(exch Exchanges) { - if !exch.Enabled { - b.SetEnabled(false) - } else { - b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - b.SetAPIKeys(exch.APIKey, exch.APISecret, exch.ClientID) - b.RESTPollingDelay = exch.RESTPollingDelay - b.Verbose = exch.Verbose - b.Websocket = exch.Websocket - b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } + if !exch.Enabled { + b.SetEnabled(false) + } else { + b.Enabled = true + b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + b.SetAPIKeys(exch.APIKey, exch.APISecret, exch.ClientID) + b.RESTPollingDelay = exch.RESTPollingDelay + b.Verbose = exch.Verbose + b.Websocket = exch.Websocket + b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } } func (b *BrightonPeak) Start() { - go b.Run() + go b.Run() } - func (b *BrightonPeak) IsEnabled() bool { return b.Enabled } diff --git a/btcchttp.go b/btcchttp.go index 7cad69a47a3..157cd6172c1 100644 --- a/btcchttp.go +++ b/btcchttp.go @@ -183,22 +183,24 @@ func (b *BTCC) SetDefaults() { //Setup is run on startup to setup exchange with config values func (b *BTCC) Setup(exch Exchanges) { - if !exch.Enabled { - b.SetEnabled(false) - } else { - b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - b.SetAPIKeys(exch.APIKey, exch.APISecret) - b.RESTPollingDelay = exch.RESTPollingDelay - b.Verbose = exch.Verbose - b.Websocket = exch.Websocket - b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } + if !exch.Enabled { + b.SetEnabled(false) + } else { + b.Enabled = true + b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + b.SetAPIKeys(exch.APIKey, exch.APISecret) + b.RESTPollingDelay = exch.RESTPollingDelay + b.Verbose = exch.Verbose + b.Websocket = exch.Websocket + b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } } + //Start is run if exchange is enabled, after Setup -func(b *BTCC) Start() { - go b.Run() +func (b *BTCC) Start() { + go b.Run() } func (b *BTCC) GetName() string { diff --git a/btcehttp.go b/btcehttp.go index c4b15532866..6296a629cfc 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -99,24 +99,25 @@ func (b *BTCE) IsEnabled() bool { return b.Enabled } -func(b *BTCE) Setup(exch Exchanges) { - if !exch.Enabled { - b.SetEnabled(false) - } else { - b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - b.SetAPIKeys(exch.APIKey, exch.APISecret) - b.RESTPollingDelay = exch.RESTPollingDelay - b.Verbose = exch.Verbose - b.Websocket = exch.Websocket - b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - - } -} - -func(b *BTCE) Start() { - go b.Run() +func (b *BTCE) Setup(exch Exchanges) { + if !exch.Enabled { + b.SetEnabled(false) + } else { + b.Enabled = true + b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + b.SetAPIKeys(exch.APIKey, exch.APISecret) + b.RESTPollingDelay = exch.RESTPollingDelay + b.Verbose = exch.Verbose + b.Websocket = exch.Websocket + b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + + } +} + +func (b *BTCE) Start() { + go b.Run() } func (b *BTCE) SetAPIKeys(apiKey, apiSecret string) { diff --git a/btcmarkets.go b/btcmarkets.go index df2d2663a53..b4173e651af 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -109,23 +109,24 @@ func (b *BTCMarkets) IsEnabled() bool { } func (b *BTCMarkets) Setup(exch Exchanges) { - if !exch.Enabled { - b.SetEnabled(false) - } else { - b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - b.SetAPIKeys(exch.APIKey, exch.APISecret) - b.RESTPollingDelay = exch.RESTPollingDelay - b.Verbose = exch.Verbose - b.Websocket = exch.Websocket - b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - - } + if !exch.Enabled { + b.SetEnabled(false) + } else { + b.Enabled = true + b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + b.SetAPIKeys(exch.APIKey, exch.APISecret) + b.RESTPollingDelay = exch.RESTPollingDelay + b.Verbose = exch.Verbose + b.Websocket = exch.Websocket + b.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + b.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + b.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + + } } -func(b *BTCMarkets) Start() { - go b.Run() +func (b *BTCMarkets) Start() { + go b.Run() } func (b *BTCMarkets) SetAPIKeys(apiKey, apiSecret string) { diff --git a/coinbasehttp.go b/coinbasehttp.go index c836981d2a3..a3be7d1db2c 100644 --- a/coinbasehttp.go +++ b/coinbasehttp.go @@ -144,23 +144,23 @@ func (c *Coinbase) IsEnabled() bool { } func (c *Coinbase) Setup(exch Exchanges) { - if !exch.Enabled { - c.SetEnabled(false) - } else { - c.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - c.SetAPIKeys(exch.ClientID, exch.APIKey, exch.APISecret) - c.RESTPollingDelay = exch.RESTPollingDelay - c.Verbose = exch.Verbose - c.Websocket = exch.Websocket - c.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - c.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - c.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - - } + if !exch.Enabled { + c.SetEnabled(false) + } else { + c.Enabled = true + c.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + c.SetAPIKeys(exch.ClientID, exch.APIKey, exch.APISecret) + c.RESTPollingDelay = exch.RESTPollingDelay + c.Verbose = exch.Verbose + c.Websocket = exch.Websocket + c.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + c.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + c.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } } func (c *Coinbase) Start() { - go c.Run() + go c.Run() } func (c *Coinbase) GetFee(maker bool) float64 { diff --git a/geminihttp.go b/geminihttp.go index 25b88c0cbee..25402bc94a6 100644 --- a/geminihttp.go +++ b/geminihttp.go @@ -122,22 +122,23 @@ func (g *Gemini) IsEnabled() bool { } func (g *Gemini) Setup(exch Exchanges) { - if !exch.Enabled { - g.SetEnabled(false) - } else { - g.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - g.SetAPIKeys(exch.APIKey, exch.APISecret) - g.RESTPollingDelay = exch.RESTPollingDelay - g.Verbose = exch.Verbose - g.Websocket = exch.Websocket - g.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - g.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - g.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} + if !exch.Enabled { + g.SetEnabled(false) + } else { + g.Enabled = true + g.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + g.SetAPIKeys(exch.APIKey, exch.APISecret) + g.RESTPollingDelay = exch.RESTPollingDelay + g.Verbose = exch.Verbose + g.Websocket = exch.Websocket + g.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + g.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + g.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (g *Gemini) Start() { - go g.Run() + go g.Run() } func (g *Gemini) SetAPIKeys(apiKey, apiSecret string) { diff --git a/huobihttp.go b/huobihttp.go index d2e677d4e7d..8fe1f6cfa37 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -63,24 +63,24 @@ func (h *HUOBI) IsEnabled() bool { return h.Enabled } - func (h *HUOBI) Setup(exch Exchanges) { - if !exch.Enabled { - h.SetEnabled(false) - } else { - h.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - h.SetAPIKeys(exch.APIKey, exch.APISecret) - h.RESTPollingDelay = exch.RESTPollingDelay - h.Verbose = exch.Verbose - h.Websocket = exch.Websocket - h.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - h.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - h.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} + if !exch.Enabled { + h.SetEnabled(false) + } else { + h.Enabled = true + h.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + h.SetAPIKeys(exch.APIKey, exch.APISecret) + h.RESTPollingDelay = exch.RESTPollingDelay + h.Verbose = exch.Verbose + h.Websocket = exch.Websocket + h.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + h.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + h.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (h *HUOBI) Start() { - go h.Run() + go h.Run() } func (h *HUOBI) SetAPIKeys(apiKey, apiSecret string) { diff --git a/interfaces.go b/interfaces.go index ff3a57150fb..8fd4bfd20c0 100644 --- a/interfaces.go +++ b/interfaces.go @@ -1,11 +1,9 @@ package main -/// type IBotExchange interface { - Setup(exch Exchanges) - Start() - SetDefaults() - GetName() string - IsEnabled() bool + Setup(exch Exchanges) + Start() + SetDefaults() + GetName() string + IsEnabled() bool } -/// \ No newline at end of file diff --git a/itbithttp.go b/itbithttp.go index 6939326b725..68932979ad6 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -71,25 +71,25 @@ func (i *ItBit) IsEnabled() bool { } func (i *ItBit) Setup(exch Exchanges) { - if !exch.Enabled { - i.SetEnabled(false) - } else { - i.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - i.SetAPIKeys(exch.APIKey, exch.APISecret, exch.ClientID) - i.RESTPollingDelay = exch.RESTPollingDelay - i.Verbose = exch.Verbose - i.Websocket = exch.Websocket - i.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - i.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - i.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} + if !exch.Enabled { + i.SetEnabled(false) + } else { + i.Enabled = true + i.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + i.SetAPIKeys(exch.APIKey, exch.APISecret, exch.ClientID) + i.RESTPollingDelay = exch.RESTPollingDelay + i.Verbose = exch.Verbose + i.Websocket = exch.Websocket + i.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + i.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + i.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (i *ItBit) Start() { - go i.Run() + go i.Run() } - func (i *ItBit) SetAPIKeys(apiKey, apiSecret, userID string) { i.ClientKey = apiKey i.APISecret = apiSecret diff --git a/kraken.go b/kraken.go index 6a597cbc502..de2a1a207a2 100644 --- a/kraken.go +++ b/kraken.go @@ -74,27 +74,26 @@ func (k *Kraken) IsEnabled() bool { return k.Enabled } - func (k *Kraken) Setup(exch Exchanges) { - if !exch.Enabled { - k.SetEnabled(false) - } else { - k.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - k.SetAPIKeys(exch.APIKey, exch.APISecret) - k.RESTPollingDelay = exch.RESTPollingDelay - k.Verbose = exch.Verbose - k.Websocket = exch.Websocket - k.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - k.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - k.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} + if !exch.Enabled { + k.SetEnabled(false) + } else { + k.Enabled = true + k.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + k.SetAPIKeys(exch.APIKey, exch.APISecret) + k.RESTPollingDelay = exch.RESTPollingDelay + k.Verbose = exch.Verbose + k.Websocket = exch.Websocket + k.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + k.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + k.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (k *Kraken) Start() { - go k.Run() + go k.Run() } - func (k *Kraken) SetAPIKeys(apiKey, apiSecret string) { k.ClientKey = apiKey k.APISecret = apiSecret diff --git a/lakebtchttp.go b/lakebtchttp.go index 6280f94cd3a..a80c67e7697 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -79,26 +79,26 @@ func (l *LakeBTC) IsEnabled() bool { return l.Enabled } -func (l *LakeBTC)Setup(exch Exchanges) { - if !exch.Enabled { - l.SetEnabled(false) - } else { - l.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - l.SetAPIKeys(exch.APIKey, exch.APISecret) - l.RESTPollingDelay = exch.RESTPollingDelay - l.Verbose = exch.Verbose - l.Websocket = exch.Websocket - l.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - l.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - l.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} +func (l *LakeBTC) Setup(exch Exchanges) { + if !exch.Enabled { + l.SetEnabled(false) + } else { + l.Enabled = true + l.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + l.SetAPIKeys(exch.APIKey, exch.APISecret) + l.RESTPollingDelay = exch.RESTPollingDelay + l.Verbose = exch.Verbose + l.Websocket = exch.Websocket + l.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + l.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + l.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (l *LakeBTC) Start() { - go l.Run() + go l.Run() } - func (l *LakeBTC) SetAPIKeys(apiKey, apiSecret string) { l.Email = apiKey l.APISecret = apiSecret diff --git a/localbitcoinshttp.go b/localbitcoinshttp.go index 95f0cfad8fa..bbeadcc30d8 100644 --- a/localbitcoinshttp.go +++ b/localbitcoinshttp.go @@ -58,26 +58,26 @@ func (l *LocalBitcoins) IsEnabled() bool { return l.Enabled } -func (l *LocalBitcoins)Setup(exch Exchanges) { - if !exch.Enabled { - l.SetEnabled(false) - } else { - l.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - l.SetAPIKeys(exch.APIKey, exch.APISecret) - l.RESTPollingDelay = exch.RESTPollingDelay - l.Verbose = exch.Verbose - l.Websocket = exch.Websocket - l.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - l.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - l.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} +func (l *LocalBitcoins) Setup(exch Exchanges) { + if !exch.Enabled { + l.SetEnabled(false) + } else { + l.Enabled = true + l.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + l.SetAPIKeys(exch.APIKey, exch.APISecret) + l.RESTPollingDelay = exch.RESTPollingDelay + l.Verbose = exch.Verbose + l.Websocket = exch.Websocket + l.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + l.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + l.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (l *LocalBitcoins) Start() { - go l.Run() + go l.Run() } - func (l *LocalBitcoins) GetFee(maker bool) float64 { if maker { return l.MakerFee diff --git a/main.go b/main.go index 2d935866341..9ce75fc53e2 100644 --- a/main.go +++ b/main.go @@ -31,30 +31,27 @@ type Exchange struct { } type Bot struct { - config Config - exchange Exchange - exchanges []IBotExchange - shutdown chan bool + config Config + exchange Exchange + exchanges []IBotExchange + shutdown chan bool } var bot Bot func SetupBotConfiguration(s IBotExchange, exch Exchanges) { - if(s.GetName() == exch.Name) { - if(s.IsEnabled()) { - log.Println("Bot " + s.GetName() + " is enabled, starting") - s.Start() - } - } + s.Setup(exch) + if s.GetName() == exch.Name { + if s.IsEnabled() { + log.Printf("%s: Exchange support: %s (Authenticated API support: %s - Verbose mode: %s).\n", exch.Name, IsEnabled(exch.Enabled), IsEnabled(exch.AuthenticatedAPISupport), IsEnabled(exch.Verbose)) + s.Start() + } else { + log.Printf("%s: Exchange support: %s\n", exch.Name, IsEnabled(exch.Enabled)) + } + } } - func main() { - /// - //var anx ANX - //exchCfg := ExchangeConfig{Name: "ANX" } - - /// HandleInterrupt() log.Println("Loading config file config.json..") @@ -110,32 +107,36 @@ func main() { log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n", len(bot.config.Exchanges), GetEnabledExchanges()) log.Println("Bot Exchange support:") + bot.exchange.okcoinIntl.APIUrl = OKCOIN_API_URL + bot.exchange.okcoinChina.APIUrl = OKCOIN_API_URL_CHINA + bot.exchanges = []IBotExchange{ - &bot.exchange.anx, - &bot.exchange.kraken, - &bot.exchange.btcc, - &bot.exchange.bitstamp, - &bot.exchange.brightonpeak, - &bot.exchange.bitfinex, - &bot.exchange.btce, - &bot.exchange.btcmarkets, - &bot.exchange.coinbase, - &bot.exchange.gemini, - &bot.exchange.okcoinChina, - &bot.exchange.okcoinIntl, - &bot.exchange.itbit, - &bot.exchange.lakebtc, - &bot.exchange.localbitcoins, - &bot.exchange.poloniex, - &bot.exchange.huobi, - } - for i := 0; i < len(bot.exchanges); i++ { - if(bot.exchanges[i] != nil) { - bot.exchanges[i].SetDefaults() - log.Println("Bot: %s successfully set defaults", bot.exchanges[i].GetName()) - } - } - + &bot.exchange.anx, + &bot.exchange.kraken, + &bot.exchange.btcc, + &bot.exchange.bitstamp, + &bot.exchange.brightonpeak, + &bot.exchange.bitfinex, + &bot.exchange.btce, + &bot.exchange.btcmarkets, + &bot.exchange.coinbase, + &bot.exchange.gemini, + &bot.exchange.okcoinChina, + &bot.exchange.okcoinIntl, + &bot.exchange.itbit, + &bot.exchange.lakebtc, + &bot.exchange.localbitcoins, + &bot.exchange.poloniex, + &bot.exchange.huobi, + } + + for i := 0; i < len(bot.exchanges); i++ { + if bot.exchanges[i] != nil { + bot.exchanges[i].SetDefaults() + log.Printf("Exchange %s successfully set default settings.\n", bot.exchanges[i].GetName()) + } + } + err = RetrieveConfigCurrencyPairs(bot.config) if err != nil { @@ -143,17 +144,11 @@ func main() { } for _, exch := range bot.config.Exchanges { - if exch.Enabled { - log.Printf("%s: Exchange support: %s (Authenticated API support: %s - Verbose mode: %s).\n", exch.Name, IsEnabled(exch.Enabled), IsEnabled(exch.AuthenticatedAPISupport), IsEnabled(exch.Verbose)) - } else { - log.Printf("%s: Exchange support: %s\n", exch.Name, IsEnabled(exch.Enabled)) + for i := 0; i < len(bot.exchanges); i++ { + if bot.exchanges[i] != nil { + SetupBotConfiguration(bot.exchanges[i], exch) + } } - - for i := 0; i < len(bot.exchanges); i++ { - if(bot.exchanges[i] != nil) { - SetupBotConfiguration(bot.exchanges[i], exch) - } - } } <-bot.shutdown Shutdown() diff --git a/okcoinhttp.go b/okcoinhttp.go index f32f4028799..a0a7c6f82bc 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -177,22 +177,23 @@ func (o *OKCoin) IsEnabled() bool { } func (o *OKCoin) Setup(exch Exchanges) { - if !exch.Enabled { - o.SetEnabled(false) - } else { - o.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - o.SetAPIKeys(exch.APIKey, exch.APISecret) - o.RESTPollingDelay = exch.RESTPollingDelay - o.Verbose = exch.Verbose - o.Websocket = exch.Websocket - o.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - o.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - o.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} + if !exch.Enabled { + o.SetEnabled(false) + } else { + o.Enabled = true + o.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + o.SetAPIKeys(exch.APIKey, exch.APISecret) + o.RESTPollingDelay = exch.RESTPollingDelay + o.Verbose = exch.Verbose + o.Websocket = exch.Websocket + o.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + o.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + o.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (o *OKCoin) Start() { - go o.Run() + go o.Run() } func (o *OKCoin) SetURL(url string) { diff --git a/poloniexhttp.go b/poloniexhttp.go index b08b115813a..3c2dcd360a4 100644 --- a/poloniexhttp.go +++ b/poloniexhttp.go @@ -87,24 +87,24 @@ func (p *Poloniex) IsEnabled() bool { return p.Enabled } - func (p *Poloniex) Setup(exch Exchanges) { - if !exch.Enabled { - p.SetEnabled(false) - } else { - p.AuthenticatedAPISupport = exch.AuthenticatedAPISupport - p.SetAPIKeys(exch.APIKey, exch.APISecret) - p.RESTPollingDelay = exch.RESTPollingDelay - p.Verbose = exch.Verbose - p.Websocket = exch.Websocket - p.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") - p.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") - p.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") - } -} + if !exch.Enabled { + p.SetEnabled(false) + } else { + p.Enabled = true + p.AuthenticatedAPISupport = exch.AuthenticatedAPISupport + p.SetAPIKeys(exch.APIKey, exch.APISecret) + p.RESTPollingDelay = exch.RESTPollingDelay + p.Verbose = exch.Verbose + p.Websocket = exch.Websocket + p.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",") + p.AvailablePairs = SplitStrings(exch.AvailablePairs, ",") + p.EnabledPairs = SplitStrings(exch.EnabledPairs, ",") + } +} func (p *Poloniex) Start() { - go p.Run() + go p.Run() } func (p *Poloniex) SetAPIKeys(apiKey, apiSecret string) {