'Kotlin: Problem with List Filter by Multiple Conditions
I'm trying to match two lists to another. In one list are items of crypto trades, the other contains so called candlesticks, which represents a price of crypto asset for one minute. A candlestick is limited by open time and close time. One trade item belongs exactly to one candlestick set. So I step through the trades list an for each item I apply a filter of two conditions. Unfortunately the filter returns no matching data. When I compare the trades data with candlestick items manually, I get a match. Here is the code of the data filter.
TradesDbHandler(dbConnector).use { dbHandler ->
val rowsInTime = dbHandler.readTimeframe(startTime, buffer)
rowsInTime.distinctBy { it.symbol }.forEach {
val symbolFilter = rowsInTime.filter { row -> row.symbol == it.symbol }
val symbolMinTime = symbolFilter.minByOrNull { it.time }
val symbolMaxTime = symbolFilter.maxByOrNull { it.time }
val tempKlines = binanceClient.getCandleSticks( symbolMaxTime!!.symbol,
symbolMinTime!!.time,
symbolMaxTime!!.time ) {
log(">>> $it")
}
val klines = mutableListOf<KlineRow>()
klines.plusElement(tempKlines.filter { row ->
(row.opentime <= it.time) &&
(row.closetime >= it.time) })
}
}
Solution 1:[1]
The code was not the problem but the data. Therefore no matches could be found. Thread can be closed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sandromo |