fme-fv-fetch
Version:
This fetches the fair-value numbers from index-arb.com
52 lines (45 loc) • 1.61 kB
text/typescript
import {Log} from "fme-logger";
import * as cheerio from "cheerio";
import * as request from "request";
var L = new Log("fv-fetch");
export class FairValues {
timeStamp = new Date();
SPX = "";
NQ = "";
DOW = "";
constructor() {
this.SPX = this.NQ = this.DOW = "N/A";
this.timeStamp = new Date();
}
}
export class FairValue {
fairValues:any;
fetch() {
L.debug ("fetching Fair Values");
this.fairValues = new FairValues();
request({
uri: 'http://indexarb.com',
},(err,res,body) => {
var $ = cheerio.load(body);
var idx = 0;
var td = $("td");
// L.info(td.length);
// for (var i=0; i<td.length; i++) {
// L.info(i,td[i].children[0].data);
// }
var spx = td[66].children[0].data;
if (typeof spx == "string") {
this.fairValues.SPX = spx.replace(/[^0-9.+-]/g,"");
}
var nq = td[72].children[0].data;
if (typeof nq == "string") {
this.fairValues.NQ = nq.replace(/[^0-9.+-]/g,"");
}
var dow = td[78].children[0].data;
if (typeof dow == "string") {
this.fairValues.DOW = dow.replace(/[^0-9.+-]/g,"");
}
L.info ("SPX FV:",this.fairValues.SPX," NQ FV:",this.fairValues.NQ,"DOW FV:",this.fairValues.DOW);
});
}
}