First functioning version with server calls.
This commit is contained in:
@@ -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