COCO研究院

 找回密碼
 註冊
搜索
查看: 3199|回復: 9

[EXCEL] 有用過群益API的大大知道怎麼解決這個問題嗎??

[複製鏈接]
發表於 13-3-13 11:57 | 顯示全部樓層 |閱讀模式
有用過群益API的大大知道怎麼解決這個問題嗎??
這是群益下載的範例檔,我登入了,但他會出現那個錯誤訊息,求大大幫幫我吧
登入錯誤.jpg
登入.jpg
發表於 13-3-13 12:08 | 顯示全部樓層
群益API 中 有一 SKQuoteLib.dll
將其放在跟範例檔 同一目錄內 (或是指定的路徑)
 樓主| 發表於 13-3-13 12:10 | 顯示全部樓層
acerman 發表於 13-3-13 12:08
群益API 中 有一 SKQuoteLib.dll
將其放在跟範例檔 同一目錄內 (或是指定的路徑) ...

同一個路徑指的是??
 樓主| 發表於 13-3-13 12:10 | 顯示全部樓層
acerman 發表於 13-3-13 12:08
群益API 中 有一 SKQuoteLib.dll
將其放在跟範例檔 同一目錄內 (或是指定的路徑) ...

大大可以再說明白一點嗎??
發表於 13-3-13 12:29 | 顯示全部樓層
獨孤求勝 發表於 13-3-13 12:10
大大可以再說明白一點嗎??

放在和excel範例檔同一個目錄
 樓主| 發表於 13-3-13 12:37 | 顯示全部樓層
comewish 發表於 13-3-13 12:29
放在和excel範例檔同一個目錄

大大謝謝你,成功了,但現在他不會接收報價ㄟ,要怎麼讓他接收報價
 樓主| 發表於 13-3-13 12:41 | 顯示全部樓層
comewish 發表於 13-3-13 12:29
放在和excel範例檔同一個目錄

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

這個程式要修改才能接收報價嗎??
發表於 13-3-13 21:15 | 顯示全部樓層
程式應該是不用改,你檢查一下商品代號是不是正確的,例子中的商品代號應該已經過期了
發表於 13-3-15 13:28 | 顯示全部樓層
獨孤求勝 發表於 13-3-13 12:41
Option Explicit
Declare Function SKQuoteLib_Initialize Lib "SKQuoteLib.dll" (ByVal strID As String ...

修改一個地方試試看
在 SubOnQuoteCallBack(ByVal Market As Integer, ByVal Index As Integer) 內,
把下面這個程式碼
ComId =Replace(Stock.StockNo, Chr(160), "")
改成
ComId =WorksheetFunction.Substitute(Stock.StockNo, Chr(160), "")
然後…..
Good Luck !
 樓主| 發表於 13-3-15 13:29 | 顯示全部樓層
ethanliang 發表於 13-3-15 13:28
修改一個地方試試看在 SubOnQuoteCallBack(ByVal Market As Integer, ByVal Index As Integer) 內,把下 ...

謝謝大大我試試看可不可以
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-11-25 02:50

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |