mirror of
https://github.com/autistic-symposium/blockchain-data-engineering-toolkit.git
synced 2025-04-25 10:19:13 -04:00
💾
This commit is contained in:
parent
f23e1b9fd6
commit
a58c917f0f
@ -2,7 +2,7 @@
|
||||
|
||||
<br>
|
||||
|
||||
##### 👉 this repository contains my blockchain engineering projects such as scalable event scanners and infrastructure setups for on-chain analysis and machine learning models training (*e.g.*, high-frequency trading with deep learning).
|
||||
##### 👉 this repository contains my blockchain engineering projects such as scalable event scanners and infrastructure setups for on-chain analysis and machine learning models training (*e.g.*, HFT with deep learning).
|
||||
|
||||
##### 🛠 here is a high-level system design chart for a possible blockchain intelligence data platform (all deployed in kubernetes):
|
||||
|
||||
|
@ -15,7 +15,6 @@ def _get_db_collection():
|
||||
"""Connect to the database."""
|
||||
|
||||
env_vars = os_utils.load_config()
|
||||
|
||||
url = env_vars['MONGODB_URL']
|
||||
db_name = env_vars['MONGODB_DB_NAME']
|
||||
collection = env_vars['MONGODB_COLLECTION_NAME']
|
||||
@ -25,12 +24,6 @@ def _get_db_collection():
|
||||
return database[collection]
|
||||
|
||||
|
||||
def _wallet_helper(item) -> dict:
|
||||
return {
|
||||
"wallet": item["wallet"],
|
||||
}
|
||||
|
||||
|
||||
def _balancer_helper(item) -> dict:
|
||||
return {
|
||||
"wallet": item["wallet"],
|
||||
@ -42,23 +35,21 @@ def _balancer_helper(item) -> dict:
|
||||
# Public methods: database #
|
||||
############################################
|
||||
|
||||
async def retrieve_top_balances() -> list:
|
||||
async def retrieve_top_balances(top_number=None) -> list:
|
||||
"""Retrieve top balances from the database."""
|
||||
|
||||
top_number = 100
|
||||
top_number = top_number or 100
|
||||
collection = _get_db_collection()
|
||||
top_balances = collection.find()#.sort({"balance"}, pymongo.DESCENDING).limit(top_number)
|
||||
top_balances = collection.find().sort("balance", -1).limit(top_number)
|
||||
|
||||
result = []
|
||||
counter = 0
|
||||
|
||||
for balance in top_balances:
|
||||
result.append(_wallet_helper(balance))
|
||||
if counter > top_number:
|
||||
break
|
||||
counter += 1
|
||||
for item in top_balances:
|
||||
result.append({
|
||||
"wallet": item["wallet"],
|
||||
"balance": item["balance"],
|
||||
})
|
||||
|
||||
return top_balances
|
||||
return result
|
||||
|
||||
|
||||
async def retrieve_balance(wallet: str) -> dict:
|
||||
@ -73,7 +64,6 @@ async def retrieve_balance(wallet: str) -> dict:
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
async def retrieve_holder_weekly_change(address: str) -> int:
|
||||
"""Retrieve weekly change of a given address."""
|
||||
|
||||
|
@ -27,7 +27,7 @@ async def get_token_balance(address: str) -> dict:
|
||||
if result:
|
||||
return {"result": result}
|
||||
else:
|
||||
return {"error": "wallet not found"}
|
||||
return {"error": "Wallet not found"}
|
||||
|
||||
|
||||
@router.get("/top")
|
||||
@ -37,14 +37,14 @@ async def get_top_holders() -> dict:
|
||||
futures = [retrieve_top_balances()]
|
||||
result = await asyncio.gather(*futures)
|
||||
if result:
|
||||
return {"result": result}
|
||||
return {"result": result[0]}
|
||||
else:
|
||||
return {"error": "No holders found"}
|
||||
|
||||
|
||||
|
||||
@router.get("/weekly/{address}")
|
||||
async def get_holder_weekly_change(env_vars: dict, address: str) -> dict:
|
||||
async def get_holder_weekly_change(address: str) -> dict:
|
||||
"""Get weekly change of a given address."""
|
||||
|
||||
futures = [retrieve_holder_weekly_change(address)]
|
||||
@ -52,4 +52,4 @@ async def get_holder_weekly_change(env_vars: dict, address: str) -> dict:
|
||||
if result:
|
||||
return {"result": result}
|
||||
else:
|
||||
return {"error": "wallet not found"}
|
||||
return {"error": "Wallet not found"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user