This commit is contained in:
louiscklaw
2025-01-31 19:27:58 +08:00
parent 9476a736d3
commit ce9a4aa9b3
313 changed files with 6340 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
Attribute VB_Name = "CheckLastRow"
Option Explicit
Function run(row as integer)
Dim last_check_row as integer
Dim last_row as boolean
End Function

View File

@@ -0,0 +1,97 @@
Option Explicit
Global TARGET_SHEET as string
Global ROW_START as Integer
Global ChromiumBinaryPath As String
Global COL_STOCK_CODE As String
Global COL_STOCK_NAME As String
Global COL_STOCK_PRICE As String
Global COL_10_DAY_MOVING_AVERAGE As String
Global COL_20_DAY_MOVING_AVERAGE As String
Global COL_50_DAY_MOVING_AVERAGE As String
Global COL_100_DAY_MOVING_AVERAGE As String
Global COL_250_DAY_MOVING_AVERAGE As String
Global COL_P_E_RATIO_EXPECTED As String
Global COL_EARNINGS_PER_SHARE As String
Global COL_YIELD As String
Global COL_FUND_FLOW As String
Global COL_SHORT_SELLING_AMOUNT_RATIO_ As String
Global COL_RSI_10 As String
Global COL_RSI_14 As String
Global COL_RSI_20 As String
Global COL_MACD_8_17_DAYS As String
Global COL_MACD_12_25_DAYS As String
Global IDX_STOCK_CODE As Integer
Global IDX_STOCK_NAME As Integer
Global IDX_STOCK_PRICE As Integer
Global IDX_10_DAY_MOVING_AVERAGE As Integer
Global IDX_20_DAY_MOVING_AVERAGE As Integer
Global IDX_50_DAY_MOVING_AVERAGE As Integer
Global IDX_100_DAY_MOVING_AVERAGE As Integer
Global IDX_250_DAY_MOVING_AVERAGE As Integer
Global IDX_P_E_RATIO_EXPECTED As Integer
Global IDX_EARNINGS_PER_SHARE As Integer
Global IDX_YIELD As Integer
Global IDX_FUND_FLOW As Integer
Global IDX_SHORT_SELLING_AMOUNT_RATIO_ As Integer
Global IDX_RSI_10 As Integer
Global IDX_RSI_14 As Integer
Global IDX_RSI_20 As Integer
Global IDX_MACD_8_17_DAYS As Integer
Global IDX_MACD_12_25_DAYS As Integer
Global COL_RESULT As String
Sub init()
ChromiumBinaryPath = "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
TARGET_SHEET = "Sheet1"
ROW_START = 11
COL_STOCK_CODE = "A"
COL_STOCK_NAME = "B"
COL_STOCK_PRICE = "C"
COL_10_DAY_MOVING_AVERAGE = "D"
COL_20_DAY_MOVING_AVERAGE = "E"
COL_50_DAY_MOVING_AVERAGE = "F"
COL_100_DAY_MOVING_AVERAGE = "G"
COL_250_DAY_MOVING_AVERAGE = "H"
COL_P_E_RATIO_EXPECTED = "L"
COL_EARNINGS_PER_SHARE = "M"
COL_YIELD = "N"
COL_FUND_FLOW = "O"
COL_SHORT_SELLING_AMOUNT_RATIO_ = "P"
COL_RSI_10 = "Q"
COL_RSI_14 = "R"
COL_RSI_20 = "S"
COL_MACD_8_17_DAYS = "V"
COL_MACD_12_25_DAYS = "W"
COL_RESULT = "AE"
IDX_STOCK_CODE = 0
IDX_STOCK_PRICE = 1
IDX_STOCK_NAME = 2
IDX_10_DAY_MOVING_AVERAGE = 4
IDX_20_DAY_MOVING_AVERAGE = 5
IDX_50_DAY_MOVING_AVERAGE = 6
IDX_100_DAY_MOVING_AVERAGE = 7
IDX_250_DAY_MOVING_AVERAGE = 8
IDX_P_E_RATIO_EXPECTED = 9
IDX_EARNINGS_PER_SHARE = 10
IDX_YIELD = 11
IDX_FUND_FLOW = 12
IDX_SHORT_SELLING_AMOUNT_RATIO_ = 13
IDX_RSI_10 = 14
IDX_RSI_14 = 15
IDX_RSI_20 = 16
IDX_MACD_8_17_DAYS = 17
IDX_MACD_12_25_DAYS = 18
End Sub

View File

@@ -0,0 +1,96 @@
Attribute VB_Name = "FetchAaStock"
Dim driver As New ChromeDriver
Function run(stock_num as integer)
' On Error GoTo eh
Dim fetch_result(0 To 22) As String
driver.SetBinary ChromiumBinaryPath
driver.AddArgument "--disable-blink-features=AutomationControlled"
driver.Start
' ' driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
' ' driver.ExecuteScript "alert('helloworld')"
driver.ExecuteScript "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
' ' driver.Get "http://localhost:8080/navigator_webdriver_test.html"
' ' https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html
' driver.Get "https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html"
' driver.ExecuteScript "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
driver.Get "http://www.aastocks.com"
' driver.ExecuteScript "console.log('hello excel')"
driver.ExecuteScript "document.querySelector('#sb-txtSymbol-aa').value = '"& stock_num &"'"
driver.ExecuteScript "document.querySelector('#sb-btnSubmit').click()"
driver.ExecuteScript "document.querySelectorAll('span.float_l')[6].click()"
Debug.Print driver.ExecuteScript("{ return 'helloworld from chrome' }")
' stock_Name # Name
fetch_result(IDX_STOCK_NAME)= driver.ExecuteScript("{ return document.querySelector('#SQ_Name').textContent.trim() }")
' stock_Price # Price
fetch_result(IDX_STOCK_PRICE)= driver.ExecuteScript("{ return document.querySelector('#labelLast').textContent.trim() }")
' 10_day_Moving_Average # 10????
fetch_result(IDX_10_DAY_MOVING_AVERAGE)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel.dq-panel')[1].querySelectorAll('tr')[1].querySelectorAll('td')[1].textContent.trim() }")
' 20_day_Moving_Average # 20????
fetch_result(IDX_20_DAY_MOVING_AVERAGE)= "20_day_Moving_Average missing"
' 50_day_Moving_Average # 50????
fetch_result(IDX_50_DAY_MOVING_AVERAGE)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel.dq-panel')[1].querySelectorAll('tr')[2].querySelectorAll('td')[1].textContent.trim() }")
' 100_day_Moving_Average # 100????
fetch_result(IDX_100_DAY_MOVING_AVERAGE)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel.dq-panel')[1].querySelectorAll('tr')[3].querySelectorAll('td')[1].textContent.trim() }")
' 250_day_Moving_Average # 250????
fetch_result(IDX_250_DAY_MOVING_AVERAGE)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel.dq-panel')[1].querySelectorAll('tr')[4].querySelectorAll('td')[1].textContent.trim() }")
' P_E_Ratio_Expected # ???/??
fetch_result(IDX_P_E_RATIO_EXPECTED)= driver.ExecuteScript("{ return document.querySelectorAll('#tbPERatio div')[5].textContent.trim() }")
' Earnings_per_Share # ??????
fetch_result(IDX_EARNINGS_PER_SHARE)= "earnings_per_share is missing"
' Yield # ???
fetch_result(IDX_YIELD)= driver.ExecuteScript("{ return document.querySelectorAll('.quote-box div')[19].textContent.trim() }")
' Fund_Flow # ????
fetch_result(IDX_FUND_FLOW)= driver.ExecuteScript("{ return document.querySelectorAll('.quote-box div')[29].textContent.trim() }")
' Short_Selling_Amount_Ratio_% # ???_??(%)
fetch_result(IDX_SHORT_SELLING_AMOUNT_RATIO_)= driver.ExecuteScript("{ return document.querySelectorAll('.quote-box div')[4].textContent.trim() }")
' RSI_10 # RSI 10
fetch_result(IDX_RSI_10)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel')[7].querySelectorAll('table')[0].querySelectorAll('tr')[0].querySelector('.txt_r').textContent.trim() }")
' RSI_14 # RSI 14
fetch_result(IDX_RSI_14)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel')[7].querySelectorAll('table')[0].querySelectorAll('tr')[0].querySelector('.txt_r').textContent.trim() }")
' RSI_20 # RSI 20
fetch_result(IDX_RSI_20)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel')[7].querySelectorAll('table')[0].querySelectorAll('tr')[1].querySelector('.txt_r').textContent.trim() }")
' MACD_8_17_days # MACD(8_17 ?)
fetch_result(IDX_MACD_8_17_DAYS)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel')[7].querySelectorAll('table')[0].querySelectorAll('tr')[2].querySelector('.txt_r').textContent.trim() }")
' MACD_12_25_days # MACD(12/25 ?)
fetch_result(IDX_MACD_12_25_DAYS)= driver.ExecuteScript("{ return document.querySelectorAll('.content.comm-panel')[7].querySelectorAll('table')[0].querySelectorAll('tr')[3].querySelector('.txt_r').textContent.trim() }")
' Application.Wait Now + TimeValue("00:30:01")
driver.Quit
Done:
' Debug.Print "hello done"
run = fetch_result
Exit Function
eh:
Debug.Print "hello error"
End Function

View File

@@ -0,0 +1,5 @@
Attribute VB_Name = "GetLastCheckRow"
Function run(first_row As Integer)
getLastCheckRow = first_row + 10
End Function

View File

@@ -0,0 +1,74 @@
Option Explicit
Dim rowc, cc, columnC As Integer
Sub helloworld()
' On Error GoTo eh
Config.init
Dim temp as Variant
' Debug.print ReadStockCode.run(11)
temp = FetchAaStock.run(268)
' Debug.print temp(IDX_STOCK_PRICE)
Debug.print temp(IDX_STOCK_NAME)
Write_10DayMovingAverage.run 11, CStr(temp(IDX_10_DAY_MOVING_AVERAGE))
Write_50DayMovingAverage.run 11, CStr(temp(IDX_50_DAY_MOVING_AVERAGE))
Write_100DayMovingAverage.run 11, CStr(temp(IDX_100_DAY_MOVING_AVERAGE))
Write_250DayMovingAverage.run 11, CStr(temp(IDX_250_DAY_MOVING_AVERAGE))
WriteRsi_10.run 11, CStr(temp(IDX_10_DAY_MOVING_AVERAGE))
WriteRsi_14.run 11, CStr(temp(IDX_50_DAY_MOVING_AVERAGE))
WriteRsi_20.run 11, CStr(temp(IDX_50_DAY_MOVING_AVERAGE))
WriteMACD_8_17Days.run 11, CStr(temp(IDX_MACD_8_17_DAYS))
WriteMACD_12_25Days.run 11, CStr(temp(IDX_MACD_12_25_DAYS))
WriteEarningsPerShare.run 11, CStr(temp(IDX_EARNINGS_PER_SHARE))
WriteFundFlow.run 11, CStr(temp(IDX_FUND_FLOW))
WritePERatioExpected.run 11, CStr(temp(IDX_P_E_RATIO_EXPECTED))
WriteShortSellingAmountRatio.run 11, CStr(temp(IDX_SHORT_SELLING_AMOUNT_RATIO_))
' WriteStockCode.run 11, CStr(temp(IDX_STOCK_CODE))
WriteStockName.run 11, CStr(temp(IDX_STOCK_NAME))
WriteStockPrice.run 11, CStr(temp(IDX_STOCK_PRICE))
WriteYield.run 11, CStr(temp(IDX_YIELD))
' driver.SetBinary ChromiumBinaryPath
' driver.Start
' driver.AddArgument "--disable-blink-features=AutomationControlled"
' ' driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
' ' driver.ExecuteScript "alert('helloworld')"
' ' driver.ExecuteScript "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
' ' driver.Get "http://localhost:8080/navigator_webdriver_test.html"
' ' https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html
' ' driver.Get "https://intoli.com/blog/not-possible-to-block-chrome-headless/chrome-headless-test.html"
' driver.ExecuteScript "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
' driver.Get "http://www.aastocks.com"
' driver.ExecuteScript "console.log('hello excel')"
' driver.ExecuteScript "document.querySelector('#sb-txtSymbol-aa').value = '939'"
' driver.ExecuteScript "document.querySelector('#sb-btnSubmit').click()"
' Debug.Print driver.ExecuteScript("return 'helloworld'")
Application.Wait Now + TimeValue("00:00:01")
Done:
Debug.Print "hello done"
Exit Sub
eh:
Debug.Print "hello error"
End Sub

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadEarningsPerShare"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadFundFlow"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadMACD_12_25Days"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadMacd_8_17Days"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadPERatioExpected"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadRsi_10"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadRsi_14"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadRsi_20"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadShortSellingAmountRatio"

View File

@@ -0,0 +1,7 @@
Attribute VB_Name = "ReadStockCode"
Option Explicit
Function run(row as integer)
run = Worksheets("Sheet1").Range("A" & CStr(row)).Value
End Function

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadStockName"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadStockPrice"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "ReadYield"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "Read_100DayMovingAverage"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "Read_10DayMovingAverage"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "Read_20DayMovingAverage"

View File

@@ -0,0 +1 @@
Attribute VB_Name = "Read_250DayMovingAverage"

View File

@@ -0,0 +1,5 @@
Option Explicit
Sub Helloworld()
Worksheets ("Sheet1")
End Sub

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteEarningsPerShare"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_EARNINGS_PER_SHARE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteEarningsPerShare"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteFundFlow"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_FUND_FLOW & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteFundFlow"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteMACD_12_25Days"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_MACD_12_25_DAYS & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteMACD_12_25Days"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteMACD_8_17Days"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_MACD_8_17_DAYS & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteMACD_8_17Days"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WritePERatioExpected"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_P_E_RATIO_EXPECTED & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WritePERatioExpected"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteRsi_10"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_RSI_10 & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteRsi_10"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteRsi_14"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_RSI_14 & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteRsi_14"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteRsi_20"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_RSI_20 & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteRsi_20"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteShortSellingAmountRatio"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_SHORT_SELLING_AMOUNT_RATIO_ & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteShortSellingAmountRatio"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteStockCode"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_STOCK_CODE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteStockCode"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteStockName"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_STOCK_NAME & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteStockName"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteStockPrice"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_STOCK_PRICE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteStockPrice"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "WriteYield"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_YIELD & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "WriteYield"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "Write_100DayMovingAverage"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_100_DAY_MOVING_AVERAGE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "Write_100DayMovingAverage"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "Write_10DayMovingAverage"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_10_DAY_MOVING_AVERAGE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "Write_10DayMovingAverage"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,6 @@
Attribute VB_Name = "Write_20DayMovingAverage"
Option Explicit
Function run()
Debug.Print "Helloworld Write_20DayMovingAverage"
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "Write_250DayMovingAverage"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_250_DAY_MOVING_AVERAGE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "Write_250DayMovingAverage"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,16 @@
Attribute VB_Name = "Write_50DayMovingAverage"
Option Explicit
Function run(row as integer, content as string)
On Error GoTo eh
Worksheets(TARGET_SHEET).Range(COL_50_DAY_MOVING_AVERAGE & CStr(row)).Value = content
Done:
exit Function
eh:
debug.print "Write_50DayMovingAverage"
debug.print row
debug.print content
End Function

View File

@@ -0,0 +1,5 @@
@REM start excel by yourself
@REM ./test.xlsm
xlwings vba edit

View File

@@ -0,0 +1,13 @@
{
"name": "hello-error",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"gitUpdate":"git add . && git commit -m\"update,\""
},
"keywords": [],
"author": "",
"license": "ISC"
}