mirror of
https://github.com/autistic-symposium/blockchain-data-engineering-toolkit.git
synced 2025-04-25 18:29:19 -04:00
💾
This commit is contained in:
parent
f23e1b9fd6
commit
a58c917f0f
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<br>
|
<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):
|
##### 🛠 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."""
|
"""Connect to the database."""
|
||||||
|
|
||||||
env_vars = os_utils.load_config()
|
env_vars = os_utils.load_config()
|
||||||
|
|
||||||
url = env_vars['MONGODB_URL']
|
url = env_vars['MONGODB_URL']
|
||||||
db_name = env_vars['MONGODB_DB_NAME']
|
db_name = env_vars['MONGODB_DB_NAME']
|
||||||
collection = env_vars['MONGODB_COLLECTION_NAME']
|
collection = env_vars['MONGODB_COLLECTION_NAME']
|
||||||
@ -25,12 +24,6 @@ def _get_db_collection():
|
|||||||
return database[collection]
|
return database[collection]
|
||||||
|
|
||||||
|
|
||||||
def _wallet_helper(item) -> dict:
|
|
||||||
return {
|
|
||||||
"wallet": item["wallet"],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _balancer_helper(item) -> dict:
|
def _balancer_helper(item) -> dict:
|
||||||
return {
|
return {
|
||||||
"wallet": item["wallet"],
|
"wallet": item["wallet"],
|
||||||
@ -42,23 +35,21 @@ def _balancer_helper(item) -> dict:
|
|||||||
# Public methods: database #
|
# Public methods: database #
|
||||||
############################################
|
############################################
|
||||||
|
|
||||||
async def retrieve_top_balances() -> list:
|
async def retrieve_top_balances(top_number=None) -> list:
|
||||||
"""Retrieve top balances from the database."""
|
"""Retrieve top balances from the database."""
|
||||||
|
|
||||||
top_number = 100
|
top_number = top_number or 100
|
||||||
collection = _get_db_collection()
|
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 = []
|
result = []
|
||||||
counter = 0
|
for item in top_balances:
|
||||||
|
result.append({
|
||||||
for balance in top_balances:
|
"wallet": item["wallet"],
|
||||||
result.append(_wallet_helper(balance))
|
"balance": item["balance"],
|
||||||
if counter > top_number:
|
})
|
||||||
break
|
|
||||||
counter += 1
|
|
||||||
|
|
||||||
return top_balances
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def retrieve_balance(wallet: str) -> dict:
|
async def retrieve_balance(wallet: str) -> dict:
|
||||||
@ -73,7 +64,6 @@ async def retrieve_balance(wallet: str) -> dict:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def retrieve_holder_weekly_change(address: str) -> int:
|
async def retrieve_holder_weekly_change(address: str) -> int:
|
||||||
"""Retrieve weekly change of a given address."""
|
"""Retrieve weekly change of a given address."""
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ async def get_token_balance(address: str) -> dict:
|
|||||||
if result:
|
if result:
|
||||||
return {"result": result}
|
return {"result": result}
|
||||||
else:
|
else:
|
||||||
return {"error": "wallet not found"}
|
return {"error": "Wallet not found"}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/top")
|
@router.get("/top")
|
||||||
@ -37,14 +37,14 @@ async def get_top_holders() -> dict:
|
|||||||
futures = [retrieve_top_balances()]
|
futures = [retrieve_top_balances()]
|
||||||
result = await asyncio.gather(*futures)
|
result = await asyncio.gather(*futures)
|
||||||
if result:
|
if result:
|
||||||
return {"result": result}
|
return {"result": result[0]}
|
||||||
else:
|
else:
|
||||||
return {"error": "No holders found"}
|
return {"error": "No holders found"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/weekly/{address}")
|
@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."""
|
"""Get weekly change of a given address."""
|
||||||
|
|
||||||
futures = [retrieve_holder_weekly_change(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:
|
if result:
|
||||||
return {"result": result}
|
return {"result": result}
|
||||||
else:
|
else:
|
||||||
return {"error": "wallet not found"}
|
return {"error": "Wallet not found"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user