Я новичок в Play Scala. Ниже приведен фрагмент кода, который я пытаюсь использовать для предоставления API. Его сбой с приведенной ниже ошибкой.
type mismatch;
found : scala.concurrent.Future[String]
required: String
Источник API:
def getStrategy(date: String) = Action.async {
val currentDate:String = toString(DateTime.now.minusDays(1))
getDecision(date, currentDate).map(lastError => Ok("No Strategy found:%s".format(lastError)))
}
def getDecision(reqestedDate:String, currentDate:String): Future[String] = {
getForecastPrice(reqestedDate).map(forecastPrice =>
getCurrentPrice(currentDate).map(currentPrice =>
getCall(currentPrice, forecastPrice)
)
)
}
def getForecastPrice(requestedDate:String): Future[Option[Double]] = {
predictionRepo.getPrediction(requestedDate).map( maybePrediction =>
maybePrediction.map ( fPrice => fPrice.price )
)
}
def getCurrentPrice(currentDate:String): Future[Option[Double]] = {
priceRepo.getPrice(currentDate).map ( maybePrice =>
maybePrice.map ( cPrice => cPrice.price )
)
}
def getCall(currentPrice:Option[Double], forcastPrice:Option[Double]): String = {
var decision = ""
println("currentPrice:" + currentPrice)
println("forcastPrice:" + forcastPrice)
if(currentPrice.isDefined && forcastPrice.isDefined) {
var currentPriceValue = currentPrice.get.toDouble
var forcastPriceValue = forcastPrice.get.toDouble
if((currentPriceValue*5/100) < (currentPriceValue - forcastPriceValue)) {
decision = "BUY"
} else if((currentPriceValue*5/100) > (currentPriceValue - forcastPriceValue)) {
decision = "SELL"
} else {
decision = "HOLD"
}
}
return decision
}
Ошибка в приведенном выше коде показана в расположении ниже.
getCurrentPrice(currentDate).map(currentPrice =>
Не могли бы вы помочь мне найти причину этой проблемы?