First functioning version with server calls.

This commit is contained in:
Joe Tretter
2020-03-09 10:49:19 -05:00
parent 9fbcf07cb5
commit 34ff5ec68f
5 changed files with 194 additions and 31 deletions

View File

@@ -29,18 +29,26 @@ let beforeShowDay=(theDate)=>{
let isoDate=theDate.toISOString().substr(0,10);
console.log("BeforeShow",isoDate,theDate);
if (!filterContext.availableDates.dates[isoDate]) {
let isDateFound=false;
for (let i=0;i<filterContext.availableDates.length;i++){
if (filterContext.availableDates[i].Date===theDate.toISOString().substr(0,10)){
isDateFound=true;
break;
};
}
if (!isDateFound) {
return {enabled:false, tooltip:"No data"};
}
}
let fetchSymbols=()=>{
$.ajax({
url:"https://netsquat.ddns.kawomi.com/wc/raw/tosym"
$.get({
url:"http://localhost:3000/getSymbols"
}).done(response=>{
let allSymbols=JSON.parse(response);
let allSymbols=response;
console.log(allSymbols);
refreshSymbolList(allSymbols.symbols);
refreshSymbolList(allSymbols);
});
}
@@ -54,8 +62,8 @@ let symbolChanged=_=>{
$("#datePicker").datepicker({beforeShowDay:beforeShowDay})
.on('changeDate', (e)=>{
console.log("DatePicker changed date",e.date);
filterContext.selectedDate=e.date.toISOString().substr(0,10);
showTimesForDay(filterContext.selectedDate);
filterContext.theDate=e.date.toISOString().substr(0,10);
showTimesForDay(filterContext.theDate);
});
});
}
@@ -68,29 +76,37 @@ let timeChanged=()=>{
let requestOptionChain=()=>{
$.ajax({
url:"https://netsquat.ddns.kawomi.com/wc/raw/spy"
url:"http://localhost:3000/getOptionChain?Date=" + filterContext.theDate + "&Symbol=" + filterContext.theSymbol + "&Time="+filterContext.selectedTime
}).done(response=>{
dta=JSON.parse(response);
dta=JSON.parse(response[0].Data);
console.log("received",dta);
displayOptionChain();
});
}
let showTimesForDay=(theDate)=>{
let lbTime=$("#lbTime");
lbTime.empty();
allTimes = filterContext.availableDates.dates[theDate];
for (let i=0;i<allTimes.length;i++){
theTime=allTimes[i];
lbTime.append($(`<option>${theTime}</option>`))
}
let showTimesForDay=()=>{
return $.ajax({
url:"http://localhost:3000/getTimes?Date=" + filterContext.theDate + "&Symbol=" + filterContext.theSymbol
}).done(response=>{
let availableTimes=response;
console.log(availableTimes);
let lbTime=$("#lbTime");
lbTime.empty();
allTimes = availableTimes;
for (let i=0;i<allTimes.length;i++){
theTime=allTimes[i].Time;
lbTime.append($(`<option>${theTime}</option>`))
}
});
}
let getAvailDatesForSymbol=(theSymbol)=>{
return $.ajax({
url:"https://netsquat.ddns.kawomi.com/wc/raw/availDates"
url:"http://localhost:3000/getDates"
}).done(response=>{
let availableDates=JSON.parse(response);
let availableDates=response;
console.log(availableDates);
filterContext.availableDates=availableDates;
});
@@ -100,7 +116,7 @@ let refreshSymbolList=(allSymbols)=>{
let lbSymbol=$("#lbSymbol");
lbSymbol.empty();
for (let i=0;i<allSymbols.length;i++){
theSymbol=allSymbols[i];
theSymbol=allSymbols[i].Symbol;
console.log(theSymbol);
lbSymbol.append($(`<option>${theSymbol}</option>`))
}

View File

@@ -1,7 +1,11 @@
var costAmount=0;
var allCombinations;
$(document).ready(_=>{
dta=fakeDta;
allCombinations=$.get("http://localhost:3000/getCombinations",
data=>{allCombinations=data;},
"json");
// displayOptionChain();
createOrderFrame();
createMasterFilterFrame();
@@ -18,12 +22,20 @@ let createOrderFrame=()=>{
window.document.getElementById('app').append(theFrameDiv);
theFrameDiv.innerHTML=`
<button onclick="clearOrder()" type="button" class="btn btn-danger">Clear All</button>
<br>
<span id='lbCost' class="bold">Gain $</span><span id='lbCostAmount'>0</span>
<ul id='listOrderItems'>
</ul>
`;
}
let clearOrder=()=>{
costAmount=0;
$("#listOrderItems").empty();
showCostAmount();
}
let addToOrder=(openType,optionData)=>{
optionData=JSON.parse(optionData.replace(/'/g,'"'));
console.log("AddToOrder",openType,optionData);
@@ -31,11 +43,14 @@ let addToOrder=(openType,optionData)=>{
let price=(openType.substr(0,1)==="b")?optionData.ask:optionData.bid;
costAmount+=(price*100) * ((openType.substr(0,1)==="b")?-1:1);
$("#lbCostAmount").text(costAmount.toLocaleString('en',{minimumFractionDigits: 2, maximumFractionDigits: 2}));
showCostAmount();
$("#listOrderItems").append(`<li>${openType} | ${optionData.symbol} | ${price*100}</li>`);
}
let showCostAmount=_=>{
$("#lbCostAmount").text(costAmount.toLocaleString('en',{minimumFractionDigits: 2, maximumFractionDigits: 2}));
}
let dta={};
let datesOut=(dateInp)=>{
@@ -56,10 +71,13 @@ let getCallArtifact=(callData,allColumns)=>{
`;
}
let strCallJSON=JSON.stringify(callData).replace(/"/g,"\\'");
bidFrm=Number(callData.bid).toLocaleString('en',{minimumFractionDigits: 2, maximumFractionDigits: 2});
askFrm=Number(callData.ask).toLocaleString('en',{minimumFractionDigits: 2, maximumFractionDigits: 2});
artifact+=`
<td class="${classes} ralign" onclick="addToOrder('sell','${strCallJSON}')"><a href="#" title="Sell">${callData.bid}</a></td>
<td class="${classes} ralign" onclick="addToOrder('buy','${strCallJSON}')"><a href="#" title="Buy">${callData.ask}</a></td>
<td class="${classes} ralign" onclick="addToOrder('sell','${strCallJSON}')"><a href="#" title="Sell">${bidFrm}</a></td>
<td class="${classes} ralign" onclick="addToOrder('buy','${strCallJSON}')"><a href="#" title="Buy">${askFrm}</a></td>
`;
return artifact;
}
@@ -78,9 +96,12 @@ let getPutArtifact=(putData,allColumns)=>{
let strPutJSON=JSON.stringify(putData).replace(/"/g,"\\'");
bidFrm=Number(putData.bid).toLocaleString('en',{minimumFractionDigits: 2, maximumFractionDigits: 2});
askFrm=Number(putData.ask).toLocaleString('en',{minimumFractionDigits: 2, maximumFractionDigits: 2});
artifact+=`
<td class="${classes} ralign" onclick="addToOrder('sell','${strPutJSON}')"><a href="#" title="Sell">${putData.bid}</a></td>
<td class="${classes} ralign" onclick="addToOrder('buy','${strPutJSON}')"><a href="#" title="Buy">${putData.ask}</a></td>
<td class="${classes} ralign" onclick="addToOrder('sell','${strPutJSON}')"><a href="#" title="Sell">${bidFrm}</a></td>
<td class="${classes} ralign" onclick="addToOrder('buy','${strPutJSON}')"><a href="#" title="Buy">${askFrm}</a></td>
`;
return artifact;
}