Skip to content

Instantly share code, notes, and snippets.

@ejektaflex
Last active January 12, 2018 06:31
Show Gist options
  • Save ejektaflex/4fee26c0fc849b8419b30aa9ffb4071f to your computer and use it in GitHub Desktop.
Save ejektaflex/4fee26c0fc849b8419b30aa9ffb4071f to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
val data = StockHelper.data("src/main/kotlin/data/STOCK.json")!!
// Basic example of where I would use it, creating a map of dates and changes for each day
// I'd then probably further display this on a chart.
val dailyChanges = data.map { it.date to it.change }
// ... Displaying of chart here
}
[
{
"date": "2018/01/10",
"close": 0.25,
"volume": 500000,
"open": 0.5,
"high": 0.5,
"low": 0.25
}
]
import com.beust.klaxon.Klaxon
import java.io.File
object StockHelper {
data class StockEntry(
val date: String,
val close: Double,
val volume: Int,
val open: Double,
val high: Double,
val low: Double
) {
val change: Double
get() = close - open
val movement: Double
get() = high - low
}
fun data(loc: String): ArrayList<StockEntry>? {
return ArrayList(Klaxon().parseArray<StockEntry>(File(loc).inputStream()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment