{"id":27876909,"url":"https://github.com/ethauvin/cryptoprice","last_synced_at":"2025-05-05T02:53:49.037Z","repository":{"id":57737836,"uuid":"365468795","full_name":"ethauvin/cryptoprice","owner":"ethauvin","description":"Retrieve cryptocurrencies current prices","archived":false,"fork":false,"pushed_at":"2025-04-25T16:44:37.000Z","size":622,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T17:49:49.893Z","etag":null,"topics":["android","bitcoin","btc","coinbase","crypto","cryptocurrency","eth","ethereum","java","kotlin","litecoin","ltc","price","spot","ticker"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ethauvin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-05-08T09:07:55.000Z","updated_at":"2025-04-25T16:44:41.000Z","dependencies_parsed_at":"2023-11-24T02:39:48.684Z","dependency_job_id":"f15039a0-4a5f-43bd-875d-94d1055b92c1","html_url":"https://github.com/ethauvin/cryptoprice","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethauvin%2Fcryptoprice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethauvin%2Fcryptoprice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethauvin%2Fcryptoprice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethauvin%2Fcryptoprice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethauvin","download_url":"https://codeload.github.com/ethauvin/cryptoprice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252429953,"owners_count":21746571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","bitcoin","btc","coinbase","crypto","cryptocurrency","eth","ethereum","java","kotlin","litecoin","ltc","price","spot","ticker"],"created_at":"2025-05-05T02:53:48.518Z","updated_at":"2025-05-05T02:53:49.029Z","avatar_url":"https://github.com/ethauvin.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](https://opensource.org/licenses/BSD-3-Clause)\n[![Kotlin](https://img.shields.io/badge/kotlin-2.1.20-7f52ff)](https://kotlinlang.org/)\n[![bld](https://img.shields.io/badge/2.2.1-FA9052?label=bld\u0026labelColor=2392FF)](https://rife2.com/bld)\n[![Release](https://img.shields.io/github/release/ethauvin/cryptoprice.svg)](https://github.com/ethauvin/cryptoprice/releases/latest)\n[![Maven Central](https://img.shields.io/maven-central/v/net.thauvin.erik/cryptoprice)](https://central.sonatype.com/artifact/net.thauvin.erik/cryptoprice)\n[![Nexus Snapshot](https://img.shields.io/nexus/s/net.thauvin.erik/cryptoprice?label=snapshot\u0026server=https%3A%2F%2Foss.sonatype.org%2F)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/cryptoprice/)\n\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_cryptoprice\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_cryptoprice)\n[![GitHub CI](https://github.com/ethauvin/cryptoprice/actions/workflows/bld.yml/badge.svg)](https://github.com/ethauvin/cryptoprice/actions/workflows/bld.yml)\n[![CircleCI](https://circleci.com/gh/ethauvin/cryptoprice/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/cryptoprice/tree/master)\n\n# Retrieve cryptocurrencies current (buy, sell or spot) prices\n\nA simple implementation of the prices [Coinbase Public API](https://docs.cdp.coinbase.com/coinbase-app/docs/api-prices).\n\n## Examples (TL;DR)\n\n```kotlin\nimport net.thauvin.erik.crypto.CryptoPrice.Companion.buyPrice\nimport net.thauvin.erik.crypto.CryptoPrice.Companion.sellPrice\nimport net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice\n\nval btc = spotPrice(\"BTC\") // Bitcoin\nprintln(btc.amount)\n\nval eth = sellPrice(\"ETH\", \"EUR\") // Ethereum in Euro\nprintln(eth.amount)\n\nval eth = buyPrice(\"LTC\", \"GBP\") // Litecoin in Pound sterling\nprintln(eth.amount)\n\n```\n - View [bld](https://github.com/ethauvin/cryptoprice/blob/master/examples/bld) or [Gradle](https://github.com/ethauvin/cryptoprice/blob/master/examples/gradle) Examples.\n\n### bld\n\nTo use with [bld](https://rife2.com/bld), include the following dependency in your [build](https://github.com/ethauvin/cryptoprice/blob/master/examples/bld/src/bld/java/com/example/CryptoPriceExampleBuild.java) file:\n\n```java\nrepositories = List.of(MAVEN_CENTRAL);\n\nscope(compile)\n    .include(dependency(\"net.thauvin.erik:cryptoprice:1.0.2\"));\n```\nBe sure to use the [bld Kotlin extension](https://github.com/rife2/bld-kotlin) in your project.\n\n### Gradle, Maven, etc.\n\nTo use with [Gradle](https://gradle.org/), include the following dependency in your [build](https://github.com/ethauvin/cryptoprice/blob/master/examples/gradle/build.gradle.kts) file:\n\n```gradle\nrepositories {\n    mavenCentral()\n    maven { url = uri(\"https://oss.sonatype.org/content/repositories/snapshots\") } // only needed for SNAPSHOT\n}\n\ndependencies {\n    implementation(\"net.thauvin.erik:cryptoprice:1.0.2\")\n}\n```\n\nInstructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://central.sonatype.com/artifact/net.thauvin.erik/cryptoprice).\n\n### Prices\n\nThe `spotPrice`, `buyPrice` and `sellPrice` functions define the following parameters:\n\n```kotlin\nspotPrice(\n    base: String, // Required \n    currency: String = \"USD\",\n    date: LocalDate? = null\n)\n\nbuyPrice(\n    base: String, // Required \n    currency: String = \"USD\"\n)\n\nsellPrice(\n    base: String, // Required \n    currency: String = \"USD\"\n)\n```\n\nParameters  | Description\n:---------- |:------------------------------------------------------------\n`base`      | The cryptocurrency ticker symbol (`BTC`, `ETH`, `LTC`, etc.)\n`currency`  | The fiat currency ISO 4217 code. (`USD`, `GBP`, `EUR`, etc.)\n`date`      | The `LocalDate` for historical price data.\n\nA `CryptoPrice` object is returned defined as follows:\n\n```kotlin\nCryptoPrice(val base: String, val currency: String, val amount: BigDecimal)\n```\nThe parameter names match the [Coinbase API](https://docs.cdp.coinbase.com/coinbase-app/docs/api-prices).\n\n#### Format\n\nTo display the amount as a formatted currency, use the `toCurrency` function:\n\n```kotlin\nval euro = CryptoPrice(\"BTC\", \"EUR\", 23456.78.toBigDecimal())\nprintln(euro.toCurrency()) // €23,456.78\n\nval krone = CryptoPrice(\"BTC\", \"DKK\", 123456.78.toBigDecimal())\nprintln(krone.toCurrency(Locale.Builder().setLanguage(\"da\").setRegion(\"DK\").build())) // 123.456,78 kr.\n```\n\n##### JSON\n\nTo convert a `CryptoPrice` object back to JSON, use the `toJson` function:\n\n```kotlin\nval price = CryptoPrice(\"BTC\", \"USD\", 34567.89.toBigDecimal())\nprintln(price.toJson())\n```\n\n*output:*\n\n```json\n{\"data\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"34567.89\"}}\n```\n\nThe `data` object matches the [Coinbase API](https://docs.cdp.coinbase.com/coinbase-app/docs/api-prices). To specify a different (or no) key, use:\n\n```kotlin\nprintln(price.toJson(\"bitcoin\"))\nprintln(price.toJson(\"\")) // or price.toString()\n```\n\n*output:*\n\n```json\n{\"bitcoin\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"34567.89\"}}\n{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"34567.89\"}\n```\n\nSimilarly, to create a `CryptoPrice` object from JSON, use the `toPrice` function:\n\n```kotlin\nval btc = \"\"\"{\"data\":{\"base\":\"BTC\",\"currency\":\"USD\",\"amount\":\"34567.89\"}}\"\"\".toPrice()\nval eth = \"\"\"{\"ether\":{\"base\":\"ETH\",\"currency\":\"USD\",\"amount\":\"2345.67\"}}\"\"\".toPrice(\"ether\")\n```\n\n### Extending\n\nA generic `apiCall()` function is available to access other [data API endpoints](https://docs.cdp.coinbase.com/coinbase-app/docs/api-currencies). For example to retrieve the [exchange rates](https://docs.cdp.coinbase.com/coinbase-app/docs/api-exchange-rates):\n\n```kotlin\napiCall(listOf(\"exchange-rates\"), mapOf(\"currency\" to \"usd\"))\n```\nwill return something like:\n\n```json\n{\"data\":{\"currency\":\"BTC\",\"rates\":{\"AED\":\"36.73\",\"AFN\":\"589.50\",\"...\":\"...\"}}}\n```\n\nSee the [examples](https://github.com/ethauvin/cryptoprice/blob/master/examples/) for more details.\n\n## Contributing\n\nIf you want to contribute to this project, all you have to do is clone the GitHub\nrepository:\n\n```console\ngit clone git@github.com:ethauvin/cryptoprice.git\n```\n\nThen use [bld](https://rife2.com/bld) to build:\n\n```console\ncd cryptoprice\n./bld compile\n```\n\nThe project has an [IntelliJ IDEA](https://www.jetbrains.com/idea/) project structure. You can just open it after all\nthe dependencies were downloaded and peruse the code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethauvin%2Fcryptoprice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethauvin%2Fcryptoprice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethauvin%2Fcryptoprice/lists"}