221 lines
5.5 KiB
HTML
221 lines
5.5 KiB
HTML
{% extends 'base.html' %}
|
|
|
|
|
|
{% block content %}
|
|
<div class="row row-deck row-cards">
|
|
<div class="col-sm-6 col-lg-3">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div class="subheader">Account Balance</div>
|
|
<div class="ms-auto lh-1">
|
|
</div>
|
|
</div>
|
|
<div class="d-flex align-items-baseline">
|
|
<div class="h1 mb-0 me-2">${{balance}}</div>
|
|
<div class="me-auto">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-12">
|
|
<div class="card">
|
|
<div class="card-header border-0">
|
|
<div class="card-title">Treasury Yields</div>
|
|
</div>
|
|
<div class="card-body">
|
|
|
|
<div id="chart-yields" class="chart-lg"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-8">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">Transactions</h3>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table card-table table-vcenter text-nowrap datatable">
|
|
<thead>
|
|
<tr>
|
|
<th>Term</th>
|
|
<th>Quantity</th>
|
|
<th>Date</th>
|
|
<th>Side</th>
|
|
<th>Rate</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="txbody">
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-4">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">Buy/Sell</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="mb-3">
|
|
<div class="form-label">Term</div>
|
|
<select class="form-select" id="term">
|
|
<option value="1 Mo">1 Mo</option>
|
|
<option value="2 Mo">2 Mo</option>
|
|
<option value="3 Mo">3 Mo</option>
|
|
<option value="4 Mo">4 Mo</option>
|
|
<option value="6 Mo">6 Mo</option>
|
|
<option value="1 Yr">1 Yr</option>
|
|
<option value="2 Yr">2 Yr</option>
|
|
<option value="3 Yr">3 Yr</option>
|
|
<option value="5 Yr">5 Yr</option>
|
|
<option value="7 Yr">7 Yr</option>
|
|
<option value="10 Yr">10 Yr</option>
|
|
<option value="12 Yr">12 Yr</option>
|
|
<option value="30 Yr">30 Yr</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Quantity</label>
|
|
<input type="number" class="form-control" name="quantity" id="quantity" placeholder="100" />
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Side</label>
|
|
<select class="form-select">
|
|
<option value="BUY">Buy</option>
|
|
<option value="SELL">Sell</option>
|
|
</select>
|
|
</div>
|
|
|
|
<button id="buybtn" class="btn btn-primary ms-auto">Submit Order</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.0.0-beta17/dist/libs/apexcharts/dist/apexcharts.min.js" defer></script>
|
|
<script>
|
|
|
|
document.getElementById("buybtn").addEventListener('click', () => {
|
|
var r = new XMLHttpRequest();
|
|
r.open("POST", "/api/buy", true);
|
|
r.onload = function () {
|
|
window.location.reload();
|
|
}
|
|
|
|
r.setRequestHeader("Content-Type", "application/json")
|
|
// Send data in below way from JS
|
|
r.send(JSON.stringify({
|
|
"quantity": document.getElementById('quantity').value,
|
|
"instrument": document.getElementById("term").value,
|
|
"user_id": "{{userid}}"
|
|
}));
|
|
});
|
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
|
|
window.ApexCharts && (new ApexCharts(document.getElementById('chart-yields'), {
|
|
chart: {
|
|
type: "line",
|
|
fontFamily: 'inherit',
|
|
parentHeightOffset: 0,
|
|
height: 512,
|
|
toolbar: {
|
|
show: true,
|
|
},
|
|
animations: {
|
|
enabled: false
|
|
},
|
|
},
|
|
fill: {
|
|
opacity: 1,
|
|
},
|
|
stroke: {
|
|
width: 2,
|
|
lineCap: "round",
|
|
curve: "straight",
|
|
},
|
|
series: [
|
|
{% for rate in rates %}
|
|
{% for name, data in rate.items() %}
|
|
{
|
|
name: "{{name}}",
|
|
data: {{data}}
|
|
},
|
|
{% endfor %}
|
|
{% endfor %}
|
|
],
|
|
tooltip: {
|
|
theme: 'dark'
|
|
},
|
|
grid: {
|
|
padding: {
|
|
top: -20,
|
|
right: 0,
|
|
left: -4,
|
|
bottom: -4
|
|
},
|
|
strokeDashArray: 4,
|
|
},
|
|
xaxis: {
|
|
labels: {
|
|
padding: 0,
|
|
},
|
|
tooltip: {
|
|
enabled: false
|
|
},
|
|
type: 'datetime',
|
|
},
|
|
yaxis: {
|
|
labels: {
|
|
padding: 4
|
|
},
|
|
},
|
|
labels: [
|
|
{% for each in dates %}
|
|
"{{each}}",
|
|
{% endfor %}
|
|
],
|
|
|
|
legend: {
|
|
show: true,
|
|
position: 'bottom',
|
|
offsetY: 12,
|
|
markers: {
|
|
width: 10,
|
|
height: 10,
|
|
radius: 100,
|
|
},
|
|
itemMargin: {
|
|
horizontal: 8,
|
|
vertical: 8
|
|
},
|
|
},
|
|
})).render();
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.withCredentials = true;
|
|
xhr.open('GET', 'http://localhost:8008/api/transactions/{{userid}}');
|
|
|
|
xhr.onload = function() {
|
|
console.log(xhr.response);
|
|
var jsonResponse = JSON.parse(xhr.response);
|
|
for (let i = 0; i < jsonResponse.length; i++) {
|
|
var newRow="<tr><td>"+ jsonResponse[i].term + "</td><td>" + jsonResponse[i].quantity + "</td><td>" + jsonResponse[i].date + "</td><td>" + jsonResponse[i].side + "</td><td>"+ jsonResponse[i].rate +"</td></tr>";
|
|
document.getElementById('txbody').innerHTML += newRow;
|
|
}
|
|
|
|
};
|
|
|
|
xhr.send();
|
|
|
|
});
|
|
</script>
|
|
|
|
|
|
{% endblock %}
|