Added readme.
This commit is contained in:
parent
61e647264b
commit
0dff725627
1 changed files with 67 additions and 0 deletions
67
README.md
Normal file
67
README.md
Normal file
|
@ -0,0 +1,67 @@
|
|||
[](http://opensource.org/licenses/BSD-3-Clause) [](https://github.com/ethauvin/cryptoprice/releases/latest) [](https://search.maven.org/search?q=g:%22net.thauvin.erik%22%20AND%20a:%22cryptoprice%22)
|
||||
|
||||
[](https://snyk.io/test/github/ethauvin/cryptoprice?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_cryptoprice) [](https://travis-ci.com/ethauvin/cryptoprice) [](https://circleci.com/gh/ethauvin/cryptoprice/tree/master)
|
||||
|
||||
# Retrieve cryptocurrencies current market prices
|
||||
|
||||
A simple Kotlin/Java/Android implementation of the spot price [Coinbase Public API](https://developers.coinbase.com/api/v2#get-spot-price).
|
||||
|
||||
## Examples (TL;DR)
|
||||
|
||||
```kotlin
|
||||
import net.thauvin.erik.crypto.CryptoPrice
|
||||
|
||||
// ...
|
||||
|
||||
val btc = marketPrice("BTC") // Bitcoin
|
||||
print(btc.amount)
|
||||
|
||||
val eth = marketPrice("ETH", "EUR") // Ethereum in Euros
|
||||
price(eth.amount)
|
||||
|
||||
```
|
||||
- View [Kotlin](https://github.com/ethauvin/cryptoprice/blob/master/examples/src/main/kotlin/com/example/CryptoPriceExample.kt) or [Java](https://github.com/ethauvin/cryptoprice/blob/master/examples/src/main/java/com/example/CryptoPriceSample.java) Examples.
|
||||
|
||||
### Market Price
|
||||
|
||||
The `marketPrice` function defines the following parameters:
|
||||
|
||||
```kotlin
|
||||
marketPrice(
|
||||
base: String, // Required
|
||||
currency: String = "USD",
|
||||
date: LocalDate? = null,
|
||||
)
|
||||
```
|
||||
|
||||
Parameters | Description
|
||||
:---------- |:-------------------------------------------------------
|
||||
`base` | The cryptocurrency ticker symbol (BTC, ETH, ETH2, etc.)
|
||||
`currency` | The fiat currency ISO 4217 code.
|
||||
`date` | The `LocalDate` for historical price data.
|
||||
|
||||
A `CryptoPrice` is returned defined as follows:
|
||||
|
||||
```kotlin
|
||||
CryptoPrice(val base: String, val currency: String, val amount: Double)
|
||||
```
|
||||
The parameter names match the [Coinbase API](https://developers.coinbase.com/api/v2#get-spot-price).
|
||||
|
||||
### Extending
|
||||
|
||||
A generic `apiCall()` function is available to access other [API data endpoints](https://developers.coinbase.com/api/v2#data-endpoints). For example to retried the current [buy price](https://developers.coinbase.com/api/v2#get-buy-price) of a cryptocurrency:
|
||||
|
||||
```kotlin
|
||||
apiCall(paths = listOf("prices", "BTC-USD", "buy"), params = emptyMap())
|
||||
```
|
||||
will return:
|
||||
|
||||
```json
|
||||
{"data":{"base":"BTC","currency":"USD","amount":"58977.17"}}
|
||||
```
|
||||
|
||||
See the [examples](https://github.com/ethauvin/cryptoprice/blob/master/examples/) for more details.
|
||||
|
||||
### Gradle, Maven, etc.
|
||||
|
||||
Instructions for using with Gradle, Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/artifact/net.thauvin.erik/cryptoprice/0.9.0/jar).
|
Loading…
Add table
Add a link
Reference in a new issue