Option Explicit
Declare Function SKQuoteLib_Initialize Lib "SKQuoteLib.dll" (ByVal strID As String, ByVal strPass As String) As Long
Declare Function SKQuoteLib_EnterMonitor Lib "SKQuoteLib.dll" () As Long
Declare Function SKQuoteLib_AttachConnectionCallBack Lib "SKQuoteLib.dll" (ByVal Func As Long) As Long
Declare Function SKQuoteLib_AttachQuoteCallBack Lib "SKQuoteLib.dll" (ByVal Func As Long) As Long
Declare Function SKQuoteLib_AttachTicksCallBack Lib "SKQuoteLib.dll" (ByVal Func As Long) As Long
Declare Function SKQuoteLib_AttachBest5CallBack Lib "SKQuoteLib.dll" (ByVal Func As Long) As Long
Declare Function SKQuoteLib_RequestStocks Lib "SKQuoteLib.dll" (ByRef Page As Integer, ByVal Stocks As String) As Long
Declare Function SKQuoteLib_RequestTicks Lib "SKQuoteLib.dll" (ByRef Page As Integer, ByVal Stock As String) As Long
Declare Function SKQuoteLib_GetStockByNo Lib "SKQuoteLib.dll" (ByVal strStockNo As String, ByRef Stock As TStock) As Long
Declare Function SKQuoteLib_GetStockByIndex Lib "SKQuoteLib.dll" (ByVal Market As Integer, ByVal Index As Integer, ByRef Stock As TStock) As Long
Declare Function SKQuoteLib_GetTick Lib "SKQuoteLib.dll" (ByVal Market As Integer, ByVal Index As Integer, ByVal Ptr As Long, ByRef Tick As TTick) As Long
Declare Function SKQuoteLib_GetBest5 Lib "SKQuoteLib.dll" (ByVal Market As Integer, ByVal Index As Integer, ByRef Best5 As TBest5) As Long
Type TStock
Stockidx As Integer
Decimal As Integer
TypeNo As Integer
MarketNo As Byte
StockNo As String * 20
StockName As String * 10
Open As Long
High As Long
Low As Long
Close As Long
TickQty As Long ' 單量
Ref As Long ' 昨收、參考價
Bid As Long ' 買價
Bc As Long ' 買量
Ask As Long ' 賣價
Ac As Long ' 賣量
TBc As Long ' 買盤量
TAc As Long ' 賣盤量
FutureOI As Long ' 期貨未平倉 OI
TQty As Long ' 單量
YQty As Long
Up As Long ' 漲停
Down As Long ' 跌停
End Type
Type TTick
Ptr As Long
Time As Long
Bid As Long
Ask As Long
Close As Long
Qty As Long
End Type
Type TBest5
Bid1 As Long
BidQty1 As Long
Bid2 As Long
BidQty2 As Long
Bid3 As Long
BidQty3 As Long
Bid4 As Long
BidQty4 As Long
Bid5 As Long
BidQty5 As Long
ExtendBid As Long
ExtendBidQty As Long
Ask1 As Long
AskQty1 As Long
Ask2 As Long
AskQty2 As Long
Ask3 As Long
AskQty3 As Long
Ask4 As Long
AskQty4 As Long
Ask5 As Long
AskQty5 As Long
ExtendAsk As Long
ExtendAskQty As Long
End Type
Public Function Login(ByVal AcNo As String, ByVal Pwd As String) As Integer
Dim Status As Long
Status = Status + SKQuoteLib_Initialize(AcNo, Pwd)
Status = Status + SKQuoteLib_AttachConnectionCallBack(AddressOf OnConnectionBack)
Status = Status + SKQuoteLib_AttachQuoteCallBack(AddressOf OnQuoteCallBack)
'Status = Status + SKQuoteLib_AttachTicksCallBack(AddressOf OnTicks)
'Status = Status + SKQuoteLib_AttachBest5CallBack(AddressOf OnBest5)
If Status = 0 Then
Status = SKQuoteLib_EnterMonitor()
Login = 0
Else
Login = -1
End If
End Function
Sub OnConnectionBack(ByVal Kind As Long, ByVal Code As Long)
If Code = 0 Then
MsgBox "報價伺服器登入成功!!"
Else
MsgBox "報價中斷!!"
UserForm1.Show
End If
End Sub
Sub OnQuoteCallBack(ByVal Market As Integer, ByVal Index As Integer)
On Error Resume Next
Dim Status As Long, Stock As TStock, ComId As String, Dot As Integer
Status = SKQuoteLib_GetStockByIndex(Market, Index, Stock)
ComId = Replace(Stock.StockNo, Chr(160), "")
Dot = 10 ^ Stock.Decimal
Dim i As Integer, N As Integer, ComIds As String
N = Sheet1.Cells(2, 3).Value
For i = 4 To N + 3
If ComId = Sheet1.Cells(i, 1).Value Then
With Sheet1
.Cells(i, 2).Value = Stock.Bid / Dot
.Cells(i, 3).Value = Stock.Bc
.Cells(i, 4).Value = Stock.Ask / Dot
.Cells(i, 5).Value = Stock.Ac
.Cells(i, 6).Value = Stock.Close / Dot
.Cells(i, 9).Value = Stock.TickQty
.Cells(i, 10).Value = Stock.TQty
.Cells(i, 11).Value = Stock.High / Dot
.Cells(i, 12).Value = Stock.Low / Dot
.Cells(i, 13).Value = Stock.Ref / Dot
End With
Exit For
End If
Next i
End Sub
Sub OnTicks(ByVal MarketNo As Integer, ByVal Index As Integer, ByVal Ptr As Long)
'Dim Tick As TTick
'If Form1.Check2.Value = 1 Then
' If Form1.List2.ListCount > 2000 Then
' Form1.List2.Clear
' End If
' Form1.List2.AddItem ("Ptr: " + Str(Tick.Ptr) _
' + " Time: " + Str(Tick.Time) _
' + " Bid: " + Str(Tick.Bid) _
' + " ASK: " + Str(Tick.Ask) _
' + " Close: " + Str(Tick.Close) _
' + " Qty" + Str(Tick.Qty))
' Form1.List2.ListIndex = Form1.List2.ListCount - 1
'End If
'Status = SKQuoteLib_GetTick(MarketNo, Index, Ptr, Tick)
'Sheet1.Cells(3, 1).Value = "Ptr: " + Str(Tick.Ptr)
'Sheet1.Cells(3, 2).Value = "Time: " + Str(Tick.Time)
'Sheet1.Cells(3, 3).Value = "Bid: " + Str(Tick.Bid)
'Sheet1.Cells(3, 4).Value = "ASK: " + Str(Tick.Ask)
'Sheet1.Cells(3, 5).Value = "Close: " + Str(Tick.Close)
'Sheet1.Cells(3, 6).Value = "Qty" + Str(Tick.Qty)
End Sub
Sub OnBest5(ByVal MarketNo As Integer, ByVal Index As Integer)
'Dim Best5 As TBest5
'If Form1.Check3.Value = 1 Then
' If Form1.List3.ListCount > 2000 Then
' Form1.List3.Clear
' End If
' Status = SKQuoteLib_GetBest5(MarketNo, Index, Best5)
' Form1.List3.AddItem ( _
"Bid 1: " + Str(Best5.Bid1) + " Qty: " + Str(Best5.BidQty1) _
+ "Bid 2: " + Str(Best5.Bid2) + " Qty: " + Str(Best5.BidQty2) _
+ "Bid 3: " + Str(Best5.Bid3) + " Qty: " + Str(Best5.BidQty3) _
+ "Bid 4: " + Str(Best5.Bid4) + " Qty: " + Str(Best5.BidQty4) _
+ "Bid 5: " + Str(Best5.Bid5) + " Qty: " + Str(Best5.BidQty5))
' Form1.List3.AddItem ( _
"Ask 1: " + Str(Best5.Ask1) + " Qty: " + Str(Best5.AskQty1) _
+ "Ask 2: " + Str(Best5.Ask2) + " Qty: " + Str(Best5.AskQty2) _
+ "Ask 3: " + Str(Best5.Ask3) + " Qty: " + Str(Best5.AskQty3) _
+ "Ask 4: " + Str(Best5.Ask4) + " Qty: " + Str(Best5.AskQty4) _
+ "Ask 5: " + Str(Best5.Ask5) + " Qty: " + Str(Best5.AskQty5))
' Form1.List3.AddItem ("Extend Bid: " + Str(Best5.ExtendBid) + " Qty: " + Str(Best5.ExtendBidQty))
' Form1.List3.AddItem ("Extend Ask: " + Str(Best5.ExtendAsk) + " Qty: " + Str(Best5.ExtendAskQty))
' Form1.List3.ListIndex = Form1.List3.ListCount - 1
'End If
End Sub
以上是 群益API 放在 EXCEL 的 Visual Basic 程式
可否 直接寫到 xDDESrv 裡面?
登入 帳號、密碼,啟動 接收數據? |