Skip to content

Commit

Permalink
Add event support for BTCe
Browse files Browse the repository at this point in the history
  • Loading branch information
Champii committed May 25, 2017
1 parent 3d9ca38 commit 7ca740c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"strconv"
"time"

"github.com/champii/gocryptotrader/common"
"github.com/champii/gocryptotrader/config"
Expand Down Expand Up @@ -232,6 +233,7 @@ func CheckEvents() {
}
}
}
time.Sleep(time.Second)
}
}

Expand Down
19 changes: 17 additions & 2 deletions exchanges/btce/btce_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (b *BTCE) Run() {
x = common.StringToUpper(x[0:3] + x[4:])
log.Printf("BTC-e %s: Last %f High %f Low %f Volume %f\n", x, y.Last, y.High, y.Low, y.Vol_cur)
b.Ticker[x] = y
b.GetTickerPrice2(pair.NewCurrencyPairFromString(pairsString), b.Ticker[x])
stats.AddExchangeInfo(b.GetName(), common.StringToUpper(x[0:3]), common.StringToUpper(x[4:]), y.Last, y.Vol_cur)
}
}()
Expand All @@ -51,10 +52,24 @@ func (b *BTCE) Run() {

func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, ok := b.Ticker[p.Pair().Lower().String()]
if !ok {
tick, ok := ticker.GetTicker(b.GetName(), p)
if ok != nil {
return tickerPrice, errors.New("Unable to get currency.")
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Ask
tickerPrice.Bid = tick.Bid
tickerPrice.Low = tick.Low
tickerPrice.Last = tick.Last
tickerPrice.Volume = tick.Volume
tickerPrice.High = tick.High
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
return tickerPrice, nil
}

func (b *BTCE) GetTickerPrice2(p pair.CurrencyPair, tick BTCeTicker) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice

tickerPrice.Pair = p
tickerPrice.Ask = tick.Buy
tickerPrice.Bid = tick.Sell
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/champii/gocryptotrader/common"
"github.com/champii/gocryptotrader/config"
"github.com/champii/gocryptotrader/currency"
"github.com/champii/gocryptotrader/events"
"github.com/champii/gocryptotrader/exchanges"
"github.com/champii/gocryptotrader/exchanges/anx"
"github.com/champii/gocryptotrader/exchanges/bitfinex"
Expand Down Expand Up @@ -158,17 +158,18 @@ func (b *Bot) Start(c chan Message) {

b.config.RetrieveConfigCurrencyPairs()

err = currency.SeedCurrencyData(currency.BaseCurrencies)
if err != nil {
log.Fatalf("Fatal error retrieving config currencies. Error: %s", err)
}
// err = currency.SeedCurrencyData(currency.BaseCurrencies)
// if err != nil {
// log.Fatalf("Fatal error retrieving config currencies. Error: %s", err)
// }

log.Println("Successfully retrieved config currencies.")

b.portfolio = &portfolio.Portfolio
b.portfolio.SeedPortfolio(b.config.Portfolio)
SeedExchangeAccountInfo(GetAllEnabledExchangeAccountInfo().Data)
go portfolio.StartPortfolioWatcher()
go func() { events.CheckEvents() }()

// if b.config.Webserver.Enabled {
// err := b.config.CheckWebserverConfigValues()
Expand Down

0 comments on commit 7ca740c

Please sign in to comment.