Skip to content

Commit

Permalink
Improve messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero committed Nov 26, 2020
1 parent b3c69f1 commit 6c3711e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
3 changes: 3 additions & 0 deletions cmd/feederd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func setup() (chan os.Signal, *websocket.Conn, []marketinfo.MarketInfo, *grpc.Cl
log.Fatal("Socket Connection Error: ", err)
}
marketsInfos := loadMarkets(conf, cSocket)
if len(marketsInfos) == 0 {
log.Warn("list of market to feed is empty")
}

// Set up the connection to the gRPC server.
conngRPC, err := conn.ConnectTogRPC(conf.DaemonEndpoint)
Expand Down
10 changes: 2 additions & 8 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
"markets": [
{
"base_asset": "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
"quote_asset":"d73f5cd0954c1bf325f85d7a7ff43a6eb3ea3b516fd57064b85306d43bc1c9ff",
"quote_asset": "691e6b9e00cb75f6383f2581ef001f2695074746e213d21771dff5a890f21104",
"kraken_ticker": "XBT/USD",
"interval": 10
},
{
"base_asset": "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225",
"quote_asset":"d090c403610fe8a9e31967355929833bc8a8fe08429e630162d1ecbf29fdf28b",
"kraken_ticker": "XBT/EUR",
"interval": 15
}
}
]
}
16 changes: 3 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import (
const (
defaultDaemonEndpoint = "localhost:9000"
defaultKrakenWsEndpoint = "ws.kraken.com"
defaultBaseAsset = "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"
defaultQuoteAsset = "d73f5cd0954c1bf325f85d7a7ff43a6eb3ea3b516fd57064b85306d43bc1c9ff"
defaultKrakenTicker = "XBT/USD"
defaultInterval = 10
)

// Config defines the struct for the configuration JSON file
type Config struct {
DaemonEndpoint string `json:"daemon_endpoint,required"`
DaemonMacaroon string `json:"daemon_macaroon"`
Expand All @@ -33,14 +30,7 @@ func defaultConfig() Config {
return Config{
DaemonEndpoint: defaultDaemonEndpoint,
KrakenWsEndpoint: defaultKrakenWsEndpoint,
Markets: []Market{
{
BaseAsset: defaultBaseAsset,
QuoteAsset: defaultQuoteAsset,
KrakenTicker: defaultKrakenTicker,
Interval: defaultInterval,
},
},
Markets: nil,
}
}

Expand Down Expand Up @@ -99,7 +89,7 @@ func checkConfigParsing(config Config) error {
func LoadConfig(filePath string) (Config, error) {
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
log.Printf("File not found: %s. Loading default config.\n", filePath)
log.Debug("File not found: %s. Loading default config.\n", filePath)
return defaultConfig(), nil
}
return loadConfigFromFile(filePath)
Expand Down
19 changes: 16 additions & 3 deletions pkg/conn/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,30 @@ func ConnectTogRPC(daemonEndpoint string) (*grpc.ClientConn, error) {
return conn, nil
}

// UpdateMarketPricegRPC calls the tdex daemon UpdateMarketPrice rpc endpoint to update a defined market
func UpdateMarketPricegRPC(marketInfo marketinfo.MarketInfo, clientgRPC pboperator.OperatorClient) {

if marketInfo.Price == 0.00 {
log.Println("Can't send gRPC request with no price")
return
}
log.Println("Sending gRPC request:", marketInfo.Config.KrakenTicker, marketInfo.Price)

log.Printf("%s %g for market %s-%s", marketInfo.Config.KrakenTicker, marketInfo.Price, marketInfo.Config.BaseAsset[:4], marketInfo.Config.QuoteAsset[:4])

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

_, err := clientgRPC.UpdateMarketPrice(ctx, &pboperator.UpdateMarketPriceRequest{
Market: &pbtypes.Market{BaseAsset: marketInfo.Config.BaseAsset, QuoteAsset: marketInfo.Config.QuoteAsset},
Price: &pbtypes.Price{BasePrice: 1 / float32(marketInfo.Price), QuotePrice: float32(marketInfo.Price)}})
Market: &pbtypes.Market{
BaseAsset: marketInfo.Config.BaseAsset,
QuoteAsset: marketInfo.Config.QuoteAsset,
},
Price: &pbtypes.Price{
BasePrice: 1 / float32(marketInfo.Price),
QuotePrice: float32(marketInfo.Price),
},
})

if err != nil {
log.Println(err)
return
Expand Down

0 comments on commit 6c3711e

Please sign in to comment.