Engine improvements

This commit is contained in:
Adrian Gallagher
2019-06-10 20:02:09 +10:00
parent 04c7c4895f
commit f777e68716
88 changed files with 2037 additions and 1413 deletions

View File

@@ -4,9 +4,6 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges/assets"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
log "github.com/thrasher-/gocryptotrader/logger"
)
@@ -26,10 +23,7 @@ type ICommunicate interface {
// Setup sets up communication variables and intiates a connection to the
// communication mediums
func (c IComm) Setup() {
TickerStaged = make(map[string]map[assets.AssetType]map[string]ticker.Price)
OrderbookStaged = make(map[string]map[assets.AssetType]map[string]Orderbook)
ServiceStarted = time.Now()
for i := range c {
if c[i].IsEnabled() && !c[i].IsConnected() {
err := c[i].Connect()
@@ -46,8 +40,8 @@ func (c IComm) PushEvent(event Event) {
if c[i].IsEnabled() && c[i].IsConnected() {
err := c[i].PushEvent(event)
if err != nil {
log.Errorf("Communications error - PushEvent() in package %s with %v",
c[i].GetName(), event)
log.Errorf("Communications error - PushEvent() in package %s with %v. Err %s",
c[i].GetName(), event, err)
}
}
}
@@ -68,42 +62,3 @@ func (c IComm) GetEnabledCommunicationMediums() {
log.Warnf("Communications: No communication mediums are enabled.")
}
}
// StageTickerData stages updated ticker data for the communications package
func (c IComm) StageTickerData(exchangeName string, assetType assets.AssetType, tickerPrice *ticker.Price) {
m.Lock()
defer m.Unlock()
if _, ok := TickerStaged[exchangeName]; !ok {
TickerStaged[exchangeName] = make(map[assets.AssetType]map[string]ticker.Price)
}
if _, ok := TickerStaged[exchangeName][assetType]; !ok {
TickerStaged[exchangeName][assetType] = make(map[string]ticker.Price)
}
TickerStaged[exchangeName][assetType][tickerPrice.Pair.String()] = *tickerPrice
}
// StageOrderbookData stages updated orderbook data for the communications
// package
func (c IComm) StageOrderbookData(exchangeName string, assetType assets.AssetType, ob *orderbook.Base) {
m.Lock()
defer m.Unlock()
if _, ok := OrderbookStaged[exchangeName]; !ok {
OrderbookStaged[exchangeName] = make(map[assets.AssetType]map[string]Orderbook)
}
if _, ok := OrderbookStaged[exchangeName][assetType]; !ok {
OrderbookStaged[exchangeName][assetType] = make(map[string]Orderbook)
}
_, totalAsks := ob.TotalAsksAmount()
_, totalBids := ob.TotalBidsAmount()
OrderbookStaged[exchangeName][assetType][ob.Pair.String()] = Orderbook{
CurrencyPair: ob.Pair.String(),
TotalAsks: totalAsks,
TotalBids: totalBids}
}