diff --git a/cmd/feederd/main.go b/cmd/feederd/main.go index f1f0789..f32b37b 100644 --- a/cmd/feederd/main.go +++ b/cmd/feederd/main.go @@ -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) diff --git a/config.example.json b/config.example.json index ddb7d33..fd6bdac 100644 --- a/config.example.json +++ b/config.example.json @@ -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 - } + } ] } \ No newline at end of file diff --git a/config/config.go b/config/config.go index 01adcf7..ed9908f 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` @@ -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, } } @@ -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) diff --git a/pkg/conn/grpc.go b/pkg/conn/grpc.go index 4e2e15f..aac8028 100644 --- a/pkg/conn/grpc.go +++ b/pkg/conn/grpc.go @@ -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