generated from nathanwoodburn/python-webserver-template
feat: Add backup cardano balance in case of failures
All checks were successful
Build Docker / BuildImage (push) Successful in 39s
All checks were successful
Build Docker / BuildImage (push) Successful in 39s
This commit is contained in:
parent
3f6623b23e
commit
ac377092e6
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1734062225.4190562, "result": 555.700092455}
|
{"timestamp": 1734066903.4409394, "result": 555.700092455}
|
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1734062242.2106752, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.239815492, "price": 242.12, "value": 58.06412692304, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "balance": 1.0, "price": 1.001, "value": 1.001, "name": "USDC", "symbol": "usdc"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 23.664735, "price": 4.26, "value": 100.8117711, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3937.58, "value": 10.069770213, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00056828, "price": 99633, "value": 56.61944124, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa", "balance": 0.03683279, "price": 708.68, "value": 26.102661617199995, "name": "Binance Coin (Wormhole)", "symbol": "bnb"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 4.84, "value": 110.60813341952, "name": "Volo Staked SUI", "symbol": "vsui"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.67, "value": 4.21630999969, "name": "Sui", "symbol": "sui"}]}
|
{"timestamp": 1734066915.9325483, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.239815492, "price": 242.12, "value": 58.06412692304, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3937.58, "value": 10.069770213, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00056828, "price": 99633, "value": 56.61944124, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "balance": 1.0, "price": 1.001, "value": 1.001, "name": "USDC", "symbol": "usdc"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 23.664735, "price": 4.26, "value": 100.8117711, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa", "balance": 0.03683279, "price": 708.68, "value": 26.102661617199995, "name": "Binance Coin (Wormhole)", "symbol": "bnb"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 4.84, "value": 110.60813341952, "name": "Volo Staked SUI", "symbol": "vsui"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.67, "value": 4.21630999969, "name": "Sui", "symbol": "sui"}]}
|
2
cache/c652e896f57f598d23e3dbebdb815ef6.json
vendored
2
cache/c652e896f57f598d23e3dbebdb815ef6.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1734062233.5109293, "result": [{"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 4.84, "value": 110.60813341952, "name": "Volo Staked SUI", "symbol": "vsui"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.67, "value": 4.21630999969, "name": "Sui", "symbol": "sui"}]}
|
{"timestamp": 1734066910.9195087, "result": [{"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 4.84, "value": 110.60813341952, "name": "Volo Staked SUI", "symbol": "vsui"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.67, "value": 4.21630999969, "name": "Sui", "symbol": "sui"}]}
|
1
cache/cardano_balance.json
vendored
Normal file
1
cache/cardano_balance.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"balance": 82.815227}
|
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1734061993.7895577, "result": 82.815227}
|
{"timestamp": 1734067111.2072852, "result": 82.815227}
|
2
cache/d4e81748ee91683b2c48adaa5cf95187.json
vendored
2
cache/d4e81748ee91683b2c48adaa5cf95187.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1734062239.760602, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 16.49, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 50.08, "updated": "1734049470", "initial": 50, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 55, "url": "https://dydx.trade/vault", "value": 60.56, "updated": "1733966269", "initial": 60, "bought": "1733300000", "type": "Lending"}]}
|
{"timestamp": 1734067112.538988, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 16.49, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 50.08, "updated": "1734049470", "initial": 50, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 55, "url": "https://dydx.trade/vault", "value": 60.58, "updated": "1734063147", "initial": 60, "bought": "1733300000", "type": "Lending"}]}
|
21
server.py
21
server.py
@ -337,19 +337,30 @@ get_cardano_balance_cache = TTLCache(maxsize=1, ttl=3600)
|
|||||||
@cache.file_cache(300)
|
@cache.file_cache(300)
|
||||||
def getCardanoBalance(address: str):
|
def getCardanoBalance(address: str):
|
||||||
# Get balance of cardano address
|
# Get balance of cardano address
|
||||||
|
if not os.path.exists("cache/cardano_balance.json"):
|
||||||
|
with open("cache/cardano_balance.json", "w") as f:
|
||||||
|
json.dump({"balance": 0}, f)
|
||||||
|
last = 0
|
||||||
|
with open("cache/cardano_balance.json") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
last = data["balance"]
|
||||||
try:
|
try:
|
||||||
response = requests.get(f"https://cardano-mainnet.blockfrost.io/api/v0/accounts/{address}", headers={"project_id": blockFrost_API})
|
response = requests.get(f"https://cardano-mainnet.blockfrost.io/api/v0/accounts/{address}", headers={"project_id": blockFrost_API})
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print("Error getting cardano balance")
|
print("Error getting cardano balance",flush=True)
|
||||||
return 0
|
# Get last known balance
|
||||||
|
return last
|
||||||
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if "controlled_amount" in data:
|
if "controlled_amount" in data:
|
||||||
|
with open("cache/cardano_balance.json", "w") as f:
|
||||||
|
json.dump({"balance": int(data["controlled_amount"]) / 1000000}, f)
|
||||||
return int(data["controlled_amount"]) / 1000000
|
return int(data["controlled_amount"]) / 1000000
|
||||||
return 0
|
return last
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print("Error getting cardano balance")
|
print("Error getting cardano balance",flush=True)
|
||||||
return 0
|
return last
|
||||||
|
|
||||||
|
|
||||||
def getCardanoValue(address: str):
|
def getCardanoValue(address: str):
|
||||||
|
Loading…
Reference in New Issue
Block a user