First functioning version with server calls.
This commit is contained in:
@@ -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>`))
|
||||
}
|
||||
|
||||
@@ -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)=>{
|
||||
@@ -57,9 +72,12 @@ 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;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
const micro = require('micro');
|
||||
const queryString = require('querystring');
|
||||
const Database = require('better-sqlite3');
|
||||
|
||||
module.exports = (req, res) => {
|
||||
console.log(req.method, req.url);
|
||||
res.setHeader("Access-Control-Allow-Origin","*");
|
||||
//console.log(res);
|
||||
if (req.method === "GET") {
|
||||
console.log("Get Request coming in");
|
||||
if (req.url === "/dates") {
|
||||
console.log("Request for Dates");
|
||||
let qsAttr;
|
||||
let func=req.url;
|
||||
if (req.url.indexOf("?") >=0){
|
||||
func=req.url.substring(0,req.url.indexOf("?"))
|
||||
qsAttr=queryString.parse(req.url.substring(req.url.indexOf("?")+1));
|
||||
}
|
||||
console.log(func,qsAttr);
|
||||
if (func === "/getCombinations") {
|
||||
console.log("Request for combinations");
|
||||
const db = new Database('./quoteDBs/consolidated.sqlite3', { verbose: console.log });
|
||||
const stmt = db.prepare("SELECT distinct Symbol,date(TimeStamp,'localtime') Date ,time(TimeStamp,'localtime') Time FROM OptionQuotes");
|
||||
let allDates = stmt.all();
|
||||
@@ -14,8 +24,62 @@ module.exports = (req, res) => {
|
||||
db.close();
|
||||
micro.send(res,200,allDates);
|
||||
}
|
||||
} else {
|
||||
res.end('Welcome to Micro');
|
||||
if (func === "/getSymbols") {
|
||||
console.log("Request for Symbols");
|
||||
const db = new Database('./quoteDBs/consolidated.sqlite3', { verbose: console.log });
|
||||
const stmt = db.prepare("SELECT distinct Symbol FROM OptionQuotes order by 1");
|
||||
let allDates = stmt.all();
|
||||
//console.log(JSON.stringify(allDates));
|
||||
db.close();
|
||||
micro.send(res,200,allDates);
|
||||
}
|
||||
if (func === "/getDates") {
|
||||
console.log("Request for Dates");
|
||||
const db = new Database('./quoteDBs/consolidated.sqlite3', { verbose: console.log });
|
||||
const stmt = db.prepare("SELECT distinct date(TimeStamp,'localtime') Date FROM OptionQuotes order by 1");
|
||||
let allDates = stmt.all();
|
||||
//console.log(JSON.stringify(allDates));
|
||||
db.close();
|
||||
micro.send(res,200,allDates);
|
||||
}
|
||||
if (func === "/getTimes") {
|
||||
console.log("Request for Times");
|
||||
const db = new Database('./quoteDBs/consolidated.sqlite3', { verbose: console.log });
|
||||
let sql = "SELECT distinct time(TimeStamp,'localtime') Time FROM OptionQuotes where 1=1"
|
||||
if (qsAttr.Symbol) {
|
||||
sql +=" and Symbol='" + qsAttr.Symbol+ "'";
|
||||
}
|
||||
if (qsAttr.Date){
|
||||
sql +=" and date(TimeStamp,'localtime')='" + qsAttr.Date+ "'";
|
||||
}
|
||||
sql+=" order by 1";
|
||||
const stmt = db.prepare(sql);
|
||||
let allDates = stmt.all();
|
||||
//console.log(JSON.stringify(allDates));
|
||||
db.close();
|
||||
micro.send(res,200,allDates);
|
||||
}
|
||||
if (func === "/getOptionChain") {
|
||||
console.log("Request for OptionChain");
|
||||
const db = new Database('./quoteDBs/consolidated.sqlite3', { verbose: console.log });
|
||||
let sql = "SELECT Data FROM OptionQuotes where 1=1"
|
||||
if (qsAttr.Symbol) {
|
||||
sql +=" and Symbol='" + qsAttr.Symbol+ "'"
|
||||
}
|
||||
if (qsAttr.Date){
|
||||
sql +=" and date(TimeStamp,'localtime')='" + qsAttr.Date+ "'";
|
||||
}
|
||||
if (qsAttr.Time){
|
||||
sql +=" and time(TimeStamp,'localtime')='" + qsAttr.Time+ "'";
|
||||
}
|
||||
|
||||
const stmt = db.prepare(sql);
|
||||
let allDates = stmt.all();
|
||||
//console.log(JSON.stringify(allDates));
|
||||
db.close();
|
||||
micro.send(res,200,allDates);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
59
server/package-lock.json
generated
59
server/package-lock.json
generated
@@ -38,6 +38,11 @@
|
||||
"pirates": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"babel-regenerator-runtime": {
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-regenerator-runtime/-/babel-regenerator-runtime-6.5.0.tgz",
|
||||
"integrity": "sha1-DkHNHJ+ARCRm8BXHSf/4upj44RA="
|
||||
},
|
||||
"babylon": {
|
||||
"version": "6.18.0",
|
||||
"resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz",
|
||||
@@ -256,6 +261,11 @@
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
||||
},
|
||||
"isstream": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
|
||||
},
|
||||
"magic-string": {
|
||||
"version": "0.22.5",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz",
|
||||
@@ -264,6 +274,11 @@
|
||||
"vlq": "^0.2.2"
|
||||
}
|
||||
},
|
||||
"media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
|
||||
},
|
||||
"micro": {
|
||||
"version": "9.3.4",
|
||||
"resolved": "https://registry.npmjs.org/micro/-/micro-9.3.4.tgz",
|
||||
@@ -275,6 +290,45 @@
|
||||
"raw-body": "2.3.2"
|
||||
}
|
||||
},
|
||||
"micro-core": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/micro-core/-/micro-core-0.4.0.tgz",
|
||||
"integrity": "sha1-8NnHCAGthl/jpu/wHPGHdU56WTM=",
|
||||
"requires": {
|
||||
"babel-regenerator-runtime": "6.5.0",
|
||||
"isstream": "0.1.2",
|
||||
"media-typer": "0.3.0",
|
||||
"minimist": "1.2.0",
|
||||
"raw-body": "2.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"bytes": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-2.3.0.tgz",
|
||||
"integrity": "sha1-1baAoWW2IBc5rLYRVCqrwtjOsHA="
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.13",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.13.tgz",
|
||||
"integrity": "sha1-H4irpKsLFQjoMSrMOTRfNumS4vI="
|
||||
},
|
||||
"raw-body": {
|
||||
"version": "2.1.6",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.1.6.tgz",
|
||||
"integrity": "sha1-nAUHN/4HztbZSk/QnGG2rYdNMQ8=",
|
||||
"requires": {
|
||||
"bytes": "2.3.0",
|
||||
"iconv-lite": "0.4.13",
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"micro-cors": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/micro-cors/-/micro-cors-0.1.1.tgz",
|
||||
"integrity": "sha512-6WqIahA5sbQR1Gjexp1VuWGFDKbZZleJb/gy1khNGk18a6iN1FdTcr3Q8twaxkV5H94RjxIBjirYbWCehpMBFw=="
|
||||
},
|
||||
"mimic-response": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz",
|
||||
@@ -413,6 +467,11 @@
|
||||
"once": "^1.3.1"
|
||||
}
|
||||
},
|
||||
"querystring": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz",
|
||||
"integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA="
|
||||
},
|
||||
"raw-body": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz",
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
"dependencies": {
|
||||
"async-to-gen": "^1.4.0",
|
||||
"better-sqlite3": "^6.0.1",
|
||||
"micro": "^9.3.4"
|
||||
"micro": "^9.3.4",
|
||||
"micro-core": "^0.4.0",
|
||||
"micro-cors": "^0.1.1",
|
||||
"querystring": "^0.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user