generated from nathanwoodburn/python-webserver-template
This commit is contained in:
parent
a67f75e788
commit
6a628494ad
2
cache/1981e30de11cf0845e8b5affb4dc75e0.json
vendored
2
cache/1981e30de11cf0845e8b5affb4dc75e0.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390401.1929479, "result": 3920.13}
|
{"timestamp": 1733397804.3863032, "result": 3929.35}
|
2
cache/1ccff5c6f117409fea0c861aa44b8e62.json
vendored
2
cache/1ccff5c6f117409fea0c861aa44b8e62.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390448.2838762, "result": 1.22}
|
{"timestamp": 1733397866.6526587, "result": 1.23}
|
2
cache/29409a8a40dd2d547a7a44b8f6758f54.json
vendored
2
cache/29409a8a40dd2d547a7a44b8f6758f54.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390447.3589993, "result": 4.19}
|
{"timestamp": 1733397805.5214965, "result": 4.2}
|
2
cache/4104ed0427efe63d4ca0dead970a4391.json
vendored
2
cache/4104ed0427efe63d4ca0dead970a4391.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390400.7691364, "result": 249.8}
|
{"timestamp": 1733397803.5678928, "result": 253.67}
|
1
cache/46c1ec7f5edb30c070003dc54e072f41.json
vendored
Normal file
1
cache/46c1ec7f5edb30c070003dc54e072f41.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"timestamp": 1733399146.2576907, "result": 3.86}
|
2
cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
vendored
2
cache/598f5dbf97fb0d45cbc6e1a5b0a3b575.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733388581.604049, "result": 235.89}
|
{"timestamp": 1733397797.9360924, "result": 238.75}
|
1
cache/6cc6c6a0b2d0654f551d33209c1fd824.json
vendored
Normal file
1
cache/6cc6c6a0b2d0654f551d33209c1fd824.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"timestamp": 1733399182.7510748, "result": 4.0}
|
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
2
cache/6eec370e2713cfc84c84e1080b8a191a.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390403.2274024, "result": 129.72815534}
|
{"timestamp": 1733397796.5670946, "result": 129.72815534}
|
2
cache/790b28a9a21cf694ad9577ef1072ac9e.json
vendored
2
cache/790b28a9a21cf694ad9577ef1072ac9e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390450.351181, "result": 0.005776758}
|
{"timestamp": 1733397869.634003, "result": 0.009266758}
|
2
cache/94ac30c93587c50252ac382a8d02257f.json
vendored
2
cache/94ac30c93587c50252ac382a8d02257f.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390400.5671725, "result": 1.36267944462}
|
{"timestamp": 1733397797.9369814, "result": 2.2124384725}
|
2
cache/a071d7bdda25c22e42ad7840f17c4b0e.json
vendored
2
cache/a071d7bdda25c22e42ad7840f17c4b0e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390400.5661695, "result": 1.001}
|
{"timestamp": 1733397802.560489, "result": 1.0}
|
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
2
cache/a0ee60913ba556f39d128e7d7249e788.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390451.4364688, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 249.8, "value": 9.9459099016, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3920.13, "value": 10.0251444555, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.19, "value": 10.06579203, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}
|
{"timestamp": 1733397805.5292268, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 253.67, "value": 10.09999585564, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3929.35, "value": 10.0487232225, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.2, "value": 10.0898154, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}
|
1
cache/aa9601d66ea6f4944a14e832c94d5077.json
vendored
Normal file
1
cache/aa9601d66ea6f4944a14e832c94d5077.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"timestamp": 1733397988.7280235, "result": 3.86}
|
2
cache/b81351778df9f812bbd75ee85a7a073e.json
vendored
2
cache/b81351778df9f812bbd75ee85a7a073e.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390500.4894085, "result": 132.43410277172}
|
{"timestamp": 1733397866.6532238, "result": 134.31370216064}
|
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
2
cache/ccf2a009e56f1b05d471a55d9c9ea8ea.json
vendored
@ -1 +1 @@
|
|||||||
{"timestamp": 1733390448.4887109, "result": 82.815227}
|
{"timestamp": 1733397806.33151, "result": 82.815227}
|
66
server.py
66
server.py
@ -51,6 +51,8 @@ stWDBRN_token_mint = Pubkey.from_string(
|
|||||||
vault_sol_address = Pubkey.from_string(
|
vault_sol_address = Pubkey.from_string(
|
||||||
"NWywvhcqdkJsm1s9VVviPm9UfyDtyCW9t8kDb24PDPN")
|
"NWywvhcqdkJsm1s9VVviPm9UfyDtyCW9t8kDb24PDPN")
|
||||||
vault_cardano_address = "stake1uy4qd785pcds7ph2jue2lrhhxa698c5959375lqdv3yphcgwc8qna"
|
vault_cardano_address = "stake1uy4qd785pcds7ph2jue2lrhhxa698c5959375lqdv3yphcgwc8qna"
|
||||||
|
vault_sui_address = "0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da"
|
||||||
|
|
||||||
|
|
||||||
fiat = "USD"
|
fiat = "USD"
|
||||||
usd_to_fiat = 1
|
usd_to_fiat = 1
|
||||||
@ -178,10 +180,10 @@ def get_coin_price(coin_id):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
@cache.file_cache()
|
@cache.file_cache()
|
||||||
def get_token_price(token_address: str):
|
def get_token_price(token_address: str, chain='solana'):
|
||||||
try:
|
try:
|
||||||
price = coingecko_client.get_token_price(
|
price = coingecko_client.get_token_price(
|
||||||
id='solana', contract_addresses=token_address, vs_currencies=fiat)
|
id=chain, contract_addresses=token_address, vs_currencies=fiat)
|
||||||
return price[token_address][fiat.lower()]
|
return price[token_address][fiat.lower()]
|
||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
@ -201,14 +203,11 @@ def getSolBalance() -> int:
|
|||||||
vault_sol_address).value / 1000000000
|
vault_sol_address).value / 1000000000
|
||||||
return SOLbalance
|
return SOLbalance
|
||||||
|
|
||||||
@cache.file_cache()
|
|
||||||
def getSolValue() -> int:
|
def getSolValue() -> int:
|
||||||
SOLbalance = solana_client.get_balance(
|
SOLbalance = getSolBalance()
|
||||||
vault_sol_address).value / 1000000000
|
|
||||||
SOLPrice = get_coin_price("solana")
|
SOLPrice = get_coin_price("solana")
|
||||||
return SOLbalance * SOLPrice
|
return SOLbalance * SOLPrice
|
||||||
|
|
||||||
@cache.file_cache()
|
|
||||||
def getVaultBalance() -> int:
|
def getVaultBalance() -> int:
|
||||||
# Get balance of vault
|
# Get balance of vault
|
||||||
vaultBalance = 0
|
vaultBalance = 0
|
||||||
@ -258,9 +257,12 @@ def getTokens():
|
|||||||
token["symbol"] = data["symbol"]
|
token["symbol"] = data["symbol"]
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
|
|
||||||
|
# Get SUI tokens
|
||||||
|
tokens.extend(getSuiTokens(vault_sui_address))
|
||||||
|
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
def getTokenData(tokenMint):
|
def getTokenData(tokenMint, chain='solana'):
|
||||||
if not os.path.exists("tokens"):
|
if not os.path.exists("tokens"):
|
||||||
os.makedirs("tokens")
|
os.makedirs("tokens")
|
||||||
|
|
||||||
@ -270,7 +272,7 @@ def getTokenData(tokenMint):
|
|||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
data = coingecko_client.get_coin_info_from_contract_address_by_id(
|
data = coingecko_client.get_coin_info_from_contract_address_by_id(
|
||||||
'solana', tokenMint)
|
chain, tokenMint)
|
||||||
with open(f"tokens/{tokenMint}.json", "w") as f:
|
with open(f"tokens/{tokenMint}.json", "w") as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
return data
|
return data
|
||||||
@ -318,6 +320,54 @@ def getCardanoValue(address: str):
|
|||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
# region Sui
|
||||||
|
|
||||||
|
@cache.file_cache()
|
||||||
|
def getSuiTokens(address: str):
|
||||||
|
url = "https://fullnode.mainnet.sui.io/"
|
||||||
|
|
||||||
|
# Define the payload for the RPC call
|
||||||
|
payload = {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"id": 1,
|
||||||
|
"method": "suix_getAllBalances",
|
||||||
|
"params": [
|
||||||
|
address
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define headers (if needed)
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make the POST request
|
||||||
|
tokens = []
|
||||||
|
try:
|
||||||
|
response = requests.post(url, json=payload, headers=headers)
|
||||||
|
response.raise_for_status() # Raise an HTTPError for bad responses
|
||||||
|
result = response.json()
|
||||||
|
|
||||||
|
for coin in result['result']:
|
||||||
|
token = {
|
||||||
|
"mint": coin['coinType'],
|
||||||
|
"balance": int(coin['totalBalance'])/10**9,
|
||||||
|
}
|
||||||
|
token["price"] = get_token_price(token["mint"], 'sui')
|
||||||
|
token["value"] = token["price"] * token["balance"]
|
||||||
|
if token["value"] < 0.01:
|
||||||
|
continue
|
||||||
|
data = getTokenData(str(token["mint"]), 'sui')
|
||||||
|
token["name"] = data["name"]
|
||||||
|
token["symbol"] = data["symbol"]
|
||||||
|
tokens.append(token)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
return tokens
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
# region API Routes
|
# region API Routes
|
||||||
|
|
||||||
@app.route("/api/v1/token")
|
@app.route("/api/v1/token")
|
||||||
|
BIN
stWDBRN.bsdesign
BIN
stWDBRN.bsdesign
Binary file not shown.
@ -134,7 +134,7 @@
|
|||||||
|
|
||||||
// Create table header
|
// Create table header
|
||||||
const headerRow = document.createElement('tr');
|
const headerRow = document.createElement('tr');
|
||||||
['Name', 'Amount', 'Value'].forEach((headerText, index) => {
|
['Name', 'Amount', 'USD Value'].forEach((headerText, index) => {
|
||||||
const th = document.createElement('th');
|
const th = document.createElement('th');
|
||||||
th.textContent = headerText;
|
th.textContent = headerText;
|
||||||
th.style.border = '1px solid #ccc';
|
th.style.border = '1px solid #ccc';
|
||||||
@ -142,7 +142,7 @@
|
|||||||
th.style.backgroundColor = '#333';
|
th.style.backgroundColor = '#333';
|
||||||
th.style.color = 'white';
|
th.style.color = 'white';
|
||||||
|
|
||||||
if (headerText === 'Value') {
|
if (headerText === 'USD Value') {
|
||||||
th.style.cursor = 'pointer'; // Make it clear this header is clickable
|
th.style.cursor = 'pointer'; // Make it clear this header is clickable
|
||||||
th.addEventListener('click', () => sortTableByValue(tbody));
|
th.addEventListener('click', () => sortTableByValue(tbody));
|
||||||
}
|
}
|
||||||
@ -318,6 +318,10 @@ function sortTableByValue(tbody) {
|
|||||||
<td>Cardano</td>
|
<td>Cardano</td>
|
||||||
<td>stake1uy4qd785pcds7ph2jue2lrhhxa698c5959375lqdv3yphcgwc8qna</td>
|
<td>stake1uy4qd785pcds7ph2jue2lrhhxa698c5959375lqdv3yphcgwc8qna</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Sui</td>
|
||||||
|
<td>0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
1
tokens/0x2::sui::SUI.json
Normal file
1
tokens/0x2::sui::SUI.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user