feat: Show defi on webpage
All checks were successful
Build Docker / BuildImage (push) Successful in 32s

This commit is contained in:
Nathan Woodburn 2024-12-09 16:03:44 +11:00
parent c3d6e681ce
commit 87b7b1ba20
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
8 changed files with 91 additions and 6 deletions

View File

@ -1 +1 @@
{"timestamp": 1733719398.4783282, "result": 326.899783283} {"timestamp": 1733720614.112476, "result": 326.899783283}

View File

@ -1 +1 @@
{"timestamp": 1733719142.5989292, "result": [{"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 245.52, "value": 9.775499595840001, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3917.66, "value": 10.018827800999999, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00035766, "price": 98929, "value": 35.38294614, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 19.88979, "price": 4.19, "value": 83.33822010000002, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.18, "value": 3.77391344726, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 9.658874002, "price": 4.32, "value": 41.72633568864, "name": "Volo Staked SUI", "symbol": "vsui"}]} {"timestamp": 1733720524.535053, "result": [{"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 19.88979, "price": 4.19, "value": 83.33822010000002, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00035766, "price": 98929, "value": 35.38294614, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 245.52, "value": 9.775499595840001, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3917.66, "value": 10.018827800999999, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.18, "value": 3.77391344726, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 9.658874002, "price": 4.32, "value": 41.72633568864, "name": "Volo Staked SUI", "symbol": "vsui"}]}

View File

@ -1 +1 @@
{"timestamp": 1733719142.5983186, "result": [{"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.18, "value": 3.77391344726, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 9.658874002, "price": 4.32, "value": 41.72633568864, "name": "Volo Staked SUI", "symbol": "vsui"}]} {"timestamp": 1733720524.479128, "result": [{"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 4.18, "value": 3.77391344726, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 9.658874002, "price": 4.32, "value": 41.72633568864, "name": "Volo Staked SUI", "symbol": "vsui"}]}

View File

@ -1 +1 @@
{"timestamp": 1733719016.3804839, "result": 82.815227} {"timestamp": 1733720521.0848057, "result": 82.815227}

View File

@ -1 +1 @@
{"timestamp": 1733719016.581333, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 26.85, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 20, "updated": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 46, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 23, "updated": "1733717057", "type": "Lending"}]} {"timestamp": 1733720598.8847191, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 26.85, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 20, "updated": "1733719659", "initial": 20, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 46, "url": "https://dydx.trade/vault", "value": 23.25, "updated": "1733719659", "initial": 23, "bought": "1733300000", "type": "Lending"}]}

View File

@ -547,6 +547,7 @@ def api_vault():
return jsonify(vault) return jsonify(vault)
@app.route("/api/v1/other") @app.route("/api/v1/other")
@app.route("/api/v1/defi")
def api_other_investments(): def api_other_investments():
data = getOtherInvestments() data = getOtherInvestments()
return jsonify(data) return jsonify(data)

Binary file not shown.

View File

@ -66,7 +66,7 @@
textStyle: { color: 'white' } textStyle: { color: 'white' }
}, },
backgroundColor: '#212529', backgroundColor: '#212529',
sliceVisibilityThreshold: 0.02 sliceVisibilityThreshold: 0.05
}; };
async function fetchData(apiUrl) { async function fetchData(apiUrl) {
@ -403,10 +403,94 @@
<td>Sui</td> <td>Sui</td>
<td><a href="https://suivision.xyz/account/0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da" target="_blank">0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da</a></td> <td><a href="https://suivision.xyz/account/0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da" target="_blank">0x7e4fa1592e4fad084789f9fe1a4d7631a2e6477b658e777ae95351681bcbe8da</a></td>
</tr> </tr>
<tr>
<td>dYdX</td>
<td><a href="https://www.mintscan.io/dydx/address/dydx1ugraczuyfmxy8k38nps4fu7e5derryzx95fs8n" target="_blank">dydx1ugraczuyfmxy8k38nps4fu7e5derryzx95fs8n</a></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
<div class="p-5">
<h2 class="display-4">DeFi Positions</h2>
<div class="table-responsive" id="defi-table">
<table class="table">
<thead>
<tr>
<th>Type</th>
<th>Initial Value</th>
<th>Date bought</th>
<th>Current Value</th>
<th>Info</th>
<th>Last Updated</th>
</tr>
</thead>
<tbody>
<tr>
<td>Position Name</td>
<td>$0</td>
<td>00/00/00</td>
<td>$0</td>
<td>Find out more</td>
<td>00/00/00</td>
</tr>
</tbody>
</table>
</div><script type="text/javascript">
async function fetchAndInjectDefiData() {
try {
// Fetch data from the API
const response = await fetch('/api/v1/defi');
if (!response.ok) {
throw new Error('Network response was not ok' + response.statusText);
}
const data = await response.json();
// Locate the table where the data will be injected
const tableBody = document.querySelector('#defi-table tbody');
if (!tableBody) {
console.error('Table body not found. Make sure your table has an id "defi-table" with a <tbody> element.');
return;
}
// Clear existing rows (optional, depending on use case)
tableBody.innerHTML = '';
const formatDate = (timestamp) => {
const date = new Date(timestamp * 1000); // Convert seconds to milliseconds
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
const year = String(date.getFullYear()).slice(-2); // Get last two digits of the year
return `${day}/${month}/${year}`;
};
// Iterate over the data and create table rows
data.forEach(item => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${item.name}</td>
<td>$${item.initial}</td>
<td>${formatDate(item.bought)}</td>
<td>$${item.value}</td>
<td><a href="${item.url}" target="_blank">Find out more</a></td>
<td>${formatDate(item.updated)}</td>
`;
tableBody.appendChild(row);
});
} catch (error) {
console.error('Error fetching or injecting data:', error);
}
}
// Set on page load event listener
window.addEventListener('load', fetchAndInjectDefiData);
</script>
</div>
</div> </div>
</section> </section>
<footer class="py-5 bg-black"> <footer class="py-5 bg-black">