-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstockDataRouter.ts
85 lines (53 loc) · 2 KB
/
stockDataRouter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Request, Response } from "express";
const router = require('express').Router();
const xss = require('xss'); //used for cleaning user input
const StockData = require('../src/StockData');
/**
*
* Searches for stocks that match the input from the user
*
* @param {string} input
* @return {Array<JSON>} stocks
*/
router.route('/searchBySymbol').get(async (req: Request, res: Response) => {
let searchInput: string = xss(req.query.input);
let response = await StockData.findBySymbol(searchInput);
res.status(response.http_id).json(response.stocks);
})
/**
* Gets a stock's quote by taking in the symbol for said stock
* @param {string} stock
* @return {JSON} quote
*/
router.route('/getStockQuote').get(async (req: Request, res: Response) => {
let stock: string = xss(req.query.symbol);
let response = await StockData.getQuoteBySymbol(stock);
res.status(response.http_id).json(response.quotes);
})
/**
* Gets you all expiration dates
* @param {string} symbol
* @returns {array<string>} dates
*/
router.route('/getExpirations').get(async (req: Request, res: Response) => {
let stock: string = xss(req.query.symbol);
let response = await StockData.getOptionExpirationsBySymbol(stock);
res.status(response.http_id).json(response.expirations);
})
/**
* Gets option chains for a specific symbol with specific expiration for either call, put, or both
*
* @param {string} symbol
* @param {string} expiration //ex : '2021-01-08'
* @param {string} optionType //'call' for calls, 'put' for puts, 'all' for both
*
* @returns {array<JSON>} option chain
*/
router.route('/getOptionsOnDate').get(async (req: Request, res: Response) => {
let stock: string = xss(req.query.symbol);
let expiration: string = xss(req.query.expiration);
let optionType: string = xss(req.query.optionType);
let response = await StockData.getOptionsOnDate(stock, expiration, optionType);
res.status(response.http_id).json(response.options);
})
module.exports = router