diff --git a/bitfinexhttp.go b/bitfinexhttp.go index df855040..059efe9a 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -179,6 +179,24 @@ func (b *Bitfinex) SetAPIKeys(apiKey, apiSecret string) { b.APISecret = apiSecret } +func (b *Bitfinex) Run() { + b.GetAccountFeeInfo() + b.GetAccountBalance() + + for b.Enabled { + go func() { + BitfinexLTC := b.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 := b.GetTicker("btcusd") + log.Printf("Bitfinex BTC: Last %f High %f Low %f Volume %f\n", BitfinexBTC.Last, BitfinexBTC.High, BitfinexBTC.Low, BitfinexBTC.Volume) + }() + time.Sleep(time.Second * 10) + } +} + func (b *Bitfinex) GetFee(maker bool, symbol string) (float64, error) { for _, i := range b.Fees { if symbol == i.Currency { diff --git a/bitstamphttp.go b/bitstamphttp.go index e94264d7..48994e20 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -108,6 +108,18 @@ func (b *Bitstamp) SetAPIKeys(clientID, apiKey, apiSecret string) { b.APISecret = apiSecret } +func (b *Bitstamp) Run() { + b.GetBalance() + + for b.Enabled { + go func() { + BitstampBTC := b.GetTicker() + log.Printf("Bitstamp BTC: Last %f High %f Low %f Volume %f\n", BitstampBTC.Last, BitstampBTC.High, BitstampBTC.Low, BitstampBTC.Volume) + }() + time.Sleep(time.Second * 10) + } +} + func (b *Bitstamp) GetTicker() (BitstampTicker) { err := SendHTTPGetRequest(BITSTAMP_API_URL + BITSTAMP_API_TICKER, true, &b.Ticker) diff --git a/btcchinahttp.go b/btcchinahttp.go index b9ad6ae6..a927c2e4 100644 --- a/btcchinahttp.go +++ b/btcchinahttp.go @@ -194,6 +194,27 @@ func (b *BTCChina) GetFee() (float64) { return b.Fee } +func (b *BTCChina) Run() { + for b.Enabled { + go func() { + BTCChinaBTC := b.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 := b.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) + }() + time.Sleep(time.Second * 10) + } +} + func (b *BTCChina) GetTicker(symbol string) (BTCChinaTicker) { type Response struct { Ticker BTCChinaTicker diff --git a/btcehttp.go b/btcehttp.go index d853d194..04b318bc 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -87,6 +87,21 @@ func (b *BTCE) GetFee() (float64) { return b.Fee } +func (b *BTCE) Run() { + for b.Enabled { + go func() { + BTCeBTC := b.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 := b.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) + }() + time.Sleep(time.Second * 10) + } +} + func (b *BTCE) GetInfo() { req := fmt.Sprintf("%s/%s/%s/", BTCE_API_PUBLIC_URL, BTCE_API_PUBLIC_VERSION, BTCE_INFO) err := SendHTTPGetRequest(req, true, nil) diff --git a/btcmarkets.go b/btcmarkets.go index 9474b764..7b73e3ff 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -58,6 +58,27 @@ func (b *BTCMarkets) GetFee() (float64) { return b.Fee } +func (b *BTCMarkets) Run() { + for b.Enabled { + go func() { + BTCMarketsBTC := b.GetTicker("BTC") + BTCMarketsBTCLastUSD, _ := ConvertCurrency(BTCMarketsBTC.LastPrice, "AUD", "USD") + BTCMarketsBTCBestBidUSD, _ := ConvertCurrency(BTCMarketsBTC.BestBID, "AUD", "USD") + BTCMarketsBTCBestAskUSD, _ := ConvertCurrency(BTCMarketsBTC.BestAsk, "AUD", "USD") + log.Printf("BTC Markets BTC: Last %f (%f) Bid %f (%f) Ask %f (%f)\n", BTCMarketsBTCLastUSD, BTCMarketsBTC.LastPrice, BTCMarketsBTCBestBidUSD, BTCMarketsBTC.BestBID, BTCMarketsBTCBestAskUSD, BTCMarketsBTC.BestAsk) + }() + + go func() { + BTCMarketsLTC := b.GetTicker("LTC") + BTCMarketsLTCLastUSD, _ := ConvertCurrency(BTCMarketsLTC.LastPrice, "AUD", "USD") + BTCMarketsLTCBestBidUSD, _ := ConvertCurrency(BTCMarketsLTC.BestBID, "AUD", "USD") + BTCMarketsLTCBestAskUSD, _ := ConvertCurrency(BTCMarketsLTC.BestAsk, "AUD", "USD") + log.Printf("BTC Markets LTC: Last %f (%f) Bid %f (%f) Ask %f (%f)", BTCMarketsLTCLastUSD, BTCMarketsLTC.LastPrice, BTCMarketsLTCBestBidUSD, BTCMarketsLTC.BestBID, BTCMarketsLTCBestAskUSD, BTCMarketsLTC.BestAsk) + }() + time.Sleep(time.Second * 10) + } +} + func (b *BTCMarkets) GetTicker(symbol string) (BTCMarketsTicker) { ticker := BTCMarketsTicker{} path := fmt.Sprintf("/market/%s/AUD/tick", symbol) diff --git a/coinbase.go b/coinbase.go index a2557db1..d812ec34 100644 --- a/coinbase.go +++ b/coinbase.go @@ -2,6 +2,7 @@ package main import ( "log" + "time" "fmt" "strconv" "net/url" @@ -108,6 +109,17 @@ func (c *Coinbase) GetFee(maker bool) (float64) { } } +func (c *Coinbase) Run() { + for c.Enabled { + go func() { + CoinbaseStats := c.GetStats("BTC-USD") + CoinbaseTicker := c.GetTicker("BTC-USD") + log.Printf("Coinbase BTC: Last %f High %f Low %f Volume %f\n", CoinbaseTicker.Price, CoinbaseStats.High, CoinbaseStats.Low, CoinbaseStats.Volume) + }() + time.Sleep(time.Second * 10) + } +} + func (c *Coinbase) SetAPIKeys(password, apiKey, apiSecret string) { c.Password = password c.APIKey = apiKey diff --git a/huobihttp.go b/huobihttp.go index 1f436771..812e4faf 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -64,6 +64,27 @@ func (h *HUOBI) GetFee() (float64) { return h.Fee } +func (h *HUOBI) Run() { + for h.Enabled { + go func() { + HuobiBTC := h.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 := h.GetTicker("ltc") + HuobiLTCLastUSD, _ := ConvertCurrency(HuobiLTC.Last, "CNY", "USD") + HuobiLTCHighUSD, _ := ConvertCurrency(HuobiLTC.High, "CNY", "USD") + HuobiLTCLowUSD, _ := ConvertCurrency(HuobiLTC.Low, "CNY", "USD") + log.Printf("Huobi LTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", HuobiLTCLastUSD, HuobiLTC.Last, HuobiLTCHighUSD, HuobiLTC.High, HuobiLTCLowUSD, HuobiLTC.Low, HuobiLTC.Vol) + }() + time.Sleep(time.Second * 10) + } +} + 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 dacfbcbb..21b3fcd7 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -76,6 +76,16 @@ func (i *ItBit) GetFee(maker bool) (float64) { } } +func (i *ItBit) Run() { + for i.Enabled { + go func() { + ItbitBTC := i.GetTicker("XBTUSD") + log.Printf("ItBit BTC: Last %f High %f Low %f Volume %f\n", ItbitBTC.LastPrice, ItbitBTC.High24h, ItbitBTC.Low24h, ItbitBTC.Volume24h) + }() + time.Sleep(time.Second * 10) + } +} + func (i *ItBit) GetTicker(currency string) (ItBitTicker) { path := ITBIT_API_URL + "/markets/" + currency + "/ticker" var itbitTicker ItBitTicker diff --git a/kraken.go b/kraken.go index 01aea4a7..3878c660 100644 --- a/kraken.go +++ b/kraken.go @@ -83,6 +83,20 @@ func (k *Kraken) GetFee(cryptoTrade bool) (float64) { } } +func (k *Kraken) Run() { + for k.Enabled { + go func() { + KrakenBTC := k.GetTicker("XBTUSD") + log.Printf("Kraken BTC: %v\n", KrakenBTC) + }() + go func() { + KrakenLTC := k.GetTicker("LTCUSD") + log.Printf("Kraken LTC: %v\n", KrakenLTC) + }() + time.Sleep(time.Second * 10) + } +} + func (k *Kraken) GetServerTime() { result, err := k.SendKrakenRequest(KRAKEN_SERVER_TIME) diff --git a/lakebtchttp.go b/lakebtchttp.go index 1ce14862..a760ebbb 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -79,6 +79,16 @@ func (l *LakeBTC) GetFee(maker bool) (float64) { } } +func (l *LakeBTC) Run() { + for l.Enabled { + go func() { + LakeBTCTickerResponse := l.GetTicker() + log.Printf("LakeBTC USD: Last %f (%f) High %f (%f) Low %f (%f) Volume US %f (CNY %f)\n", LakeBTCTickerResponse.USD.Last, LakeBTCTickerResponse.CNY.Last, LakeBTCTickerResponse.USD.High, LakeBTCTickerResponse.CNY.High, LakeBTCTickerResponse.USD.Low, LakeBTCTickerResponse.CNY.Low, LakeBTCTickerResponse.USD.Volume, LakeBTCTickerResponse.CNY.Volume) + }() + time.Sleep(time.Second * 10) + } +} + func (l *LakeBTC) GetTicker() (LakeBTCTickerResponse) { response := LakeBTCTickerResponse{} err := SendHTTPGetRequest(LAKEBTC_API_URL + LAKEBTC_TICKER, true, &response) diff --git a/main.go b/main.go index b5c84c0c..ccb66642 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,8 @@ package main import ( "log" - "time" "os" "errors" - "os/exec" "os/signal" "syscall" ) @@ -28,32 +26,11 @@ type Exchange struct { type Bot struct { config Config exchange Exchange + shutdown chan bool } var bot Bot -func HandleInterrupt() { - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt, syscall.SIGTERM) - go func() { - sig := <-c - log.Printf("Captured %v.", sig) - Shutdown() - log.Println("Exiting.") - os.Exit(1) - }() -} - -func Shutdown() { - err := SaveConfig() - - if err != nil { - log.Println("Unable to save config.") - } - - log.Println("Config file saved successfully.") -} - func main() { HandleInterrupt() log.Println("Loading config file config.json..") @@ -115,6 +92,12 @@ func main() { bot.exchange.lakebtc.SetDefaults() bot.exchange.huobi.SetDefaults() + err = RetrieveConfigCurrencyPairs(bot.config) + + if err != nil { + log.Println("Fatal error retrieving config currency pairs. Error: ", err) + } + for _, exch := range bot.config.Exchanges { if bot.exchange.btcchina.GetName() == exch.Name { if !exch.Enabled { @@ -123,10 +106,12 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.btcchina.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.btcchina.Run() if exch.Verbose { bot.exchange.btcchina.Verbose = true log.Printf("%s Verbose output enabled.\n", exch.Name) + go bot.exchange.btcchina.Run() } else { log.Printf("%s Verbose output disabled.\n", exch.Name) } @@ -138,7 +123,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.bitstamp.SetAPIKeys(exch.ClientID, exch.APIKey, exch.APISecret) - bot.exchange.bitstamp.GetBalance() + go bot.exchange.bitstamp.Run() if exch.Verbose { bot.exchange.bitstamp.Verbose = true @@ -154,6 +139,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.bitfinex.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.bitfinex.Run() if exch.Verbose { bot.exchange.bitfinex.Verbose = true @@ -161,8 +147,6 @@ func main() { } else { log.Printf("%s Verbose output disabled.\n", exch.Name) } - bot.exchange.bitfinex.GetAccountFeeInfo() - bot.exchange.bitfinex.GetAccountBalance() } } else if bot.exchange.btce.GetName() == exch.Name { if !exch.Enabled { @@ -171,6 +155,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.btce.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.btce.Run() if exch.Verbose { bot.exchange.btce.Verbose = true @@ -186,6 +171,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.btcmarkets.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.btcmarkets.Run() if exch.Verbose { bot.exchange.btcmarkets.Verbose = true @@ -201,6 +187,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.coinbase.SetAPIKeys(exch.ClientID, exch.APIKey, exch.APISecret) + go bot.exchange.coinbase.Run() if exch.Verbose { bot.exchange.coinbase.Verbose = true @@ -216,6 +203,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.okcoinChina.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.okcoinChina.Run() if exch.Verbose { bot.exchange.okcoinChina.Verbose = true @@ -231,6 +219,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.okcoinIntl.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.okcoinIntl.Run() if exch.Verbose { bot.exchange.okcoinIntl.Verbose = true @@ -246,6 +235,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.itbit.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.itbit.Run() if exch.Verbose { bot.exchange.itbit.Verbose = true @@ -261,6 +251,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.kraken.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.kraken.Run() if exch.Verbose { bot.exchange.kraken.Verbose = true @@ -276,6 +267,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.lakebtc.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.lakebtc.Run() if exch.Verbose { bot.exchange.lakebtc.Verbose = true @@ -291,6 +283,7 @@ func main() { } else { log.Printf("%s enabled.\n", exch.Name) bot.exchange.huobi.SetAPIKeys(exch.APIKey, exch.APISecret) + go bot.exchange.huobi.Run() if exch.Verbose { bot.exchange.huobi.Verbose = true @@ -301,196 +294,30 @@ func main() { } } } + <-bot.shutdown + Shutdown() +} - err = RetrieveConfigCurrencyPairs(bot.config) +func HandleInterrupt() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + sig := <-c + log.Printf("Captured %v.", sig) + Shutdown() + }() +} + +func Shutdown() { + log.Println("Bot shutting down..") + err := SaveConfig() if err != nil { - log.Println("Fatal error retrieving config currency pairs. Error: ", err) + log.Println("Unable to save config.") + } else { + log.Println("Config file saved successfully.") } - //temp until proper asynchronous method of getting pricing/order books is coded - for { - //spot - if bot.exchange.coinbase.IsEnabled() { - go func() { - CoinbaseStats := bot.exchange.coinbase.GetStats("BTC-USD") - CoinbaseTicker := bot.exchange.coinbase.GetTicker("BTC-USD") - log.Printf("Coinbase BTC: Last %f High %f Low %f Volume %f\n", CoinbaseTicker.Price, CoinbaseStats.High, CoinbaseStats.Low, CoinbaseStats.Volume) - }() - } - if bot.exchange.kraken.IsEnabled() { - go func() { - KrakenBTC := bot.exchange.kraken.GetTicker("XBTUSD") - log.Printf("Kraken BTC: %v\n", KrakenBTC) - }() - go func() { - KrakenLTC := bot.exchange.kraken.GetTicker("LTCUSD") - log.Printf("Kraken LTC: %v\n", KrakenLTC) - }() - } - if bot.exchange.lakebtc.IsEnabled() { - go func() { - LakeBTCTickerResponse := bot.exchange.lakebtc.GetTicker() - log.Printf("LakeBTC USD: Last %f (%f) High %f (%f) Low %f (%f) Volume US %f (CNY %f)\n", LakeBTCTickerResponse.USD.Last, LakeBTCTickerResponse.CNY.Last, LakeBTCTickerResponse.USD.High, LakeBTCTickerResponse.CNY.High, LakeBTCTickerResponse.USD.Low, LakeBTCTickerResponse.CNY.Low, LakeBTCTickerResponse.USD.Volume, LakeBTCTickerResponse.CNY.Volume) - }() - } - if bot.exchange.btcchina.IsEnabled() { - go func() { - BTCChinaBTC := bot.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 := bot.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) - }() - } - - if bot.exchange.huobi.IsEnabled() { - go func() { - HuobiBTC := bot.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 := bot.exchange.huobi.GetTicker("ltc") - HuobiLTCLastUSD, _ := ConvertCurrency(HuobiLTC.Last, "CNY", "USD") - HuobiLTCHighUSD, _ := ConvertCurrency(HuobiLTC.High, "CNY", "USD") - HuobiLTCLowUSD, _ := ConvertCurrency(HuobiLTC.Low, "CNY", "USD") - log.Printf("Huobi LTC: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", HuobiLTCLastUSD, HuobiLTC.Last, HuobiLTCHighUSD, HuobiLTC.High, HuobiLTCLowUSD, HuobiLTC.Low, HuobiLTC.Vol) - }() - } - - if bot.exchange.itbit.IsEnabled() { - go func() { - ItbitBTC := bot.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 bot.exchange.bitstamp.IsEnabled() { - go func() { - BitstampBTC := bot.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 bot.exchange.bitfinex.IsEnabled() { - go func() { - BitfinexLTC := bot.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 := bot.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 bot.exchange.btce.IsEnabled() { - go func() { - BTCeBTC := bot.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 := bot.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 bot.exchange.btcmarkets.IsEnabled() { - go func() { - BTCMarketsBTC := bot.exchange.btcmarkets.GetTicker("BTC") - BTCMarketsBTCLastUSD, _ := ConvertCurrency(BTCMarketsBTC.LastPrice, "AUD", "USD") - BTCMarketsBTCBestBidUSD, _ := ConvertCurrency(BTCMarketsBTC.BestBID, "AUD", "USD") - BTCMarketsBTCBestAskUSD, _ := ConvertCurrency(BTCMarketsBTC.BestAsk, "AUD", "USD") - log.Printf("BTC Markets BTC: Last %f (%f) Bid %f (%f) Ask %f (%f)\n", BTCMarketsBTCLastUSD, BTCMarketsBTC.LastPrice, BTCMarketsBTCBestBidUSD, BTCMarketsBTC.BestBID, BTCMarketsBTCBestAskUSD, BTCMarketsBTC.BestAsk) - }() - - go func() { - BTCMarketsLTC := bot.exchange.btcmarkets.GetTicker("LTC") - BTCMarketsLTCLastUSD, _ := ConvertCurrency(BTCMarketsLTC.LastPrice, "AUD", "USD") - BTCMarketsLTCBestBidUSD, _ := ConvertCurrency(BTCMarketsLTC.BestBID, "AUD", "USD") - BTCMarketsLTCBestAskUSD, _ := ConvertCurrency(BTCMarketsLTC.BestAsk, "AUD", "USD") - log.Printf("BTC Markets LTC: Last %f (%f) Bid %f (%f) Ask %f (%f)", BTCMarketsLTCLastUSD, BTCMarketsLTC.LastPrice, BTCMarketsLTCBestBidUSD, BTCMarketsLTC.BestBID, BTCMarketsLTCBestAskUSD, BTCMarketsLTC.BestAsk) - }() - } - - if bot.exchange.okcoinChina.IsEnabled() { - go func() { - OKCoinChinaBTC := bot.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 := bot.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 bot.exchange.okcoinIntl.IsEnabled() { - go func() { - OKCoinChinaIntlBTC := bot.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 := bot.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 := bot.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 := bot.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 := bot.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 := bot.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 := bot.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 := bot.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") - cmd.Stdout = os.Stdout - cmd.Run() - } -} \ No newline at end of file + log.Println("Exiting.") + os.Exit(1) +} diff --git a/okcoinhttp.go b/okcoinhttp.go index 8176b4a6..cd1bdf57 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -4,6 +4,7 @@ import ( "net/url" "strings" "strconv" + "time" "fmt" "log" ) @@ -94,6 +95,69 @@ func (o *OKCoin) GetFee(maker bool) (float64) { return 0 } +func (o *OKCoin) Run() { + for o.Enabled { + if o.APIUrl == OKCOIN_API_URL { + go func() { + OKCoinChinaIntlBTC := o.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 := o.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() { + OKCoinFuturesBTC := o.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 := o.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 := o.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 := o.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 := o.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 := o.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) + }() + } else { + go func() { + OKCoinChinaBTC := o.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 := o.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) + }() + } + time.Sleep(time.Second * 10) + } +} + func (o *OKCoin) GetTicker(symbol string) (OKCoinTicker) { resp := OKCoinTickerResponse{} path := fmt.Sprintf("ticker.do?symbol=%s&ok=1", symbol)