Server now returns HTML and can pass back/forth data
This commit is contained in:
59
templates/assets/main.js
Normal file
59
templates/assets/main.js
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
|
||||
var optionResults;
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
$("#option-terms").on("submit", function(e) {
|
||||
//
|
||||
e.preventDefault();
|
||||
sendRequest();
|
||||
})
|
||||
});
|
||||
|
||||
function serializeForm(id) {
|
||||
//
|
||||
return $(id).serializeArray()
|
||||
.reduce(function(a, x) { a[x.name] = x.value; return a; }, {});
|
||||
}
|
||||
|
||||
function sendRequest() {
|
||||
//
|
||||
var inputData = serializeForm("#option-terms");
|
||||
// Get the right data-types
|
||||
inputData.ExpiryDate = new Date(inputData.ExpiryDate).toJSON();
|
||||
inputData.OptType = parseInt(inputData.OptType);
|
||||
inputData.Rfr = parseFloat(inputData.Rfr);
|
||||
inputData.Sims = parseInt(inputData.Sims);
|
||||
inputData.Spot = parseFloat(inputData.Spot);
|
||||
inputData.Strike = parseFloat(inputData.Strike);
|
||||
inputData.ValueDate = new Date(inputData.ValueDate).toJSON();
|
||||
inputData.Vol = parseFloat(inputData.impliedVol);
|
||||
|
||||
// Send request
|
||||
var startTime;
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "http://localhost:8080",
|
||||
data: JSON.stringify(inputData),
|
||||
beforeSend: function(request, settings) {
|
||||
startTime = new Date().getTime();
|
||||
},
|
||||
success: function(e) {
|
||||
optionResults = e;
|
||||
updateTable();
|
||||
let requestTime = new Date().getTime() - startTime;
|
||||
console.log("Request time: ", requestTime);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function updateTable() {
|
||||
$("#results-table > tbody > tr").each(function(idx, el) {
|
||||
$($(el).children()[1])[0].innerText =
|
||||
optionResults["ClosedForm"][$($(el).children()[0]).text()].toFixed(4);
|
||||
$($(el).children()[2])[0].innerText =
|
||||
optionResults["MonteCarlo"][$($(el).children()[0]).text()].toFixed(4);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user