Skip to content

Instantly share code, notes, and snippets.

@SimonSchubert
Last active May 16, 2022 09:52
Show Gist options
  • Save SimonSchubert/8b845964dd0cbf1eddf2930021b29c07 to your computer and use it in GitHub Desktop.
Save SimonSchubert/8b845964dd0cbf1eddf2930021b29c07 to your computer and use it in GitHub Desktop.
Monitor LUNA and UST market cap and estimate when selling pressure will end
#!/usr/bin/env kotlin
@file:DependsOn("io.ktor:ktor-client-core-jvm:1.5.3")
@file:DependsOn("io.ktor:ktor-client-cio-jvm:1.5.3")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
@file:DependsOn("org.json:json:20220320")
import kotlinx.coroutines.*
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import org.json.*
import java.text.DecimalFormat
import kotlinx.coroutines.delay
import kotlin.time.Duration.*
import kotlin.time.ExperimentalTime
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
import kotlin.time.DurationUnit
import kotlin.time.measureTimedValue
import java.text.*
import java.util.*
import java.math.BigDecimal
val client = HttpClient()
suspend fun getUstCirculating(): Double {
val response: HttpResponse = client.get("https://fcd.terra.dev/v1/totalsupply/ust")
return response.readText().toDouble()
}
suspend fun getLunaPrice(): BigDecimal {
val response: HttpResponse = client.get("https://api.coingecko.com/api/v3/simple/price?ids=terra-luna&vs_currencies=usd")
return JSONObject(response.readText()).getJSONObject("terra-luna").getBigDecimal("usd")
}
suspend fun getLunaMarketCap(): Long {
val response: HttpResponse = client.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=terra-luna&order=market_cap_desc&per_page=100&page=1&sparkline=false")
return JSONArray(response.readText()).getJSONObject(0).getLong("market_cap")
}
val currencyFormat = NumberFormat.getCurrencyInstance(Locale.US)
currencyFormat.setMaximumFractionDigits(0)
val circulatingSupplies = mutableListOf<Double>()
runBlocking {
while(true) {
try {
update()
} catch(ignore: Exception) { }
delay(60000)
}
}
suspend fun update() {
val lunaMarketCap = getLunaMarketCap()
val ustCirculating = getUstCirculating()
val lunaPrice = getLunaPrice()
circulatingSupplies.add(ustCirculating)
print("\u001b[H\u001b[2J")
println("▄▄▄▄ ██▓ ▒█████ ▒█████ ▓█████▄ ███▄ ▄███▓ ▒█████ ▒█████ ███▄ █")
println("▓█████▄ ▓██▒ ▒██▒ ██▒▒██▒ ██▒▒██▀ ██▌ ▓██▒▀█▀ ██▒▒██▒ ██▒▒██▒ ██▒ ██ ▀█ █")
println("▒██▒ ▄██▒██░ ▒██░ ██▒▒██░ ██▒░██ █▌ ▓██ ▓██░▒██░ ██▒▒██░ ██▒▓██ ▀█ ██▒")
println("▒██░█▀ ▒██░ ▒██ ██░▒██ ██░░▓█▄ ▌ ▒██ ▒██ ▒██ ██░▒██ ██░▓██▒ ▐▌██▒")
println("░▓█ ▀█▓░██████▒░ ████▓▒░░ ████▓▒░░▒████▓ ▒██▒ ░██▒░ ████▓▒░░ ████▓▒░▒██░ ▓██░")
println("░▒▓███▀▒░ ▒░▓ ░░ ▒░▒░▒░ ░ ▒░▒░▒░ ▒▒▓ ▒ ░ ▒░ ░ ░░ ▒░▒░▒░ ░ ▒░▒░▒░ ░ ▒░ ▒ ▒")
println("▒░▒ ░ ░ ░ ▒ ░ ░ ▒ ▒░ ░ ▒ ▒░ ░ ▒ ▒ ░ ░ ░ ░ ▒ ▒░ ░ ▒ ▒░ ░ ░░ ░ ▒░")
println("░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░")
println()
println(String.format("%30s%20s", "LUNA price:", "$${lunaPrice}"))
println()
println(String.format("%30s%20s", "LUNA/UST cap difference:", "${currencyFormat.format(lunaMarketCap-ustCirculating)}"))
println(String.format("%30s%20s", "LUNA market cap:", "${currencyFormat.format(lunaMarketCap)}"))
println(String.format("%30s%20s", "UST circulating supply:", "${currencyFormat.format(ustCirculating)}"))
circulatingSupplies.dropLast(1).takeLast(6).reversed().forEach {
println(String.format("%30s%20s", "", "${currencyFormat.format(it)}"))
}
val minutesPast = circulatingSupplies.size
val circulationDifference = circulatingSupplies.first()-circulatingSupplies.last()
val minutesUntilEclipse = (ustCirculating/circulationDifference*minutesPast).toInt().minutes
println(String.format("%30s%20s", "Burned UST in past $minutesPast minutes:", "${currencyFormat.format(circulationDifference)}"))
if(circulationDifference > 0) {
println(String.format("%30s%20s", "Time until blood moon ends:", "~${minutesUntilEclipse}"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment