diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0cffcb34 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json \ No newline at end of file diff --git a/bitfinexhttp.go b/bitfinexhttp.go index 7811ce71..794d09b6 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -72,6 +72,8 @@ type SymbolsDetails struct { } type Bitfinex struct { + Name string + Enabled bool APIKey, APISecret string Ticker BitfinexTicker Stats []BitfinexStats @@ -80,6 +82,23 @@ type Bitfinex struct { SymbolsDetails []SymbolsDetails } +func (b *Bitfinex) SetDefaults() { + b.Name = "Bitfinex" + b.Enabled = true +} + +func (b *Bitfinex) GetName() (string) { + return b.Name +} + +func (b *Bitfinex) SetEnabled(enabled bool) { + b.Enabled = enabled +} + +func (b *Bitfinex) IsEnabled() (bool) { + return b.Enabled +} + func (b *Bitfinex) SendAuthenticatedHTTPRequest(path string, params map[string]interface{}) (err error) { request := make(map[string]interface{}) request["request"] = "/v1/" + path diff --git a/bitstamphttp.go b/bitstamphttp.go index e293d0db..9d71e418 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -36,6 +36,8 @@ const ( ) type Bitstamp struct { + Name string + Enabled bool ClientID, APIKey, APISecret string Ticker BitstampTicker Orderbook Orderbook @@ -69,6 +71,23 @@ type ConversionRate struct { Sell string } +func (b *Bitstamp) SetDefaults() { + b.Name = "Bitstamp" + b.Enabled = true +} + +func (b *Bitstamp) GetName() (string) { + return b.Name +} + +func (b *Bitstamp) SetEnabled(enabled bool) { + b.Enabled = enabled +} + +func (b *Bitstamp) IsEnabled() (bool) { + return b.Enabled +} + func (b *Bitstamp) GetTicker() (BitstampTicker) { err := SendHTTPRequest(BITSTAMP_API_URL + BITSTAMP_API_TICKER, true, &b.Ticker) diff --git a/btcchinahttp.go b/btcchinahttp.go index 9774a138..893ada00 100644 --- a/btcchinahttp.go +++ b/btcchinahttp.go @@ -22,6 +22,8 @@ const ( ) type BTCChina struct { + Name string + Enabled bool APISecret, APIKey string } @@ -38,6 +40,23 @@ type BTCChinaTicker struct { Open float64 `json:",string"` } +func (b *BTCChina) SetDefaults() { + b.Name = "BTC China" + b.Enabled = true +} + +func (b *BTCChina) GetName() (string) { + return b.Name +} + +func (b *BTCChina) SetEnabled(enabled bool) { + b.Enabled = enabled +} + +func (b *BTCChina) IsEnabled() (bool) { + return b.Enabled +} + func (b *BTCChina) GetTicker(symbol string) (BTCChinaTicker) { type Response struct { Ticker BTCChinaTicker diff --git a/btcehttp.go b/btcehttp.go index b550d874..6e93d1a3 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -25,6 +25,8 @@ const ( ) type BTCE struct { + Name string + Enabled bool APIKey, APISecret string } @@ -41,6 +43,23 @@ type BTCeTicker struct { Server_time int64 } +func (b *BTCE) SetDefaults() { + b.Name = "BTCE" + b.Enabled = true +} + +func (b *BTCE) GetName() (string) { + return b.Name +} + +func (b *BTCE) SetEnabled(enabled bool) { + b.Enabled = enabled +} + +func (b *BTCE) IsEnabled() (bool) { + return b.Enabled +} + func (b *BTCE) GetTicker(symbol string) (BTCeTicker) { type Response struct { Ticker BTCeTicker diff --git a/config.go b/config.go new file mode 100644 index 00000000..fbb8d4b9 --- /dev/null +++ b/config.go @@ -0,0 +1,31 @@ +package main + +import ( + "io/ioutil" + "encoding/json" +) + +type Config struct { + Exchanges []Exchanges +} + +type Exchanges struct { + Name string + Enabled bool + APIKey string + APISecret string + Pairs string + BaseCurrencies string +} + +func ReadConfig(path string) (Config, error) { + file, err := ioutil.ReadFile(path) + + if err != nil { + return Config{}, err + } + + cfg := Config{} + err = json.Unmarshal(file, &cfg) + return cfg, err +} diff --git a/config_example.json b/config_example.json new file mode 100644 index 00000000..27cdf689 --- /dev/null +++ b/config_example.json @@ -0,0 +1,76 @@ +{ + "Exchanges": [ + { + "Name": "Bitfinex", + "Pairs": "BTCUSD,LTCUSD,DRKUSD", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "USD", + "Enabled": true + }, + { + "Name": "Bitstamp", + "Pairs": "BTCUSD", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "USD", + "Enabled": true + }, + { + "Name": "BTC China", + "Pairs": "BTCCNY,LTCCNY,LTCBTC", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "CNY", + "Enabled": true + }, + { + "Name": "BTCE", + "Pairs": "BTCUSD,BTCRUR,BTCEUR,BTCCNH,BTCGBP,LTCBTC,LTCUSD,LTCRUR,LTCEUR,LTCCNH,LTCGBP,NMCBTC,NMCUSD,NVCBTC,NVCUSD,USDRUR,EURUSD,EURRUR,USDCNH,GDPUSD,PPCBTC,PPCUSD", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "USD,RUB,EUR,CNY,GBP", + "Enabled": true + }, + { + "Name": "Huobi", + "Pairs": "BTCCNY,LTCCNY,LTCBTC", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "CNY", + "Enabled": true + }, + { + "Name": "ITBIT", + "Pairs": "XBTUSD,XBTSGD,XBTEUR", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "USD,SGD,EUR", + "Enabled": true + }, + { + "Name": "LakeBTC", + "Pairs": "BTCCNY,LTCCNY,LTCBTC", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "CNY", + "Enabled": true + }, + { + "Name": "OKCOIN China", + "Pairs": "BTCCNY,LTCCNY", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "CNY", + "Enabled": true + }, + { + "Name": "OKCOIN International", + "Pairs": "BTCUSD,LTCUSD", + "APIKey": "Key", + "APISecret": "Secret", + "BaseCurrencies": "USD", + "Enabled": true + } + ] +} \ No newline at end of file diff --git a/currency.go b/currency.go index c66737ac..80472473 100644 --- a/currency.go +++ b/currency.go @@ -40,7 +40,6 @@ type YahooJSONResponse struct { const ( YAHOO_YQL_URL = "http://query.yahooapis.com/v1/public/yql" YAHOO_DATABASE = "store://datatables.org/alltableswithkeys" - CURRENCIES = "USD,CNY,AUD,EUR" ) @@ -48,10 +47,35 @@ var ( CurrencyStore YahooJSONResponse ErrCurrencyDataNotFetched = errors.New("Yahoo currency data has not been fetched yet.") ErrCurrencyNotFound = errors.New("Unable to find specified currency.") + ErrQueryingYahoo = errors.New("Unable to query Yahoo currency values.") ) -func MakeCurrencyPairs() (string) { - currencies := strings.Split(CURRENCIES, ",") +func RetrieveConfigCurrencyPairs(config Config) (error) { + currencyPairs := "" + for _, exchange := range config.Exchanges { + if (exchange.Enabled) { + result := strings.Split(exchange.BaseCurrencies, ",") + + for _, s := range result { + if (!strings.Contains(currencyPairs, s)) { + currencyPairs += s + "," + } + } + } + } + currencyPairs = currencyPairs[0:len(currencyPairs)-1] + err := QueryYahooCurrencyValues(currencyPairs) + + if err != nil { + return ErrQueryingYahoo + } + + log.Println("Fetched currency value data.") + return nil +} + +func MakecurrencyPairs(supportedCurrencies string) (string) { + currencies := strings.Split(supportedCurrencies, ",") pairs := "" count := len(currencies) for i := 0; i < count; i++ { @@ -79,8 +103,8 @@ func ConvertCurrency(amount float64, from, to string) (float64, error) { return 0, ErrCurrencyNotFound } -func QueryYahooCurrencyValues() (error) { - currencyPairs := MakeCurrencyPairs() +func QueryYahooCurrencyValues(currencies string) (error) { + currencyPairs := MakecurrencyPairs(currencies) log.Printf("Supported currency pairs: %s\n", currencyPairs) values := url.Values{} @@ -88,7 +112,6 @@ func QueryYahooCurrencyValues() (error) { values.Set("format", "json") values.Set("env", YAHOO_DATABASE) path := YAHOO_YQL_URL+"?"+values.Encode() - log.Println("Sending request to: " + path) req, err := http.NewRequest("GET", path, strings.NewReader("")) if err != nil { diff --git a/huobihttp.go b/huobihttp.go index 61c958ff..937ec907 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -18,6 +18,8 @@ const ( ) type HUOBI struct { + Name string + Enabled bool AccessKey, SecretKey string } @@ -35,6 +37,23 @@ type HuobiTickerResponse struct { Ticker HuobiTicker } +func (h *HUOBI) SetDefaults() { + h.Name = "Huobi" + h.Enabled = true +} + +func (h *HUOBI) GetName() (string) { + return h.Name +} + +func (h *HUOBI) SetEnabled(enabled bool) { + h.Enabled = enabled +} + +func (h *HUOBI) IsEnabled() (bool) { + return h.Enabled +} + func (h *HUOBI) GetTicker(symbol string) (HuobiTicker) { resp := HuobiTickerResponse{} path := fmt.Sprintf("http://market.huobi.com/staticmarket/ticker_%s_json.js", symbol) diff --git a/itbithttp.go b/itbithttp.go index e76dd3ec..d8b684cf 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -21,6 +21,8 @@ const ( ) type ItBit struct { + Name string + Enabled bool ClientKey, APISecret, UserID string } @@ -44,6 +46,23 @@ type ItBitTicker struct { ServertimeUTC string } +func (i *ItBit) SetDefaults() { + i.Name = "ITBIT" + i.Enabled = true +} + +func (i *ItBit) GetName() (string) { + return i.Name +} + +func (i *ItBit) SetEnabled(enabled bool) { + i.Enabled = enabled +} + +func (i *ItBit) IsEnabled() (bool) { + return i.Enabled +} + func (i *ItBit) GetTicker(currency string) (ItBitTicker) { path := ITBIT_API_URL + "/markets/" + currency + "/ticker" var itbitTicker ItBitTicker diff --git a/lakebtchttp.go b/lakebtchttp.go index d263e01e..327449ef 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -30,6 +30,8 @@ const ( ) type LakeBTC struct { + Name string + Enabled bool Email, APISecret string } @@ -46,6 +48,23 @@ type LakeBTCTickerResponse struct { CNY LakeBTCTicker } +func (l *LakeBTC) SetDefaults() { + l.Name = "LakeBTC" + l.Enabled = true +} + +func (l *LakeBTC) GetName() (string) { + return l.Name +} + +func (l *LakeBTC) SetEnabled(enabled bool) { + l.Enabled = enabled +} + +func (l *LakeBTC) IsEnabled() (bool) { + return l.Enabled +} + func (l *LakeBTC) GetTicker() (LakeBTCTickerResponse) { response := LakeBTCTickerResponse{} err := SendHTTPRequest(LAKEBTC_API_URL + LAKEBTC_TICKER, true, &response) diff --git a/main.go b/main.go index 5e4ec65e..88e15e5e 100644 --- a/main.go +++ b/main.go @@ -21,145 +21,263 @@ type Exchange struct { func main() { log.Println("Bot started") - exchange := Exchange{} - exchange.okcoinChina.SetURL(OKCOIN_API_URL_CHINA) - exchange.okcoinIntl.SetURL(OKCOIN_API_URL) - err := QueryYahooCurrencyValues() + log.Println("Loading config file config.json..") + config, err := ReadConfig("config.json") if err != nil { - log.Fatalln(err) + log.Println("Fatal error opening config.json file. Error: ", err) return } - + + log.Println("Config file loaded.") + + enabledExchanges := 0 + for _, exch := range config.Exchanges { + if exch.Enabled { + enabledExchanges++ + } + } + + if enabledExchanges == 0 { + log.Println("Bot started with no exchanges supported. Exiting.") + return + } + + log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n", len(config.Exchanges), enabledExchanges) + log.Println("Bot exchange support:") + + exchange := Exchange{} + exchange.btcchina.SetDefaults() + exchange.bitstamp.SetDefaults() + exchange.bitfinex.SetDefaults() + exchange.btce.SetDefaults() + exchange.okcoinChina.SetURL(OKCOIN_API_URL_CHINA) + exchange.okcoinChina.SetDefaults() + exchange.okcoinIntl.SetURL(OKCOIN_API_URL) + exchange.okcoinIntl.SetDefaults() + exchange.itbit.SetDefaults() + exchange.lakebtc.SetDefaults() + exchange.huobi.SetDefaults() + + for _, exch := range config.Exchanges { + if exchange.btcchina.GetName() == exch.Name { + if !exch.Enabled { + exchange.btcchina.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.bitstamp.GetName() == exch.Name { + if !exch.Enabled { + exchange.bitstamp.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.bitfinex.GetName() == exch.Name { + if !exch.Enabled { + exchange.bitfinex.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.btce.GetName() == exch.Name { + if !exch.Enabled { + exchange.btce.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.okcoinChina.GetName() == exch.Name { + if !exch.Enabled { + exchange.okcoinChina.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.okcoinIntl.GetName() == exch.Name { + if !exch.Enabled { + exchange.okcoinIntl.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.itbit.GetName() == exch.Name { + if !exch.Enabled { + exchange.itbit.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.lakebtc.GetName() == exch.Name { + if !exch.Enabled { + exchange.lakebtc.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } else if exchange.huobi.GetName() == exch.Name { + if !exch.Enabled { + exchange.huobi.SetEnabled(false) + log.Printf("%s disabled.\n", exch.Name) + } else { + log.Printf("%s enabled.\n", exch.Name) + } + } + } + + err = RetrieveConfigCurrencyPairs(config) + + if err != nil { + log.Println("Fatal error retrieving config currency pairs. Error: ", err) + } + //temp until proper asynchronous method of getting pricing/order books is coded for { //spot + if exchange.lakebtc.IsEnabled() { + go func() { + LakeBTCTickerResponse := exchange.lakebtc.GetTicker() + log.Printf("LakeBTC USD: Last %f (%f) High %f (%f) Low %f (%f)\n", LakeBTCTickerResponse.USD.Last, LakeBTCTickerResponse.CNY.Last, LakeBTCTickerResponse.USD.High, LakeBTCTickerResponse.CNY.High, LakeBTCTickerResponse.USD.Low, LakeBTCTickerResponse.CNY.Low) + }() + } - go func() { - LakeBTCTickerResponse := exchange.lakebtc.GetTicker() - log.Printf("LakeBTC USD: Last %f (%f) High %f (%f) Low %f (%f)\n", LakeBTCTickerResponse.USD.Last, LakeBTCTickerResponse.CNY.Last, LakeBTCTickerResponse.USD.High, LakeBTCTickerResponse.CNY.High, LakeBTCTickerResponse.USD.Low, LakeBTCTickerResponse.CNY.Low) - }() + if exchange.btcchina.IsEnabled() { + go func() { + BTCChinaBTC := exchange.btcchina.GetTicker("btccny") + BTCChinaBTCLastUSD, _ := ConvertCurrency(BTCChinaBTC.Last, "CNY", "USD") + BTCChinaBTCHighUSD, _ := ConvertCurrency(BTCChinaBTC.High, "CNY", "USD") + BTCChinaBTCLowUSD, _ := ConvertCurrency(BTCChinaBTC.Low, "CNY", "USD") + log.Printf("BTCChina BTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", BTCChinaBTCLastUSD, BTCChinaBTC.Last, BTCChinaBTCHighUSD, BTCChinaBTC.High, BTCChinaBTCLowUSD, BTCChinaBTC.Low, BTCChinaBTC.Vol) + }() - go func() { - BTCChinaBTC := exchange.btcchina.GetTicker("btccny") - BTCChinaBTCLastUSD, _ := ConvertCurrency(BTCChinaBTC.Last, "CNY", "USD") - BTCChinaBTCHighUSD, _ := ConvertCurrency(BTCChinaBTC.High, "CNY", "USD") - BTCChinaBTCLowUSD, _ := ConvertCurrency(BTCChinaBTC.Low, "CNY", "USD") - log.Printf("BTCChina BTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", BTCChinaBTCLastUSD, BTCChinaBTC.Last, BTCChinaBTCHighUSD, BTCChinaBTC.High, BTCChinaBTCLowUSD, BTCChinaBTC.Low, BTCChinaBTC.Vol) - }() - go func() { - BTCChinaLTC := exchange.btcchina.GetTicker("ltccny") - BTCChinaLTCLastUSD, _ := ConvertCurrency(BTCChinaLTC.Last, "CNY", "USD") - BTCChinaLTCHighUSD, _ := ConvertCurrency(BTCChinaLTC.High, "CNY", "USD") - BTCChinaLTCLowUSD, _ := ConvertCurrency(BTCChinaLTC.Low, "CNY", "USD") - log.Printf("BTCChina LTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", BTCChinaLTCLastUSD, BTCChinaLTC.Last, BTCChinaLTCHighUSD, BTCChinaLTC.High, BTCChinaLTCLowUSD, BTCChinaLTC.Low, BTCChinaLTC.Vol) - }() + go func() { + BTCChinaLTC := exchange.btcchina.GetTicker("ltccny") + BTCChinaLTCLastUSD, _ := ConvertCurrency(BTCChinaLTC.Last, "CNY", "USD") + BTCChinaLTCHighUSD, _ := ConvertCurrency(BTCChinaLTC.High, "CNY", "USD") + BTCChinaLTCLowUSD, _ := ConvertCurrency(BTCChinaLTC.Low, "CNY", "USD") + log.Printf("BTCChina LTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", BTCChinaLTCLastUSD, BTCChinaLTC.Last, BTCChinaLTCHighUSD, BTCChinaLTC.High, BTCChinaLTCLowUSD, BTCChinaLTC.Low, BTCChinaLTC.Vol) + }() + } - go func() { - HuobiBTC := exchange.huobi.GetTicker("btc") - HuobiBTCLastUSD, _ := ConvertCurrency(HuobiBTC.Last, "CNY", "USD") - HuobiBTCHighUSD, _ := ConvertCurrency(HuobiBTC.High, "CNY", "USD") - HuobiBTCLowUSD, _ := ConvertCurrency(HuobiBTC.Low, "CNY", "USD") - log.Printf("Huobi BTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", HuobiBTCLastUSD, HuobiBTC.Last, HuobiBTCHighUSD, HuobiBTC.High, HuobiBTCLowUSD, HuobiBTC.Low, HuobiBTC.Vol) - }() + if exchange.huobi.IsEnabled() { + go func() { + HuobiBTC := exchange.huobi.GetTicker("btc") + HuobiBTCLastUSD, _ := ConvertCurrency(HuobiBTC.Last, "CNY", "USD") + HuobiBTCHighUSD, _ := ConvertCurrency(HuobiBTC.High, "CNY", "USD") + HuobiBTCLowUSD, _ := ConvertCurrency(HuobiBTC.Low, "CNY", "USD") + log.Printf("Huobi BTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", HuobiBTCLastUSD, HuobiBTC.Last, HuobiBTCHighUSD, HuobiBTC.High, HuobiBTCLowUSD, HuobiBTC.Low, HuobiBTC.Vol) + }() - go func() { - HuobiLTC := exchange.huobi.GetTicker("btc") - HuobiLTCLastUSD, _ := ConvertCurrency(HuobiLTC.Last, "CNY", "USD") - HuobiLTCHighUSD, _ := ConvertCurrency(HuobiLTC.High, "CNY", "USD") - HuobiLTCLowUSD, _ := ConvertCurrency(HuobiLTC.Low, "CNY", "USD") - log.Printf("Huobi BTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", HuobiLTCLastUSD, HuobiLTC.Last, HuobiLTCHighUSD, HuobiLTC.High, HuobiLTCLowUSD, HuobiLTC.Low, HuobiLTC.Vol) - }() + go func() { + HuobiLTC := exchange.huobi.GetTicker("btc") + HuobiLTCLastUSD, _ := ConvertCurrency(HuobiLTC.Last, "CNY", "USD") + HuobiLTCHighUSD, _ := ConvertCurrency(HuobiLTC.High, "CNY", "USD") + HuobiLTCLowUSD, _ := ConvertCurrency(HuobiLTC.Low, "CNY", "USD") + log.Printf("Huobi BTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", HuobiLTCLastUSD, HuobiLTC.Last, HuobiLTCHighUSD, HuobiLTC.High, HuobiLTCLowUSD, HuobiLTC.Low, HuobiLTC.Vol) + }() + } - go func() { - ItbitBTC := exchange.itbit.GetTicker("XBTUSD") - log.Printf("ItBit BTC: Last %f High %f Low %f Volume %f\n", ItbitBTC.LastPrice, ItbitBTC.High24h, ItbitBTC.Low24h, ItbitBTC.Volume24h) - }() + if exchange.itbit.IsEnabled() { + go func() { + ItbitBTC := exchange.itbit.GetTicker("XBTUSD") + log.Printf("ItBit BTC: Last %f High %f Low %f Volume %f\n", ItbitBTC.LastPrice, ItbitBTC.High24h, ItbitBTC.Low24h, ItbitBTC.Volume24h) + }() + } - go func() { - BitstampBTC := exchange.bitstamp.GetTicker() - log.Printf("Bitstamp BTC: Last %f High %f Low %f Volume %f\n", BitstampBTC.Last, BitstampBTC.High, BitstampBTC.Low, BitstampBTC.Volume) - }() + if exchange.bitstamp.IsEnabled() { + go func() { + BitstampBTC := exchange.bitstamp.GetTicker() + log.Printf("Bitstamp BTC: Last %f High %f Low %f Volume %f\n", BitstampBTC.Last, BitstampBTC.High, BitstampBTC.Low, BitstampBTC.Volume) + }() + } - go func() { - BitfinexLTC := exchange.bitfinex.GetTicker("ltcusd") - log.Printf("Bitfinex LTC: Last %f High %f Low %f Volume %f\n", BitfinexLTC.Last, BitfinexLTC.High, BitfinexLTC.Low, BitfinexLTC.Volume) - }() + if exchange.bitfinex.IsEnabled() { + go func() { + BitfinexLTC := exchange.bitfinex.GetTicker("ltcusd") + log.Printf("Bitfinex LTC: Last %f High %f Low %f Volume %f\n", BitfinexLTC.Last, BitfinexLTC.High, BitfinexLTC.Low, BitfinexLTC.Volume) + }() - go func() { - BitfinexBTC := exchange.bitfinex.GetTicker("btcusd") - log.Printf("Bitfinex BTC: Last %f High %f Low %f Volume %f\n", BitfinexBTC.Last, BitfinexBTC.High, BitfinexBTC.Low, BitfinexBTC.Volume) - }() + go func() { + BitfinexBTC := exchange.bitfinex.GetTicker("btcusd") + log.Printf("Bitfinex BTC: Last %f High %f Low %f Volume %f\n", BitfinexBTC.Last, BitfinexBTC.High, BitfinexBTC.Low, BitfinexBTC.Volume) + }() + } + + if exchange.btce.IsEnabled() { + go func() { + BTCeBTC := exchange.btce.GetTicker("btc_usd") + log.Printf("BTC-e BTC: Last %f High %f Low %f Volume %f\n", BTCeBTC.Last, BTCeBTC.High, BTCeBTC.Low, BTCeBTC.Vol_cur) + }() + + go func() { + BTCeLTC := exchange.btce.GetTicker("ltc_usd") + log.Printf("BTC-e LTC: Last %f High %f Low %f Volume %f\n", BTCeLTC.Last, BTCeLTC.High, BTCeLTC.Low, BTCeLTC.Vol_cur) + }() + } + + if exchange.okcoinChina.IsEnabled() { + go func() { + OKCoinChinaBTC := exchange.okcoinChina.GetTicker("btc_cny") + OKCoinChinaBTCLastUSD, _ := ConvertCurrency(OKCoinChinaBTC.Last, "CNY", "USD") + OKCoinChinaBTCHighUSD, _ := ConvertCurrency(OKCoinChinaBTC.High, "CNY", "USD") + OKCoinChinaBTCLowUSD, _ := ConvertCurrency(OKCoinChinaBTC.Low, "CNY", "USD") + log.Printf("OKCoin China: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", OKCoinChinaBTCLastUSD, OKCoinChinaBTC.Last, OKCoinChinaBTCHighUSD, OKCoinChinaBTC.High, OKCoinChinaBTCLowUSD, OKCoinChinaBTC.Low, OKCoinChinaBTC.Vol) + }() + + go func() { + OKCoinChinaLTC := exchange.okcoinChina.GetTicker("ltc_cny") + OKCoinChinaLTCLastUSD, _ := ConvertCurrency(OKCoinChinaLTC.Last, "CNY", "USD") + OKCoinChinaLTCHighUSD, _ := ConvertCurrency(OKCoinChinaLTC.High, "CNY", "USD") + OKCoinChinaLTCLowUSD, _ := ConvertCurrency(OKCoinChinaLTC.Low, "CNY", "USD") + log.Printf("OKCoin China: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", OKCoinChinaLTCLastUSD, OKCoinChinaLTC.Last, OKCoinChinaLTCHighUSD, OKCoinChinaLTC.High, OKCoinChinaLTCLowUSD, OKCoinChinaLTC.Low, OKCoinChinaLTC.Vol) + }() + } + + if exchange.okcoinIntl.IsEnabled() { + go func() { + OKCoinChinaIntlBTC := exchange.okcoinIntl.GetTicker("btc_usd") + log.Printf("OKCoin Intl BTC: Last %f High %f Low %f Volume %f\n", OKCoinChinaIntlBTC.Last, OKCoinChinaIntlBTC.High, OKCoinChinaIntlBTC.Low, OKCoinChinaIntlBTC.Vol) + }() + + go func() { + OKCoinChinaIntlLTC := exchange.okcoinIntl.GetTicker("ltc_usd") + log.Printf("OKCoin Intl LTC: Last %f High %f Low %f Volume %f\n", OKCoinChinaIntlLTC.Last, OKCoinChinaIntlLTC.High, OKCoinChinaIntlLTC.Low, OKCoinChinaIntlLTC.Vol) + }() - go func() { - BTCeBTC := exchange.btce.GetTicker("btc_usd") - log.Printf("BTC-e BTC: Last %f High %f Low %f Volume %f\n", BTCeBTC.Last, BTCeBTC.High, BTCeBTC.Low, BTCeBTC.Vol_cur) - }() - - go func() { - BTCeLTC := exchange.btce.GetTicker("ltc_usd") - log.Printf("BTC-e LTC: Last %f High %f Low %f Volume %f\n", BTCeLTC.Last, BTCeLTC.High, BTCeLTC.Low, BTCeLTC.Vol_cur) - }() - - go func() { - OKCoinChinaBTC := exchange.okcoinChina.GetTicker("btc_cny") - OKCoinChinaBTCLastUSD, _ := ConvertCurrency(OKCoinChinaBTC.Last, "CNY", "USD") - OKCoinChinaBTCHighUSD, _ := ConvertCurrency(OKCoinChinaBTC.High, "CNY", "USD") - OKCoinChinaBTCLowUSD, _ := ConvertCurrency(OKCoinChinaBTC.Low, "CNY", "USD") - log.Printf("OKCoin China: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", OKCoinChinaBTCLastUSD, OKCoinChinaBTC.Last, OKCoinChinaBTCHighUSD, OKCoinChinaBTC.High, OKCoinChinaBTCLowUSD, OKCoinChinaBTC.Low, OKCoinChinaBTC.Vol) - }() - - go func() { - OKCoinChinaLTC := exchange.okcoinChina.GetTicker("ltc_cny") - OKCoinChinaLTCLastUSD, _ := ConvertCurrency(OKCoinChinaLTC.Last, "CNY", "USD") - OKCoinChinaLTCHighUSD, _ := ConvertCurrency(OKCoinChinaLTC.High, "CNY", "USD") - OKCoinChinaLTCLowUSD, _ := ConvertCurrency(OKCoinChinaLTC.Low, "CNY", "USD") - log.Printf("OKCoin China: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", OKCoinChinaLTCLastUSD, OKCoinChinaLTC.Last, OKCoinChinaLTCHighUSD, OKCoinChinaLTC.High, OKCoinChinaLTCLowUSD, OKCoinChinaLTC.Low, OKCoinChinaLTC.Vol) - }() - - go func() { - OKCoinChinaIntlBTC := exchange.okcoinIntl.GetTicker("btc_usd") - log.Printf("OKCoin Intl BTC: Last %f High %f Low %f Volume %f\n", OKCoinChinaIntlBTC.Last, OKCoinChinaIntlBTC.High, OKCoinChinaIntlBTC.Low, OKCoinChinaIntlBTC.Vol) - }() - - go func() { - OKCoinChinaIntlLTC := exchange.okcoinIntl.GetTicker("ltc_usd") - log.Printf("OKCoin Intl LTC: Last %f High %f Low %f Volume %f\n", OKCoinChinaIntlLTC.Last, OKCoinChinaIntlLTC.High, OKCoinChinaIntlLTC.Low, OKCoinChinaIntlLTC.Vol) - }() - // futures + go func() { + OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("btc_usd", "this_week") + log.Printf("OKCoin BTC Futures (weekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) + }() - go func() { - OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("btc_usd", "this_week") - log.Printf("OKCoin BTC Futures (weekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) - }() + go func() { + OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("ltc_usd", "this_week") + log.Printf("OKCoin LTC Futures (weekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) + }() - go func() { - OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("ltc_usd", "this_week") - log.Printf("OKCoin LTC Futures (weekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) - }() + go func() { + OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("btc_usd", "next_week") + log.Printf("OKCoin BTC Futures (biweekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) + }() - go func() { - OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("btc_usd", "next_week") - log.Printf("OKCoin BTC Futures (biweekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) - }() + go func() { + OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("ltc_usd", "next_week") + log.Printf("OKCoin LTC Futures (biweekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) + }() - go func() { - OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("ltc_usd", "next_week") - log.Printf("OKCoin LTC Futures (biweekly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) - }() + go func() { + OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("btc_usd", "quarter") + log.Printf("OKCoin BTC Futures (quarterly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) + }() - go func() { - OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("btc_usd", "quarter") - log.Printf("OKCoin BTC Futures (quarterly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) - }() - - go func() { - OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("ltc_usd", "quarter") - log.Printf("OKCoin LTC Futures (quarterly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) - }() + go func() { + OKCoinFuturesBTC := exchange.okcoinIntl.GetFuturesTicker("ltc_usd", "quarter") + log.Printf("OKCoin LTC Futures (quarterly): Last %f High %f Low %f Volume %f\n", OKCoinFuturesBTC.Last, OKCoinFuturesBTC.High, OKCoinFuturesBTC.Low, OKCoinFuturesBTC.Vol) + }() + } time.Sleep(time.Second * 15) cmd := exec.Command("cmd", "/c", "cls") diff --git a/okcoinhttp.go b/okcoinhttp.go index a81885b1..ef9420d3 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -18,6 +18,8 @@ const ( ) type OKCoin struct { + Name string + Enabled bool APIUrl, PartnerID, SecretKey string } @@ -50,6 +52,27 @@ type OKCoinFuturesTickerResponse struct { Ticker OKCoinFuturesTicker } +func (o *OKCoin) SetDefaults() { + if (o.APIUrl == OKCOIN_API_URL) { + o.Name = "OKCOIN International" + } else if (o.APIUrl == OKCOIN_API_URL_CHINA) { + o.Name = "OKCOIN China" + } + o.Enabled = true +} + +func (o *OKCoin) GetName() (string) { + return o.Name +} + +func (o *OKCoin) SetEnabled(enabled bool) { + o.Enabled = enabled +} + +func (o *OKCoin) IsEnabled() (bool) { + return o.Enabled +} + func (o *OKCoin) SetURL(url string) { o.APIUrl = url }