Skip to content

Commit 539fd43

Browse files
committed
Bug fixes
1 parent 6a0418b commit 539fd43

File tree

10 files changed

+141
-982
lines changed

10 files changed

+141
-982
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.ignoreWords": [
3+
"monthindex"
4+
]
5+
}

algo/validation/convertsymbol.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class ConvertToSymbol extends StringUDF {
55
super()
66
}
77

8-
insertYear = (scrip, scriptype) => {
8+
insertYear = (scrip, scripType) => {
99
var _year = 21;
1010

11-
let year_index = scriptype == 'FUT' ? -2 : -3;
12-
let oldyear = scrip.slice(year_index, year_index + 1)[0]
13-
let is_year = this.isNumeric(oldyear);
11+
let year_index = scripType == 'FUT' ? -2 : -3;
12+
let oldYear = scrip.slice(year_index, year_index + 1)[0]
13+
let is_year = this.isNumeric(oldYear);
1414

1515
if (is_year) return scrip;
1616

@@ -51,24 +51,24 @@ class ConvertToSymbol extends StringUDF {
5151
let scrip = stringSymbol.toUpperCase().split(' ');
5252

5353
//find fut/ce/pe
54-
let scriptype = scrip[scrip.length - 1];
55-
let isFO = scriptype == 'CE' || scriptype == 'PE' || scriptype == 'FUT';
54+
let scripType = scrip[scrip.length - 1];
55+
let isFO = scripType == 'CE' || scripType == 'PE' || scripType == 'FUT';
5656
if (!isFO) return stringSymbol;
5757
var ex;
5858
//insert year in ce/pe
59-
scrip = this.insertYear(scrip, scriptype);
59+
scrip = this.insertYear(scrip, scripType);
6060

6161
//convert month as per weekly/monthly option
62-
if (scriptype == 'CE' || scriptype == 'PE') {
62+
if (scripType == 'CE' || scripType == 'PE') {
6363

64-
//isweekly
64+
//is weekly
6565
if (this.isNumeric(scrip[1])) {
6666
//YEAR MONTHINDEX DATE STRIKE CE/PE
6767
//2021 1 07 14000 CE
6868
var monthIndex = months.findIndex(element => element === scrip[2]);
69-
ex = `${scrip[3]}${monthIndex}` + `0${scrip[1]}`.slice(-2) + `${scrip[4]}${scrip[5]}`;
69+
ex = `${scrip[3]}${monthIndex}` + `0${scrip[1]}`.slice(-2) + `${Number(scrip[4])}${scrip[5]}`;
7070
} else {
71-
ex = `${scrip[2]}${scrip[1]}${scrip[3]}${scrip[4]}`;
71+
ex = `${scrip[2]}${scrip[1]}${Number(scrip[3])}${scrip[4]}`;
7272
}
7373
} else {
7474
ex = `${scrip[2]}${scrip[1]}FUT`;

api_calls/api_calls.js renamed to api_calls/axios_calls.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const axios = require('axios');
22
const qs = require('qs');
33
const stringUDFs = require('../string_udf/stringUDF');
44

5-
class Calls extends stringUDFs {
5+
class AxiosCalls extends stringUDFs {
66
constructor(baseURL, headers) {
77
super()
88
this.baseURL = baseURL;
@@ -52,4 +52,4 @@ class Calls extends stringUDFs {
5252
}
5353
}
5454

55-
module.exports = Calls
55+
module.exports = AxiosCalls

example/bhav.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const node_udf = require('../index.js');
2+
// const { getLastNRecords, pushBhavData } = require('../firebase/api');
3+
4+
const options = {
5+
type: "json", // optional. if not specified, zip file will be downloaded. Valid TYPES: ['json', 'csv', 'zip']
6+
dir: "" // optional. if not specified, files will be downloaded under NSE folder
7+
};
8+
9+
const nodeUDF = new node_udf(options);
10+
11+
const isTodayData = (data, bhavDate) => {
12+
let { TIMESTAMP } = data[0];
13+
return bhavDate.getDate() === new Date(TIMESTAMP).getDate();
14+
}
15+
16+
const bhavCopyDownload = async (myDate, dbPath = '/cash') => {
17+
let date = myDate == 0 || !myDate ? new Date() : myDate;
18+
let year = date.getFullYear();
19+
let month = date.toLocaleString('en-us', { month: 'short' }).toUpperCase();
20+
let day = date.getDate();
21+
22+
let options = {
23+
year: year,
24+
month: month,
25+
day: day
26+
}
27+
28+
console.log(options);
29+
try {
30+
//check if data in db
31+
// let data = await getLastNRecords(1, dbPath);
32+
33+
34+
// if (await isTodayData(data[0], date)) {
35+
// return 'BhavCopy already updated for the day.'
36+
// }
37+
// console.log('here')
38+
39+
let isfo = dbPath === '/fo';
40+
let bhavData = await nodeUDF.bhavdownload(options, isfo);
41+
console.log('here1')
42+
// pushBhavData(bhavData[0]);
43+
return "BhavCopy downloaded for the day " + day + " " + month;
44+
} catch (e) {
45+
console.log(e)
46+
return e;
47+
}
48+
}
49+
50+
51+
bhavCopyDownload()

example/test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const _udf = require('../node-udf.js');
1+
const _udf = require('../index');
22

33
let udf = new _udf();
44

@@ -24,7 +24,7 @@ const insertInToArray = () => {
2424
}
2525

2626
const convertToTradingSymbol = () => {
27-
let output = udf.convertToTradingSymbol('CRUDEOIL OCT FUT');
27+
let output = udf.convertToTradingSymbol('USDINR AUG 74.50 PE');
2828
console.log(output);
2929
}
3030

@@ -73,4 +73,6 @@ Keep your token secure and store it safely, it can be used by anyone to control
7373
For a description of the Bot API, see this page: https://core.telegram.org/bots/api`;
7474
parseBOTToken = () => udf.parseBOTToken(msg)
7575

76-
// parseBOTToken();
76+
// parseBOTToken();
77+
78+
convertToTradingSymbol()

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const Pushlog = require('./telegram/logs');
99
const QuickTelegramFn = require('./telegram/quickfn');
1010
const BhavCopy = require('./public_api/bhavcopy');
1111
const Cache = require("./misc/cache");
12-
const ApiCalls = require('./api_calls/api_calls');
12+
const AxiosCalls = require('./api_calls/axios_calls');
1313

14-
class UDF extends Many(StringUDF, Table, InputValidation, ConvertToSymbol, SqlUDF, BroadCastMessage, Pushlog, QuickTelegramFn, BhavCopy, Cache, ApiCalls) {
14+
class UDF extends Many(StringUDF, Table, InputValidation, ConvertToSymbol, SqlUDF, BroadCastMessage, Pushlog, QuickTelegramFn, BhavCopy, Cache, AxiosCalls) {
1515
constructor(params) {
1616
super(params)
1717
this.params = params;

0 commit comments

Comments
 (0)