lemdaddy commited on
Commit
2f3a7c5
·
1 Parent(s): 6a7abb7

Add new coingecko data endpoints

Browse files
run.py CHANGED
@@ -2,6 +2,13 @@ import json
2
  import pprint
3
  import asyncio
4
 
5
- import src.knowledge_bases.pipeline as Pipeline
6
 
7
- asyncio.run(Pipeline.main())
 
 
 
 
 
 
 
 
2
  import pprint
3
  import asyncio
4
 
5
+ # import src.knowledge_bases.pipeline as Pipeline
6
 
7
+ # asyncio.run(Pipeline.main())
8
+
9
+ from src.data_sources.coin_gecko import CoinGecko
10
+ from src.data_sources.cryptocompare import CryptoCompare
11
+
12
+ cgc = CoinGecko()
13
+
14
+ pprint.pprint(cgc.get_trending_coin_list())
src/data_sources/coin_gecko.py CHANGED
@@ -183,3 +183,84 @@ class CoinGecko:
183
 
184
  return result
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
  return result
185
 
186
+ @redis_cache(ttl=ONE_MONTH_IN_SECONDS)
187
+ @logger.instrument()
188
+ def get_coin_categories_list(self, cache_ttl: int = None) -> dict:
189
+ """
190
+ Retrieves a list of all available coin categories.
191
+
192
+ Args:
193
+ cache_ttl (int, optional): The time-to-live (in seconds) for the cached data. Defaults to None.
194
+
195
+ Returns:
196
+ dict: A dictionary containing a list of all available coin categories.
197
+
198
+ Example:
199
+ To get a list of all available coin categories, you can call:
200
+
201
+ ```python
202
+ category_list = coin_gecko.get_coin_categories_list()
203
+ ```
204
+
205
+ Note:
206
+ The `get_coin_categories_list` method uses the `redis_cache` decorator to cache the result for a specified time (`ONE_MONTH_IN_SECONDS`). This means that if the same request is made within the cache time, the cached result will be returned instead of making a new API call.
207
+ """
208
+ result = self.cgc.categories.get()
209
+ logger.debug(f"Result: {result}")
210
+
211
+ return { 'exchanges': result }
212
+
213
+ @redis_cache(ttl=ONE_HOUR_IN_SECONDS)
214
+ @logger.instrument()
215
+ def get_asset_platforms_list(self, cache_ttl: int = None) -> dict:
216
+ """
217
+ Retrieves a list of all available asset platforms.
218
+
219
+ Args:
220
+ cache_ttl (int, optional): The time-to-live (in seconds) for the cached data. Defaults to None.
221
+
222
+ Returns:
223
+ dict: A dictionary containing a list of all available asset platforms.
224
+
225
+ Example:
226
+ To get a list of all available asset platforms, you can call:
227
+
228
+ ```python
229
+ asset_platforms_list = coin_gecko.get_asset_platforms_list()
230
+ ```
231
+
232
+ Note:
233
+ The `get_asset_platforms_list` method uses the `redis_cache` decorator to cache the result for a specified time (`ONE_HOUR_IN_SECONDS`). This means that if the same request is made within the cache time, the cached result will be returned instead of making a new API call.
234
+ """
235
+ result = self.cgc.asset_platform.get()
236
+ logger.debug(f"Result: {result}")
237
+
238
+ return { 'exchanges': result }
239
+
240
+ @redis_cache(ttl=ONE_HOUR_IN_SECONDS)
241
+ @logger.instrument()
242
+ def get_trending_coin_list(self, cache_ttl: int = None) -> dict:
243
+ """
244
+ Retrieves a list of query trending 15 coins, 7 nfts and 5 categories on CoinGecko in the last 24 hours.
245
+
246
+ Args:
247
+ cache_ttl (int, optional): The time-to-live (in seconds) for the cached data. Defaults to None.
248
+
249
+ Returns:
250
+ dict: A dictionary containing a list of trending coins.
251
+
252
+ Example:
253
+ To get a list of trending coins, you can call:
254
+
255
+ ```python
256
+ trending_coins = coin_gecko.get_trending_coin_list()
257
+ ```
258
+
259
+ Note:
260
+ The `get_trending_coin_list` method uses the `redis_cache` decorator to cache the result for a specified time (`ONE_HOUR_IN_SECONDS`). This means that if the same request is made within the cache time, the cached result will be returned instead of making a new API call.
261
+ """
262
+ result = self.cgc.search.get_trending()
263
+ logger.debug(f"Result: {result}")
264
+
265
+ return { 'exchanges': result }
266
+
src/knowledge_bases/pipeline.py CHANGED
@@ -29,10 +29,13 @@ async def fetch_and_load_crypto_compare_json_data():
29
 
30
  async def fetch_and_load_coin_gecko_json_data():
31
  get_all_coins = make_async(coin_gecko.get_exchanges_list)
 
32
 
33
  all_exchange_data = await get_all_coins()
 
34
 
35
  await store_json_data_in_s3(all_exchange_data, "coin_gecko_all_exchange_data")
 
36
 
37
  async def load_json_data_into_knowledge_base():
38
  load_knowledge_base = make_async(json_knowledge_base.load_knowledge_base)
 
29
 
30
  async def fetch_and_load_coin_gecko_json_data():
31
  get_all_coins = make_async(coin_gecko.get_exchanges_list)
32
+ get_asset_platforms_list = make_async(coin_gecko.get_asset_platforms_list)
33
 
34
  all_exchange_data = await get_all_coins()
35
+ asset_platforms_list = await get_asset_platforms_list()
36
 
37
  await store_json_data_in_s3(all_exchange_data, "coin_gecko_all_exchange_data")
38
+ await store_json_data_in_s3(asset_platforms_list, "coin_gecko_asset_platforms_list")
39
 
40
  async def load_json_data_into_knowledge_base():
41
  load_knowledge_base = make_async(json_knowledge_base.load_knowledge_base)