In the following code:
let getIVoneDay = async (symbol, option, date, exp_date, strike) => {
let close_ce = await getCE(symbol, option, date, exp_date, strike);
const close_pe=await getPE(symbol, option, date, exp_date, strike);
const close_xx= await getXX(symbol, option, date, exp_date, strike);
console.log(close_ce,close_pe,close_xx);
};
I get the value
undefined undefined undefined
The three functions take some params, make a query in DB and return a value which takes a little time. So, i have tried to use it with async/await and yet i get the same results. How can i do this? I have tried callbacks too for the same and get the same results.
for calling:
var x = getIVoneDay("ACC", "CE", "2020-01-01", "2020-01-30", 1220);
The get functions:
let getPE = (symbol, option, date, exp_date, strike) => {
var collection_pe = symbol + ".PE";
var model_pe = mongoose.model("model_pe", bhavcopySchema, collection_pe);
model_pe
.find({
SYMBOL: symbol,
STRIKE_PR: strike,
OPTION_TYP: "PE",
EXPIRY_DT: new Date(exp_date),
TIMESTAMP: new Date(date),
})
.exec((err, result) => {
let close_pe = result[0].CLOSE.value;
console.log(close_pe);
return close_pe;
});
};
PS: the print inside getCE() and other functions prints the correct value.