Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save molekilla/1e949cccc36685fabc510905a6c66c7d to your computer and use it in GitHub Desktop.
Save molekilla/1e949cccc36685fabc510905a6c66c7d to your computer and use it in GitHub Desktop.
svelte server render example
<!-- Main -->
<script lang="ts">
import Table from "./AccountingTable.svelte";
export let accountingGroupByPairs = {};
</script>
<svelte:head>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous" />
</svelte:head>
<body>
<div class="container-fluid">
<div class="row">
<Table items={accountingGroupByPairs} />
</div>
</div>
<!-- ${reload} -->
</body>
<!-- Table -->
<script lang="ts">
import Row from "./AccountingRow.svelte";
export let items = {};
</script>
<table class="table table-dark table-sm">
<thead>
<tr>
<th scope="col">Pair</th>
<th scope="col">Sell</th>
<th scope="col">Buy</th>
<th scope="col">Profit</th>
</tr>
</thead>
<tbody>
{#each Object.values(items) as item}
<Row group={item} />
{/each}
</tbody>
</table>
<!-- Row -->
<script lang="ts">
export let group = [{ pair: ''}];
$: sell = group
.filter(i => i.credit)
.map(i => i.amount)
.reduce((p, c) => p + c, 0);
$: buy = group
.filter(i => !i.credit)
.map(i => i.amount)
.reduce((p, c) => p + c, 0);
$: profit = (100 * ((sell - buy) / sell)).toFixed(2);
let pair = group[0].pair;
</script>
<tr>
<td>
<a href="https://www.tradingview.com/symbols/{pair}" class="card-link">
{pair}
</a>
</td>
<td>$ {sell}</td>
<td>$ {buy}</td>
<td>{profit} %</td>
</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment