- ©«¤l
- 519
- ¥DÃD
- 54
- ºëµØ
- 0
- ¿n¤À
- 595
- ÂI¦W
- 251
- §@·~¨t²Î
- win 10
- ³nÅ骩¥»
- []
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2013-3-19
- ³Ì«áµn¿ý
- 2024-11-18
|
¦^´_ 2# joey0415
¸Õ§@¦p¤U¡A½Ð joey0415 ¤j°Ñ¦Ò©ò¥¿¡AÁÂÁ¡G
Option Base 1
'myArr() ªºÄæ¦ì¡G ¤é´Á¡B¶}¡B°ª¡B§C¡B¦¬¡Bº¦¡Bº¦%¡B±i¼Æ
'¹d¦ë¸ê®Æ¦C ¡G¤é´Á¡B¶}¡B°ª¡B§C¡B¦¬¡B±i¼Æ
Sub ¹d¦ë¾ú¥vK_Test1()
Dim stockno$, myTEXT, myText1
Dim sh As Worksheet
Dim T!, recCAT$, i%, j%, k%, n%, Trade%, BarCntReq%
Dim myXML As Object, URL$, myArr
Dim StartDate&, EndDate&
Const Dat% = 1, Op% = 2, Hi% = 3, Low% = 4, Klose% = 5, CHG% = 6, CHGpercent% = 7, Vol% = 8 'for myArr
StartDate = DateToUnixTime("2020/01/02")
EndDate = DateToUnixTime(Format(Date, "yyyy/mm/dd"))
Application.DisplayStatusBar = True
Application.StatusBar = stockno & " ³sºô¤¤... "
Set myXML = CreateObject("WinHttp.WinHttpRequest.5.1")
recCAT = "D" '¤é½u¹Ï
URL = "https://ws.api.cnyes.com/charting/api/v1/history?resolution=" & recCAT & "&symbol=TWS:2330:STOCK&from=" & EndDate & "&to=" & StartDate
T = timer
With myXML
.Open "GET", URL, False
.send
Do While .Status <> 200
DoEvents
If timer - T > 3 Then Exit Do
Loop
myTEXT = .responsetext '¤å¦r¦ê .txt
End With
Set myXML = Nothing
If myTEXT = "" Then GoTo Exit_Sub
myTEXT = Split(myTEXT, ":")
myText1 = Split(Replace(Replace(myTEXT(5), "[", ""), "]", ""), ",")
n = UBound(myText1): ReDim myArr(n + 1, 8)
For i = 0 To UBound(myText1) - 1
myArr(i + 1, 1) = UnixTime2Date(myText1(i))
Next
k = 4
For j = 6 To 10 '¶}¡B°ª¡B§C¡B¦¬¡B±i¼Æ
myText1 = Split(myTEXT(j), ",")
If j = 10 Then k = 2 '±±¨î myArr ªº¦æ¼Æ(column), ²Ä8¦æ¬O±i¼Æ
For i = 0 To n - 1
myArr(i + 1, j - k) = myText1(i)
Next
myArr(1, j - k) = Replace(myArr(1, j - k), "[", ""): myArr(n, j - k) = Replace(myArr(n, j - k), "]", "")
Next j
For i = 1 To n - 1
myArr(i, 6) = myArr(i, 5) - myArr(i + 1, 5): myArr(i, 7) = Format(myArr(i, 6) / myArr(i + 1, 5) * 100, "#0.00") 'º¦¶^¡Bº¦¶^%
Next
Exit_Sub:
Set myXML = Nothing
Application.StatusBar = ""
Application.DisplayStatusBar = False
End Sub
Function DateToUnixTime(dstring) As Long
DateToUnixTime = (DateValue(dstring) - #1/1/1970 8:00:00 AM#) * 86400
End Function
Function UnixTime2Date(UnixT) As Date
UnixTime2Date = Format(UnixT / 86400 + #1/1/1970 8:00:00 AM#, "yyyy/mm/dd")
End Function |
|