Implemented buyPrice and sellPrice. Closes #1
This commit is contained in:
parent
c046cd7341
commit
bef4b2ee20
18 changed files with 152 additions and 98 deletions
41
README.md
41
README.md
|
@ -1,10 +1,10 @@
|
|||
[](https://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://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/cryptoprice/) -->
|
||||
[](https://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://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/cryptoprice/)
|
||||
|
||||
[](https://snyk.io/test/github/ethauvin/cryptoprice?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_cryptoprice) [](https://github.com/ethauvin/cryptoprice/actions/workflows/gradle.yml) [](https://circleci.com/gh/ethauvin/cryptoprice/tree/master)
|
||||
|
||||
# Retrieve cryptocurrencies current prices
|
||||
# Retrieve cryptocurrencies current (buy, sell or spot) prices
|
||||
|
||||
A simple Kotlin/Java/Android implementation of the spot price [Coinbase Public API](https://developers.coinbase.com/api/v2#get-spot-price).
|
||||
A simple Kotlin/Java/Android implementation of the prices [Coinbase Public API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices).
|
||||
|
||||
## Examples (TL;DR)
|
||||
|
||||
|
@ -16,7 +16,10 @@ import net.thauvin.erik.crypto.CryptoPrice.Companion.spotPrice
|
|||
val btc = spotPrice("BTC") // Bitcoin
|
||||
println(btc.amount)
|
||||
|
||||
val eth = spotPrice("ETH", "EUR") // Ethereum in Euros
|
||||
val eth = sellPrice("ETH", "EUR") // Ethereum in Euro
|
||||
println(eth.amount)
|
||||
|
||||
val eth = buyPrice("LTC", "GBP") // Litecoin in Pound sterling
|
||||
println(eth.amount)
|
||||
|
||||
```
|
||||
|
@ -28,21 +31,31 @@ To use with [Gradle](https://gradle.org/), include the following dependency in y
|
|||
|
||||
```gradle
|
||||
dependencies {
|
||||
implementation("net.thauvin.erik:cryptoprice:0.9.0")
|
||||
implementation("net.thauvin.erik:cryptoprice:1.0.0-SNAPSHOT")
|
||||
}
|
||||
```
|
||||
|
||||
Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/artifact/net.thauvin.erik/cryptoprice/0.9.0/jar).
|
||||
Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/search?q=g:%22net.thauvin.erik%22%20AND%20a:%22cryptoprice%22).
|
||||
|
||||
### Spot Price
|
||||
### Prices
|
||||
|
||||
The `spotPrice` function defines the following parameters:
|
||||
The `spotPrice`, `buyPrice` and `sellPrice` functions define the following parameters:
|
||||
|
||||
```kotlin
|
||||
spotPrice(
|
||||
base: String, // Required
|
||||
currency: String = "USD",
|
||||
date: LocalDate? = null,
|
||||
date: LocalDate? = null
|
||||
)
|
||||
|
||||
buyPrice(
|
||||
base: String, // Required
|
||||
currency: String = "USD"
|
||||
)
|
||||
|
||||
sellPrice(
|
||||
base: String, // Required
|
||||
currency: String = "USD"
|
||||
)
|
||||
```
|
||||
|
||||
|
@ -57,7 +70,7 @@ A `CryptoPrice` object is returned defined as follows:
|
|||
```kotlin
|
||||
CryptoPrice(val base: String, val currency: String, val amount: BigDecimal)
|
||||
```
|
||||
The parameter names match the [Coinbase API](https://developers.coinbase.com/api/v2#get-spot-price).
|
||||
The parameter names match the [Coinbase API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices).
|
||||
|
||||
#### Format
|
||||
|
||||
|
@ -86,7 +99,7 @@ println(price.toJson())
|
|||
{"data":{"base":"BTC","currency":"USD","amount":"34567.89"}}
|
||||
```
|
||||
|
||||
The `data` object matches the [Coinbase API](https://developers.coinbase.com/api/v2#get-spot-price). To specify a different (or no) key, use:
|
||||
The `data` object matches the [Coinbase API](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-spot-price). To specify a different (or no) key, use:
|
||||
|
||||
```kotlin
|
||||
println(price.toJson("bitcoin"))
|
||||
|
@ -109,15 +122,15 @@ val eth = """{"ether":{"base":"ETH","currency":"USD","amount":"2345.67"}}""".toP
|
|||
|
||||
### Extending
|
||||
|
||||
A generic `apiCall()` function is available to access other [API data endpoints](https://developers.coinbase.com/api/v2#data-endpoints). For example to retrieve the current [buy price](https://developers.coinbase.com/api/v2#get-buy-price) of a cryptocurrency:
|
||||
A generic `apiCall()` function is available to access other [data API endpoints](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies). For example to retrieve the [exchange rates](https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates):
|
||||
|
||||
```kotlin
|
||||
apiCall(paths = listOf("prices", "BTC-USD", "buy"), params = emptyMap())
|
||||
apiCall(listOf("exchange-rates"), mapOf("currency" to "usd"))
|
||||
```
|
||||
will return something like:
|
||||
|
||||
```json
|
||||
{"data":{"base":"BTC","currency":"USD","amount":"34554.32"}}
|
||||
{"data":{"currency":"BTC","rates":{"AED":"36.73","AFN":"589.50",...}}}
|
||||
```
|
||||
|
||||
See the [examples](https://github.com/ethauvin/cryptoprice/blob/master/examples/) for more details.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue