Last active
October 19, 2020 09:12
-
-
Save owyongsk/9053c4bc8b09ee07b06bc8a8896b310c to your computer and use it in GitHub Desktop.
Automatically add transactions to klse.i3investor.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//****** | |
//* | |
//* 1. Change the text below by pasting each line from the email you receive | |
//* 2. Then open the console, and copy and paste the whole file and press enter | |
//* | |
//****** | |
text = ` | |
Order matched – Bought 30000 units of MTAG (0213) at RM 0.580000 on (2020-07-30 12:12:38). Login to UTRADE for more information. | |
Order matched – Bought 13000 units of HEXZA (3298) at RM 1.330000 on (2020-07-30 12:14:27). Login to UTRADE for more information. | |
Order matched – Bought 30000 units of D&O (7204) at RM 0.810000 on (2020-07-28 13:45:10). Login to UTRADE for more information. | |
` | |
sleep_time = 15 // In seconds | |
function save_transactions(text) { | |
showtransform('a'); | |
text.trim().split("\n").forEach((input, index) => { | |
setTimeout(function() { | |
[_, _, _, type, quantity, _, _, stock, _, _, _, price, _, date] = input.trim().replace(/\(/g, "").split(/\s+/); | |
[year, month, day] = date.split("-"); | |
order_date = `${day}/${month}/${year}`; | |
map = { "Bought": 0, "Sold": 1 }; | |
document.getElementById("txnFormtxnd").value = order_date; | |
document.getElementsByName("stxnt")[0].selectedIndex = map[type]; | |
document.getElementsByName("stxnt")[0].dispatchEvent(new Event('change')); | |
document.getElementById("txnFormsname").value = stock; | |
document.getElementById("txnFormsname").dispatchEvent(new Event('blur')); | |
document.getElementById("txnFormtxnq").value = quantity; | |
document.getElementById("txnFormtxnq").dispatchEvent(new Event('change')); | |
document.getElementById("txnFormtxnup").value = price; | |
document.getElementById("txnFormtxnup").dispatchEvent(new Event('change')); | |
stock = encodeURIComponent(stock); | |
pfid = location.pathname.match(/\d+/)[0]; | |
txnt = portfolioView.stockTxnType().value; | |
txnbrok = roundToDoubleDigit(portfolioView.brokerageCharge()); | |
txnbrokgst = roundToDoubleDigit(portfolioView.brokerageChargeGst()); | |
txncf = portfolioView.clearingFeeCharge(); | |
txncfgst = roundToDoubleDigit(portfolioView.clearingFeeChargeGst()); | |
txnd = encodeURIComponent(order_date); | |
txnc = roundToDoubleDigit(portfolioView.comission() || 0); | |
body = `aa=apfte&pfid=${pfid}&txnd=${txnd}&portfolioEntryTxnPaymentDate=&txng=STOCK&txnt=${txnt}¬e=&txna=&sname=${stock}&txnq=${quantity}&txnup=${price}&txnc=${txnc}&txndt=N&txnsd=0&txncf=${txncf}&txnbrok=${txnbrok}&txncfgst=${txncfgst}&txnbrokgst=${txnbrokgst}&txnoc=0`; | |
console.log(body); | |
fetch("https://klse.i3investor.com/pfservlet.jsp", { | |
"headers": { | |
"accept": "*/*", | |
"accept-language": "es-419,es;q=0.9,en;q=0.8", | |
"cache-control": "no-cache", | |
"content-type": "application/x-www-form-urlencoded; charset=UTF-8", | |
"pragma": "no-cache", | |
"sec-fetch-dest": "empty", | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
"x-requested-with": "XMLHttpRequest", | |
"cookie": document.cookie, | |
}, | |
"referrerPolicy": "no-referrer-when-downgrade", | |
"body": body, | |
"method": "POST", | |
"mode": "cors" | |
}).then(res => res).catch(error => alert(error)); | |
}, index * sleep_time * 1000); | |
}); | |
} | |
save_transactions(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment