├── .github
└── workflows
│ └── maven.yml
├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── litesoftwares
│ └── coingecko
│ ├── CoinGeckoApi.java
│ ├── CoinGeckoApiClient.java
│ ├── CoinGeckoApiError.java
│ ├── CoinGeckoApiService.java
│ ├── constant
│ ├── Currency.java
│ └── Order.java
│ ├── domain
│ ├── AssetPlatforms.java
│ ├── Coins
│ │ ├── CoinData
│ │ │ ├── CodeAdditionsDeletions4Weeks.java
│ │ │ ├── CommunityData.java
│ │ │ ├── DeveloperData.java
│ │ │ ├── IcoData.java
│ │ │ ├── Links.java
│ │ │ ├── Links_.java
│ │ │ ├── PublicInterestStats.java
│ │ │ ├── ReposUrl.java
│ │ │ ├── Roi.java
│ │ │ └── SparklineIn7d.java
│ │ ├── CoinFullData.java
│ │ ├── CoinHistoryById.java
│ │ ├── CoinList.java
│ │ ├── CoinMarkets.java
│ │ ├── CoinTickerById.java
│ │ ├── MarketChart.java
│ │ └── MarketData.java
│ ├── Events
│ │ ├── EventCountries.java
│ │ ├── EventCountryData.java
│ │ ├── EventData.java
│ │ ├── EventTypes.java
│ │ └── Events.java
│ ├── ExchangeRates
│ │ ├── ExchangeRates.java
│ │ └── Rate.java
│ ├── Exchanges
│ │ ├── ExchangeById.java
│ │ ├── Exchanges.java
│ │ ├── ExchangesList.java
│ │ └── ExchangesTickersById.java
│ ├── Global
│ │ ├── DecentralizedFinanceDefi.java
│ │ ├── DecentralizedFinanceDefiData.java
│ │ ├── Global.java
│ │ └── GlobalData.java
│ ├── Ping.java
│ ├── Search
│ │ ├── Search.java
│ │ ├── SearchCategory.java
│ │ ├── SearchCoin.java
│ │ ├── SearchExchange.java
│ │ ├── SearchNft.java
│ │ ├── Trending.java
│ │ ├── TrendingCoin.java
│ │ └── TrendingCoinItem.java
│ ├── Shared
│ │ ├── Image.java
│ │ ├── Market.java
│ │ └── Ticker.java
│ └── Status
│ │ ├── Project.java
│ │ ├── StatusUpdates.java
│ │ └── Update.java
│ ├── exception
│ └── CoinGeckoApiException.java
│ └── impl
│ └── CoinGeckoApiClientImpl.java
└── test
└── java
└── com
└── litesoftwares
└── coingecko
└── examples
├── AssetPlatformsExample.java
├── CoinsExample.java
├── DecentralizedFinanceDefiExample.java
├── EventsExample.java
├── ExchangeRatesExample.java
├── ExchangesExample.java
├── GlobalExample.java
├── PingExample.java
├── SearchExample.java
├── SimpleExample.java
├── StatusUpdatesExample.java
└── TrendingExample.java
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3 |
4 | # This workflow uses actions that are not certified by GitHub.
5 | # They are provided by a third-party and are governed by
6 | # separate terms of service, privacy policy, and support
7 | # documentation.
8 |
9 | name: Java CI with Maven
10 |
11 | on:
12 | push:
13 | branches: [ "master" ]
14 | pull_request:
15 | branches: [ "master" ]
16 |
17 | jobs:
18 | build:
19 |
20 | runs-on: ubuntu-latest
21 |
22 | steps:
23 | - uses: actions/checkout@v3
24 | - name: Set up JDK 17
25 | uses: actions/setup-java@v3
26 | with:
27 | java-version: '17'
28 | distribution: 'temurin'
29 | cache: maven
30 | - name: Build with Maven
31 | run: mvn -B package --file pom.xml
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3 |
4 | #idea folder
5 | .idea/
6 |
7 | # User-specific stuff
8 | .idea/**/workspace.xml
9 | .idea/**/tasks.xml
10 | .idea/**/usage.statistics.xml
11 | .idea/**/dictionaries
12 | .idea/**/shelf
13 |
14 | # Generated files
15 | .idea/**/contentModel.xml
16 |
17 | # Sensitive or high-churn files
18 | .idea/**/dataSources/
19 | .idea/**/dataSources.ids
20 | .idea/**/dataSources.local.xml
21 | .idea/**/sqlDataSources.xml
22 | .idea/**/dynamic.xml
23 | .idea/**/uiDesigner.xml
24 | .idea/**/dbnavigator.xml
25 |
26 | # Gradle
27 | .idea/**/gradle.xml
28 | .idea/**/libraries
29 |
30 | # Gradle and Maven with auto-import
31 | # When using Gradle or Maven with auto-import, you should exclude module files,
32 | # since they will be recreated, and may cause churn. Uncomment if using
33 | # auto-import.
34 | # .idea/modules.xml
35 | # .idea/*.iml
36 | # .idea/modules
37 |
38 | # CMake
39 | cmake-build-*/
40 |
41 | # Mongo Explorer plugin
42 | .idea/**/mongoSettings.xml
43 |
44 | # File-based project format
45 | *.iws
46 |
47 | # IntelliJ
48 | out/
49 |
50 | # Eclipse
51 | .settings
52 | .classpath
53 | .project
54 |
55 | # Maven
56 | target/
57 |
58 | # mpeltonen/sbt-idea plugin
59 | .idea_modules/
60 |
61 | # JIRA plugin
62 | atlassian-ide-plugin.xml
63 |
64 | # Cursive Clojure plugin
65 | .idea/replstate.xml
66 |
67 | # Crashlytics plugin (for Android Studio and IntelliJ)
68 | com_crashlytics_export_strings.xml
69 | crashlytics.properties
70 | crashlytics-build.properties
71 | fabric.properties
72 |
73 | # Editor-based Rest Client
74 | .idea/httpRequests
75 |
76 | # Package Files #
77 | *.jar
78 | *.war
79 | *.ear
80 | *.zip
81 | *.tar.gz
82 | *.rar
83 | *.iml
84 |
85 | # Compiled class file
86 | *.class
87 |
88 | # Log file
89 | *.log
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Philip Okugbe
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CoinGecko-Java
2 | 
3 |
4 | Java wrapper for the CoinGecko API.
5 |
6 |
7 |
8 |
9 | ## Usage
10 | This API client covers all CoinGecko's API endpoints and i'll try to update it when new endpoints are added.
11 |
12 | For complete API documentation please refer to https://www.coingecko.com/api/docs/v3.
13 |
14 | For examples Goto: Examples.
15 |
16 | ```
17 | CoinGeckoApiClient client = new CoinGeckoApiClientImpl();
18 | client.ping();
19 | client.shutdown();
20 | ```
21 |
22 | To get price of a currency in USD
23 | ```
24 | client.getPrice("bitcoin",Currency.USD);
25 | ```
26 |
27 | ## License
28 | MIT License
29 |
30 | Copyright (c) 2019 Philip Okugbe
31 |
32 | Permission is hereby granted, free of charge, to any person obtaining a copy
33 | of this software and associated documentation files (the "Software"), to deal
34 | in the Software without restriction, including without limitation the rights
35 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36 | copies of the Software, and to permit persons to whom the Software is
37 | furnished to do so, subject to the following conditions:
38 |
39 | The above copyright notice and this permission notice shall be included in all
40 | copies or substantial portions of the Software.
41 |
42 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48 | SOFTWARE.
49 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.litesoftwares
8 | coingecko-java
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 1.8
13 | 1.8
14 | UTF-8
15 |
16 |
17 |
18 |
19 |
20 | com.squareup.retrofit2
21 | retrofit
22 | 2.9.0
23 |
24 |
25 |
26 | com.squareup.retrofit2
27 | converter-jackson
28 | 2.9.0
29 |
30 |
31 |
32 | org.projectlombok
33 | lombok
34 | 1.18.28
35 | provided
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-compiler-plugin
44 | 3.11.0
45 |
46 | 1.8
47 | 1.8
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/main/java/com/litesoftwares/coingecko/CoinGeckoApi.java:
--------------------------------------------------------------------------------
1 | package com.litesoftwares.coingecko;
2 |
3 | import com.litesoftwares.coingecko.exception.CoinGeckoApiException;
4 | import okhttp3.OkHttpClient;
5 | import retrofit2.Call;
6 | import retrofit2.Response;
7 | import retrofit2.Retrofit;
8 | import retrofit2.converter.jackson.JacksonConverterFactory;
9 |
10 | import java.io.IOException;
11 | import java.lang.annotation.Annotation;
12 | import java.util.concurrent.TimeUnit;
13 |
14 | public class CoinGeckoApi {
15 | private final String API_BASE_URL = "https://api.coingecko.com/api/v3/";
16 |
17 | private OkHttpClient okHttpClient = null;
18 | private Retrofit retrofit = null;
19 |
20 | public S createService(Class serviceClass, Long connectionTimeoutSeconds, Long readTimeoutSeconds, Long writeTimeoutSeconds){
21 | okHttpClient = new OkHttpClient.Builder()
22 | .connectTimeout(connectionTimeoutSeconds, TimeUnit.SECONDS)
23 | .readTimeout(readTimeoutSeconds, TimeUnit.SECONDS)
24 | .writeTimeout(writeTimeoutSeconds, TimeUnit.SECONDS)
25 | .build();
26 |
27 | retrofit = new Retrofit.Builder()
28 | .baseUrl(API_BASE_URL)
29 | .client(okHttpClient)
30 | .addConverterFactory(JacksonConverterFactory.create())
31 | .build();
32 |
33 | return retrofit.create(serviceClass);
34 | }
35 |
36 | public T executeSync(Call call) {
37 | try {
38 | Response response = call.execute();
39 | if (response.isSuccessful()) {
40 | return response.body();
41 | } else if(response.code() == 429) {
42 | // When the client gets rate limited the response is a CloudFlare error page,
43 | // not a regular error body.
44 | CoinGeckoApiError apiError = new CoinGeckoApiError();
45 | apiError.setCode(1015);
46 | apiError.setMessage("Rate limited");
47 | throw new CoinGeckoApiException(apiError);
48 | } else {
49 | try {
50 | CoinGeckoApiError apiError = getCoinGeckoApiError(response);
51 | apiError.setCode(response.code());
52 | throw new CoinGeckoApiException(apiError);
53 | } catch (IOException e) {
54 | throw new CoinGeckoApiException(response.toString(), e);
55 | }
56 | }
57 | } catch (IOException e) {
58 | throw new CoinGeckoApiException(e);
59 | } finally {
60 | shutdown();
61 | }
62 | }
63 |
64 | public void shutdown() {
65 | if (okHttpClient != null) {
66 | okHttpClient.dispatcher().executorService().shutdown();
67 | okHttpClient.connectionPool().evictAll();
68 | }
69 | }
70 |
71 | private CoinGeckoApiError getCoinGeckoApiError(Response> response) throws IOException{
72 | return (CoinGeckoApiError) retrofit.responseBodyConverter(CoinGeckoApiError.class,new Annotation[0])
73 | .convert(response.errorBody());
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/litesoftwares/coingecko/CoinGeckoApiClient.java:
--------------------------------------------------------------------------------
1 | package com.litesoftwares.coingecko;
2 |
3 | import com.litesoftwares.coingecko.domain.*;
4 | import com.litesoftwares.coingecko.domain.Coins.*;
5 | import com.litesoftwares.coingecko.domain.Events.EventCountries;
6 | import com.litesoftwares.coingecko.domain.Events.EventTypes;
7 | import com.litesoftwares.coingecko.domain.Events.Events;
8 | import com.litesoftwares.coingecko.domain.ExchangeRates.ExchangeRates;
9 | import com.litesoftwares.coingecko.domain.Exchanges.*;
10 | import com.litesoftwares.coingecko.domain.Global.DecentralizedFinanceDefi;
11 | import com.litesoftwares.coingecko.domain.Global.Global;
12 | import com.litesoftwares.coingecko.domain.Search.Search;
13 | import com.litesoftwares.coingecko.domain.Search.Trending;
14 | import com.litesoftwares.coingecko.domain.Status.StatusUpdates;
15 |
16 | import java.util.List;
17 | import java.util.Map;
18 |
19 | public interface CoinGeckoApiClient {
20 | Ping ping();
21 |
22 | Map> getPrice(String ids, String vsCurrencies);
23 |
24 | Map> getPrice(String ids, String vsCurrencies, boolean includeMarketCap, boolean include24hrVol,
25 | boolean include24hrChange, boolean includeLastUpdatedAt);
26 |
27 | Map> getTokenPrice(String id, String contractAddress, String vsCurrencies);
28 |
29 | Map> getTokenPrice(String id, String contractAddress, String vsCurrencies, boolean includeMarketCap,
30 | boolean include24hrVol, boolean include24hrChange, boolean includeLastUpdatedAt);
31 |
32 | List getSupportedVsCurrencies();
33 |
34 | List getCoinList();
35 |
36 | List getCoinMarkets(String vsCurrency);
37 |
38 | List getCoinMarkets(String vsCurrency, String ids, String order, Integer perPage, Integer page, boolean sparkline, String priceChangePercentage);
39 |
40 | List getCoinMarkets(String vsCurrency, String ids, String category, String order, Integer perPage, Integer page, boolean sparkline, String priceChangePercentage);
41 |
42 | CoinFullData getCoinById(String id);
43 |
44 | CoinFullData getCoinById(String id, boolean localization, boolean tickers, boolean marketData, boolean communityData, boolean developerData, boolean sparkline);
45 |
46 | CoinTickerById getCoinTickerById(String id);
47 |
48 | CoinTickerById getCoinTickerById(String id, String exchangeIds, Integer page, String order);
49 |
50 | CoinHistoryById getCoinHistoryById(String id, String date);
51 |
52 | CoinHistoryById getCoinHistoryById(String id, String data, boolean localization);
53 |
54 | MarketChart getCoinMarketChartById(String id, String vsCurrency, Integer days);
55 |
56 | MarketChart getCoinMarketChartById(String id, String vsCurrency, Integer days, String interval);
57 |
58 | MarketChart getCoinMarketChartRangeById(String id, String vsCurrency, String from, String to);
59 |
60 | List> getCoinOHLC(String id, String vsCurrency, Integer days);
61 |
62 | StatusUpdates getCoinStatusUpdateById(String id);
63 |
64 | StatusUpdates getCoinStatusUpdateById(String id, Integer perPage, Integer page);
65 |
66 | CoinFullData getCoinInfoByContractAddress(String id, String contractAddress);
67 |
68 | List getAssetPlatforms();
69 |
70 | List getExchanges();
71 |
72 | List getExchanges(int perPage, int page);
73 |
74 | List getExchangesList();
75 |
76 | ExchangeById getExchangesById(String id);
77 |
78 | ExchangesTickersById getExchangesTickersById(String id);
79 |
80 | ExchangesTickersById getExchangesTickersById(String id, String coinIds, Integer page, String order);
81 |
82 | StatusUpdates getExchangesStatusUpdatesById(String id);
83 |
84 | StatusUpdates getExchangesStatusUpdatesById(String id, Integer perPage, Integer page);
85 |
86 | List> getExchangesVolumeChart(String id, Integer days);
87 |
88 | @Deprecated
89 | StatusUpdates getStatusUpdates();
90 |
91 | @Deprecated
92 | StatusUpdates getStatusUpdates(String category, String projectType, Integer perPage, Integer page);
93 |
94 | @Deprecated
95 | Events getEvents();
96 |
97 | @Deprecated
98 | Events getEvents(String countryCode, String type, Integer page, boolean upcomingEventsOnly, String fromDate, String toDate);
99 |
100 | @Deprecated
101 | EventCountries getEventsCountries();
102 |
103 | @Deprecated
104 | EventTypes getEventsTypes();
105 |
106 | ExchangeRates getExchangeRates();
107 |
108 | Trending getTrending();
109 |
110 | Search getSearchResult(String query);
111 |
112 | Global getGlobal();
113 |
114 | DecentralizedFinanceDefi getDecentralizedFinanceDefi();
115 |
116 | void shutdown();
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/com/litesoftwares/coingecko/CoinGeckoApiError.java:
--------------------------------------------------------------------------------
1 | package com.litesoftwares.coingecko;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import lombok.*;
6 |
7 | @Data
8 | @JsonIgnoreProperties(ignoreUnknown = true)
9 |
10 | public class CoinGeckoApiError {
11 | @JsonProperty("code")
12 | private int code;
13 | @JsonProperty("error")
14 | private String message;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/litesoftwares/coingecko/CoinGeckoApiService.java:
--------------------------------------------------------------------------------
1 | package com.litesoftwares.coingecko;
2 |
3 | import com.litesoftwares.coingecko.domain.*;
4 | import com.litesoftwares.coingecko.domain.Coins.*;
5 | import com.litesoftwares.coingecko.domain.Events.EventCountries;
6 | import com.litesoftwares.coingecko.domain.Events.EventTypes;
7 | import com.litesoftwares.coingecko.domain.Events.Events;
8 | import com.litesoftwares.coingecko.domain.ExchangeRates.ExchangeRates;
9 | import com.litesoftwares.coingecko.domain.Exchanges.*;
10 | import com.litesoftwares.coingecko.domain.Global.DecentralizedFinanceDefi;
11 | import com.litesoftwares.coingecko.domain.Global.Global;
12 | import com.litesoftwares.coingecko.domain.Search.Search;
13 | import com.litesoftwares.coingecko.domain.Search.Trending;
14 | import com.litesoftwares.coingecko.domain.Status.StatusUpdates;
15 | import retrofit2.Call;
16 | import retrofit2.http.GET;
17 | import retrofit2.http.Path;
18 | import retrofit2.http.Query;
19 |
20 | import java.util.List;
21 | import java.util.Map;
22 |
23 | public interface CoinGeckoApiService {
24 | @GET("ping")
25 | Call ping();
26 |
27 | @GET("simple/price")
28 | Call