@engineering-tf/shared 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/index.d.ts +9 -0
- package/dist/constants/index.js +96 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +25 -0
- package/dist/types/optionChain.d.ts +21 -0
- package/dist/types/optionChain.js +2 -0
- package/dist/types/optionTrades.d.ts +101 -0
- package/dist/types/optionTrades.js +53 -0
- package/dist/types/shared.d.ts +376 -0
- package/dist/types/shared.js +218 -0
- package/dist/types/websocketCF.d.ts +30 -0
- package/dist/types/websocketCF.js +2 -0
- package/dist/utils/common/date-functions.d.ts +45 -0
- package/dist/utils/common/date-functions.js +150 -0
- package/dist/utils/common/discord-functions.d.ts +3 -0
- package/dist/utils/common/discord-functions.js +89 -0
- package/dist/utils/common/math-functions.d.ts +32 -0
- package/dist/utils/common/math-functions.js +118 -0
- package/dist/utils/common/record-function.d.ts +116 -0
- package/dist/utils/common/record-function.js +308 -0
- package/dist/utils/common/util-functions.d.ts +4 -0
- package/dist/utils/common/util-functions.js +94 -0
- package/dist/utils/strategy/calculateScoreAndStrategy.d.ts +14 -0
- package/dist/utils/strategy/calculateScoreAndStrategy.js +133 -0
- package/package.json +29 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isMarketOpen = exports.getTimestamp = exports.convertUnixTimestampToTime = exports.convertUnixTimestampToDate = exports.isOneDateBeforeAnotherDate = exports.momentInNewYork = exports.getDiffDaysBetweenFutureAndPast = exports.getDiffDaysBetweenFutureAndToday = exports.convertDateFormatToYYYYMMDD = exports.convertDateToString = exports.getLastTradeDate = exports.isTradingDate = void 0;
|
|
7
|
+
var moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
8
|
+
function isTradingDate(todayDateStr) {
|
|
9
|
+
if (todayDateStr === void 0) { todayDateStr = (0, moment_timezone_1.default)().tz("America/New_York").format('YYYY-MM-DD'); }
|
|
10
|
+
//TODO: there is a bug for 2023-12-26, it should be a trading date, but it's not, it is working on local, not working on ec2
|
|
11
|
+
var todayDate = (0, moment_timezone_1.default)(todayDateStr);
|
|
12
|
+
todayDate.add(30, 'minutes');
|
|
13
|
+
// Check if it's a weekend
|
|
14
|
+
if (todayDate.isoWeekday() >= 6) { // we don't check holiday, because holiday package is not reliable
|
|
15
|
+
console.info("todayDate is ".concat(todayDate, ", todayDate.isoWeekday() is ").concat(todayDate.isoWeekday(), ",todayDateStr is ").concat(todayDateStr, ")}"));
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
exports.isTradingDate = isTradingDate;
|
|
21
|
+
/**
|
|
22
|
+
* @description 取最近的交易日 in New York timezone, in the format of YYYY-MM-DD,
|
|
23
|
+
* exclude weekends and holidays, and before 9:30am(PST)
|
|
24
|
+
*/
|
|
25
|
+
function getLastTradeDate(format, currentMoment) {
|
|
26
|
+
if (format === void 0) { format = 'YYYY-MM-DD'; }
|
|
27
|
+
if (currentMoment === void 0) { currentMoment = (0, moment_timezone_1.default)().tz("America/New_York"); }
|
|
28
|
+
var lastTradingDate = currentMoment;
|
|
29
|
+
var time = (0, moment_timezone_1.default)(lastTradingDate.format("YYYY-MM-DD HH:mm"));
|
|
30
|
+
var today = lastTradingDate.format("YYYY-MM-DD");
|
|
31
|
+
if (lastTradingDate.isoWeekday() === 6 ||
|
|
32
|
+
lastTradingDate.isoWeekday() === 7
|
|
33
|
+
// || hd.isHoliday(lastTradingDate.toISOString())
|
|
34
|
+
) {
|
|
35
|
+
while (lastTradingDate.isoWeekday() === 6 ||
|
|
36
|
+
lastTradingDate.isoWeekday() === 7
|
|
37
|
+
// || hd.isHoliday(lastTradingDate.toISOString())
|
|
38
|
+
) {
|
|
39
|
+
lastTradingDate = lastTradingDate.subtract(1, "days");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (time.isSameOrAfter(today + " 00:00") &&
|
|
43
|
+
time.isBefore(today + " 09:30")) {
|
|
44
|
+
lastTradingDate = lastTradingDate.subtract(1, "days");
|
|
45
|
+
while ( //For the case of Monday Morning.
|
|
46
|
+
lastTradingDate.isoWeekday() === 6 ||
|
|
47
|
+
lastTradingDate.isoWeekday() === 7
|
|
48
|
+
// || hd.isHoliday(lastTradingDate.toISOString())
|
|
49
|
+
) {
|
|
50
|
+
lastTradingDate = lastTradingDate.subtract(1, "days");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return lastTradingDate.format(format);
|
|
54
|
+
}
|
|
55
|
+
exports.getLastTradeDate = getLastTradeDate;
|
|
56
|
+
/**
|
|
57
|
+
* @description 将Date Object转化为日期string YYYY-MM-DD
|
|
58
|
+
*/
|
|
59
|
+
function convertDateToString(date) {
|
|
60
|
+
return date.toISOString().split("T")[0];
|
|
61
|
+
}
|
|
62
|
+
exports.convertDateToString = convertDateToString;
|
|
63
|
+
/**
|
|
64
|
+
* @description 将string YYYY-MM-DD convert to YYYYMMDD
|
|
65
|
+
*/
|
|
66
|
+
function convertDateFormatToYYYYMMDD(date) {
|
|
67
|
+
return date.split("-").join("");
|
|
68
|
+
}
|
|
69
|
+
exports.convertDateFormatToYYYYMMDD = convertDateFormatToYYYYMMDD;
|
|
70
|
+
/**
|
|
71
|
+
* @description 计算一个未来的日期和今天的相差天数(按照UTC)
|
|
72
|
+
*/
|
|
73
|
+
var getDiffDaysBetweenFutureAndToday = function (future_date) {
|
|
74
|
+
var endData = moment_timezone_1.default.utc(future_date);
|
|
75
|
+
var startDate = moment_timezone_1.default.utc();
|
|
76
|
+
return endData.diff(startDate, "day");
|
|
77
|
+
};
|
|
78
|
+
exports.getDiffDaysBetweenFutureAndToday = getDiffDaysBetweenFutureAndToday;
|
|
79
|
+
/**
|
|
80
|
+
* @description 计算两个日期之间的相差天数
|
|
81
|
+
*/
|
|
82
|
+
var getDiffDaysBetweenFutureAndPast = function (future_date, past_date) {
|
|
83
|
+
var endData = (0, moment_timezone_1.default)(future_date);
|
|
84
|
+
var startDate = (0, moment_timezone_1.default)(past_date);
|
|
85
|
+
return endData.diff(startDate, "day");
|
|
86
|
+
};
|
|
87
|
+
exports.getDiffDaysBetweenFutureAndPast = getDiffDaysBetweenFutureAndPast;
|
|
88
|
+
function momentInNewYork() {
|
|
89
|
+
return (0, moment_timezone_1.default)().tz("America/New_York");
|
|
90
|
+
}
|
|
91
|
+
exports.momentInNewYork = momentInNewYork;
|
|
92
|
+
/**
|
|
93
|
+
* @description whether one date in format of YYYY-MM-DD is before/same before another date
|
|
94
|
+
*/
|
|
95
|
+
function isOneDateBeforeAnotherDate(a_date, b_date, could_be_same_date) {
|
|
96
|
+
if (b_date === void 0) { b_date = (0, moment_timezone_1.default)().format("YYYY-MM-DD"); }
|
|
97
|
+
if (could_be_same_date === void 0) { could_be_same_date = false; }
|
|
98
|
+
return could_be_same_date
|
|
99
|
+
? (0, moment_timezone_1.default)(a_date).isSameOrBefore(b_date)
|
|
100
|
+
: (0, moment_timezone_1.default)(a_date).isBefore(b_date);
|
|
101
|
+
}
|
|
102
|
+
exports.isOneDateBeforeAnotherDate = isOneDateBeforeAnotherDate;
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param time unix time stamp
|
|
106
|
+
* @returns a date format in YYYY-MM-DD in New York Time Zone
|
|
107
|
+
*/
|
|
108
|
+
function convertUnixTimestampToDate(time, format) {
|
|
109
|
+
if (format === void 0) { format = "YYYY-MM-DD"; }
|
|
110
|
+
return moment_timezone_1.default
|
|
111
|
+
.unix(parseInt(time) / 1000)
|
|
112
|
+
.tz("America/New_York")
|
|
113
|
+
.format(format);
|
|
114
|
+
}
|
|
115
|
+
exports.convertUnixTimestampToDate = convertUnixTimestampToDate;
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param time unix time stamp
|
|
119
|
+
* @returns a date format in HH:mm:ss in New York Time Zone
|
|
120
|
+
*/
|
|
121
|
+
function convertUnixTimestampToTime(time, format) {
|
|
122
|
+
if (format === void 0) { format = "HH:mm:ss"; }
|
|
123
|
+
return moment_timezone_1.default
|
|
124
|
+
.unix(parseInt(time) / 1000)
|
|
125
|
+
.tz("America/New_York")
|
|
126
|
+
.format(format);
|
|
127
|
+
}
|
|
128
|
+
exports.convertUnixTimestampToTime = convertUnixTimestampToTime;
|
|
129
|
+
/**
|
|
130
|
+
* get current timestamp in unix format
|
|
131
|
+
*/
|
|
132
|
+
function getTimestamp() {
|
|
133
|
+
return (0, moment_timezone_1.default)().unix();
|
|
134
|
+
}
|
|
135
|
+
exports.getTimestamp = getTimestamp;
|
|
136
|
+
function isMarketOpen(currentMoment) {
|
|
137
|
+
if (currentMoment === void 0) { currentMoment = (0, moment_timezone_1.default)().tz("America/New_York"); }
|
|
138
|
+
var time = (0, moment_timezone_1.default)(currentMoment.format("YYYY-MM-DD HH:mm"));
|
|
139
|
+
var today = currentMoment.format("YYYY-MM-DD");
|
|
140
|
+
if (currentMoment.isoWeekday() === 6 ||
|
|
141
|
+
currentMoment.isoWeekday() === 7) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (time.isSameOrBefore(today + " 17:00") &&
|
|
145
|
+
time.isSameOrAfter(today + " 09:30")) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
exports.isMarketOpen = isMarketOpen;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.discordMessageSender = exports.TRADINGFLOW_ALL_TEST_LOG = void 0;
|
|
40
|
+
var localLogging = function (msg) {
|
|
41
|
+
if (process.env.NODE_ENV !== 'production' && process.env.CUSTOM_NODE_ENV !== 'production') {
|
|
42
|
+
console.log("[LOCAL ONLY LOG] ".concat(msg));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.TRADINGFLOW_ALL_TEST_LOG = "https://discord.com/api/webhooks/1024841963209490542/Pn45x2jJ4-jlXKF9V5mXMJtCNgD4LgOBW6daEBJOBz9WalSt7NsxXimJMi1RvOiRVvDW";
|
|
46
|
+
function discordMessageSender(msg, channel) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var err_1;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
localLogging("[LOCAL LOGGING] send message to discord: ".concat(msg, ")"));
|
|
53
|
+
_a.label = 1;
|
|
54
|
+
case 1:
|
|
55
|
+
_a.trys.push([1, 3, , 4]);
|
|
56
|
+
return [4 /*yield*/, channel.send(truncateString(msg))];
|
|
57
|
+
case 2:
|
|
58
|
+
_a.sent();
|
|
59
|
+
return [3 /*break*/, 4];
|
|
60
|
+
case 3:
|
|
61
|
+
err_1 = _a.sent();
|
|
62
|
+
/**
|
|
63
|
+
* Sometime, we are not able to send discord messages
|
|
64
|
+
*/
|
|
65
|
+
localLogging("Not able to send discord message, err is ".concat(err_1.message, " ").concat(JSON.stringify(err_1)));
|
|
66
|
+
return [3 /*break*/, 4];
|
|
67
|
+
case 4: return [2 /*return*/];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.discordMessageSender = discordMessageSender;
|
|
73
|
+
/**
|
|
74
|
+
* discord has a 2000 character limit, so we need to truncate the string
|
|
75
|
+
* @param input
|
|
76
|
+
* @param maxLength
|
|
77
|
+
* @param useEllipsis
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
function truncateString(input, maxLength, useEllipsis) {
|
|
81
|
+
if (maxLength === void 0) { maxLength = 1990; }
|
|
82
|
+
if (useEllipsis === void 0) { useEllipsis = true; }
|
|
83
|
+
if (input.length <= maxLength)
|
|
84
|
+
return input;
|
|
85
|
+
// Adjust the maximum length to account for ellipsis if needed
|
|
86
|
+
var effectiveLength = useEllipsis ? maxLength - 3 : maxLength;
|
|
87
|
+
// Return the truncated string
|
|
88
|
+
return input.substring(0, effectiveLength) + (useEllipsis ? "..." : "");
|
|
89
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* @num could be negative
|
|
4
|
+
* 3000 => 3K,
|
|
5
|
+
* 3000000 => 3M
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertLargeNumberToFormattedString(input: number, precision?: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* @description convert '1K' => 1000, '1M' => 1000000
|
|
10
|
+
*/
|
|
11
|
+
export declare const convertFormattedStringToLargeNumber: (total: string) => number;
|
|
12
|
+
/**
|
|
13
|
+
* @description 98.4% => 0.984
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertPctStringToNumber(pct: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* @description convert $3,105,773,056 to 3105773056
|
|
18
|
+
*/
|
|
19
|
+
export declare const convertMoneyStringToLargeNumber: (money: string) => number;
|
|
20
|
+
/**
|
|
21
|
+
* @description convert 3,105,773,056 to 3105773056
|
|
22
|
+
*/
|
|
23
|
+
export declare const convertCommaSeparatedNumberStringToLargeNumber: (money: string) => number;
|
|
24
|
+
/**
|
|
25
|
+
* @description 3.23231 => 3.23, 3.235 => 3.23, 3.236 => 3.24
|
|
26
|
+
*/
|
|
27
|
+
export declare function fixFloatPrecisionToString(num: any, precision?: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* @description 3.23231 => 3.23, return number
|
|
30
|
+
*/
|
|
31
|
+
export declare function fixFloatPrecisionToNumber(num: any, precision?: number): number;
|
|
32
|
+
export declare function addNSecondsDelay(n: number): any;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addNSecondsDelay = exports.fixFloatPrecisionToNumber = exports.fixFloatPrecisionToString = exports.convertCommaSeparatedNumberStringToLargeNumber = exports.convertMoneyStringToLargeNumber = exports.convertPctStringToNumber = exports.convertFormattedStringToLargeNumber = exports.convertLargeNumberToFormattedString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* @num could be negative
|
|
7
|
+
* 3000 => 3K,
|
|
8
|
+
* 3000000 => 3M
|
|
9
|
+
*/
|
|
10
|
+
function convertLargeNumberToFormattedString(input, precision) {
|
|
11
|
+
if (precision === void 0) { precision = 2; }
|
|
12
|
+
if (!input || input === 0)
|
|
13
|
+
return "0";
|
|
14
|
+
var num;
|
|
15
|
+
var res;
|
|
16
|
+
var isNeg = false;
|
|
17
|
+
if (input < 0) {
|
|
18
|
+
num = -input;
|
|
19
|
+
isNeg = true;
|
|
20
|
+
}
|
|
21
|
+
else
|
|
22
|
+
num = input;
|
|
23
|
+
if (num < 1000)
|
|
24
|
+
res = num.toString();
|
|
25
|
+
else if (num >= 1000 && num < 1000000)
|
|
26
|
+
res = (num / 1000).toFixed(precision) + "K";
|
|
27
|
+
else if (num >= 1000000 && num < 1000000000)
|
|
28
|
+
res = (num / 1000000).toFixed(precision) + "M";
|
|
29
|
+
else
|
|
30
|
+
res = (num / 1000000000).toFixed(precision) + "B";
|
|
31
|
+
if (isNeg)
|
|
32
|
+
res = '-' + res;
|
|
33
|
+
return res;
|
|
34
|
+
}
|
|
35
|
+
exports.convertLargeNumberToFormattedString = convertLargeNumberToFormattedString;
|
|
36
|
+
/**
|
|
37
|
+
* @description convert '1K' => 1000, '1M' => 1000000
|
|
38
|
+
*/
|
|
39
|
+
var convertFormattedStringToLargeNumber = function (total) {
|
|
40
|
+
var last_digit = total.charAt(total.length - 1);
|
|
41
|
+
switch (last_digit) {
|
|
42
|
+
case "K":
|
|
43
|
+
return parseInt(total.substring(0, total.length - 1)) * 1000;
|
|
44
|
+
case "M":
|
|
45
|
+
return parseInt(total.substring(0, total.length - 1)) * 1000000;
|
|
46
|
+
case "B":
|
|
47
|
+
return parseInt(total.substring(0, total.length - 1)) * 1000000000;
|
|
48
|
+
default:
|
|
49
|
+
return parseInt(total);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.convertFormattedStringToLargeNumber = convertFormattedStringToLargeNumber;
|
|
53
|
+
/**
|
|
54
|
+
* @description 98.4% => 0.984
|
|
55
|
+
*/
|
|
56
|
+
function convertPctStringToNumber(pct) {
|
|
57
|
+
return parseFloat(fixFloatPrecisionToString(Number(pct.substring(0, pct.length - 1)) / 100, 3));
|
|
58
|
+
}
|
|
59
|
+
exports.convertPctStringToNumber = convertPctStringToNumber;
|
|
60
|
+
/**
|
|
61
|
+
* @description convert $3,105,773,056 to 3105773056
|
|
62
|
+
*/
|
|
63
|
+
var convertMoneyStringToLargeNumber = function (money) {
|
|
64
|
+
/** step 1: remove $ */
|
|
65
|
+
var moneySliced = money.slice(1);
|
|
66
|
+
/** step 2: 3,100 =>3100 */
|
|
67
|
+
return (0, exports.convertCommaSeparatedNumberStringToLargeNumber)(moneySliced);
|
|
68
|
+
};
|
|
69
|
+
exports.convertMoneyStringToLargeNumber = convertMoneyStringToLargeNumber;
|
|
70
|
+
/**
|
|
71
|
+
* @description convert 3,105,773,056 to 3105773056
|
|
72
|
+
*/
|
|
73
|
+
var convertCommaSeparatedNumberStringToLargeNumber = function (money) {
|
|
74
|
+
/** step 2: 3,100 =>3100
|
|
75
|
+
* skip amount less than 999, otherwise will throw parsing error
|
|
76
|
+
*/
|
|
77
|
+
var moneySplit = "0";
|
|
78
|
+
var moneyString = money.toString();
|
|
79
|
+
try {
|
|
80
|
+
if (moneyString.indexOf(",") == -1) {
|
|
81
|
+
return parseInt(moneyString);
|
|
82
|
+
}
|
|
83
|
+
moneySplit = moneyString.split(",").join("");
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.log("error in convertCommaSeparatedNumberStringToLargeNumber: ".concat(error.message, ", money is ").concat(moneyString, "}"));
|
|
87
|
+
}
|
|
88
|
+
return parseInt(moneySplit);
|
|
89
|
+
};
|
|
90
|
+
exports.convertCommaSeparatedNumberStringToLargeNumber = convertCommaSeparatedNumberStringToLargeNumber;
|
|
91
|
+
/**
|
|
92
|
+
* @description 3.23231 => 3.23, 3.235 => 3.23, 3.236 => 3.24
|
|
93
|
+
*/
|
|
94
|
+
function fixFloatPrecisionToString(num, precision) {
|
|
95
|
+
if (precision === void 0) { precision = 2; }
|
|
96
|
+
if (!num)
|
|
97
|
+
return num;
|
|
98
|
+
return typeof num === "string"
|
|
99
|
+
? parseFloat(num).toFixed(precision)
|
|
100
|
+
: num.toFixed(precision);
|
|
101
|
+
}
|
|
102
|
+
exports.fixFloatPrecisionToString = fixFloatPrecisionToString;
|
|
103
|
+
/**
|
|
104
|
+
* @description 3.23231 => 3.23, return number
|
|
105
|
+
*/
|
|
106
|
+
function fixFloatPrecisionToNumber(num, precision) {
|
|
107
|
+
if (precision === void 0) { precision = 2; }
|
|
108
|
+
return parseFloat(fixFloatPrecisionToString(num, precision));
|
|
109
|
+
}
|
|
110
|
+
exports.fixFloatPrecisionToNumber = fixFloatPrecisionToNumber;
|
|
111
|
+
function addNSecondsDelay(n) {
|
|
112
|
+
return new Promise(function (resolve) {
|
|
113
|
+
setTimeout(function () {
|
|
114
|
+
resolve();
|
|
115
|
+
}, n * 1000);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.addNSecondsDelay = addNSecondsDelay;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CALL_PUT_TAG, MONEYNESS_LABEL, OptionFlowItem, SENTIMENT_TAG, SIDE_LABEL } from '../../types/shared';
|
|
2
|
+
import { OptionFlowItemFull } from '../../types/optionTrades';
|
|
3
|
+
/**
|
|
4
|
+
* opening的定义是size 是今天最大一个订单以保证不是当日内的换仓, 因为他的size比当日所有的剩余的oi+volume都大, 导致无法被换仓, 这样能保证肯定是开仓
|
|
5
|
+
* 如果只是size > oi, 但今天至今交易的volume可能可以跟这个order进行交换, 同时也要大于今日volume
|
|
6
|
+
* @param record
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function passOpeningFilter(record: OptionFlowItem): number;
|
|
10
|
+
export declare function passOpeningFilterFull(record: OptionFlowItemFull): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated potential bugs when the we don't get the data in time, please use calculateRecordExpiryDaysUtil instead
|
|
13
|
+
* @param date_expiration
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function calculateRecordExpiryDays(date_expiration: string): number;
|
|
17
|
+
export declare function calculateRecordExpiryDaysUtil(date_expiration: string, date: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* @description
|
|
20
|
+
* Decide the price side by the price
|
|
21
|
+
*/
|
|
22
|
+
export declare function calculateRecordSide(record: OptionFlowItem): SIDE_LABEL;
|
|
23
|
+
export declare function calculateRecordSideUtil(ask: number, bid: number, price: number): SIDE_LABEL;
|
|
24
|
+
export declare function calculateRecordMoneyness(record: OptionFlowItem): MONEYNESS_LABEL;
|
|
25
|
+
export declare function calculateRecordMoneynessUtil(strike_price: number, ref: number, put_call: CALL_PUT_TAG): MONEYNESS_LABEL;
|
|
26
|
+
/**
|
|
27
|
+
* delta exposure => delta impact in shares
|
|
28
|
+
* calculate the equivalent shares the dealer has to hedge,
|
|
29
|
+
* always positive, because put delta always negative, but it doesn't mean this put trade is a bearish one.
|
|
30
|
+
* TODO: it is going to be replaced by cron function
|
|
31
|
+
* @param record
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function calculateDeltaExposure(record: OptionFlowItem): number;
|
|
35
|
+
export declare function calculateDeltaExposureUtil(delta: number, size: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* calculate the impact on the stock from the delta exposure,
|
|
38
|
+
* always positive
|
|
39
|
+
* @param record
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export declare function calculateDeltaImpact(deltaExposure: number, avgDailyStockVol: number | null): number;
|
|
43
|
+
export declare function compareTwoNullableValue(a: number | null, b: number | null): number;
|
|
44
|
+
export declare function calculateRecordSentiment(record: OptionFlowItem): SENTIMENT_TAG;
|
|
45
|
+
export declare function calculateRecordSentimentUtil(side: SIDE_LABEL, put_call: CALL_PUT_TAG): SENTIMENT_TAG;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param ["32~76"]
|
|
49
|
+
* special case: ["-2.2~-1.1"]
|
|
50
|
+
* @returns [32,76] or [-2.2,-1.1]
|
|
51
|
+
*/
|
|
52
|
+
export declare function calculateMinMaxFromTableFiltersItem(value: [string]): (number | null)[];
|
|
53
|
+
/**
|
|
54
|
+
* @description used to calculate custom id, we need to custom id to combine smart flow with full flow into ddb.
|
|
55
|
+
* @usage CronService ProcessingService
|
|
56
|
+
* @param record
|
|
57
|
+
* @returns STT-20250117-65-PUT-20230501-10:14-250-6.80
|
|
58
|
+
*/
|
|
59
|
+
export declare function calRecordId(record: OptionFlowItem): string;
|
|
60
|
+
/**
|
|
61
|
+
* @usage cron-service process-service
|
|
62
|
+
* @default 365 days
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
export declare function calculateTtl(days?: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* calculate the record option symbol
|
|
68
|
+
* @usage api-service cron-service process-service
|
|
69
|
+
* @param record
|
|
70
|
+
* @ex: CVS230818C00077500 => CVS Oct 23 2020 $77.50 Call
|
|
71
|
+
* PANW250117C00173330 => PANW Jan 17 2025 $173.33 Call
|
|
72
|
+
*/
|
|
73
|
+
export declare function calculateRecordOptionSymbol(record: OptionFlowItem): string;
|
|
74
|
+
export declare function calculateRecordOptionSymbolUtil(ticker: string, date_expiration: string, put_call: CALL_PUT_TAG, strike_price: number): string;
|
|
75
|
+
/**
|
|
76
|
+
"""
|
|
77
|
+
Extracts the underlying stock symbol from a standard option symbol.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
optionSymbol: The option symbol string, e.g., "AAPL240412C00175000".
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
The underlying stock symbol, e.g., "AAPL".
|
|
84
|
+
@usage api-service websocket-service
|
|
85
|
+
|
|
86
|
+
*/
|
|
87
|
+
export declare function extractSymbolFromOptionSymbol(optionSymbol: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* """
|
|
90
|
+
Extracts the option type (CALL or PUT) from the option symbol string.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
optionSymbol: The option symbol string, e.g., "AAPL240412C00175000", "QTTB1241018C00005000"
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
"CALL", "PUT", or null if not found.
|
|
97
|
+
"""
|
|
98
|
+
*/
|
|
99
|
+
export declare function extractOptionTypeFromOptionSymbol(optionSymbol: string): CALL_PUT_TAG;
|
|
100
|
+
/**
|
|
101
|
+
* """
|
|
102
|
+
Extracts the strike price from a standard option symbol.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
optionSymbol: The option symbol string, e.g., "AAPL240412C00175000".
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
The strike price as a number (e.g., 175), or null if not found or invalid.
|
|
109
|
+
""" GLYC241115C00000500 => 0.5
|
|
110
|
+
SPY241030C00582000 => 582
|
|
111
|
+
ZK241220P00022500 => 22.5
|
|
112
|
+
* @param optionSymbol
|
|
113
|
+
* @returns
|
|
114
|
+
*/
|
|
115
|
+
export declare function extractStrikePriceFromOptionSymbol(optionSymbol: string): number | null;
|
|
116
|
+
export declare function extractExpirationDateFromOptionSymbol(optionSymbol: string): string;
|