無無明 發表於 12-1-6 11:35

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 裡面?
登入 帳號、密碼,啟動 接收數據?

無無明 發表於 12-1-6 11:36

用 EXCEL 登入 在轉接到 xDDESrv 效率明顯降低很多

meimeichen 發表於 12-1-6 13:57

回復 32# 無無明


無大都說話了 當然可以
因為API 都長得差不多
只是我沒有群X的測試帳號可以使用,比較傷腦筋。

kilroy 發表於 12-1-6 14:04

回復無無明


無大都說話了 當然可以
因為API 都長得差不多
只是我沒有群X的測試帳號可以使用,比較傷腦 ...
meimeichen 發表於 12-1-6 01:57 PM http://coco-in.net/images/common/back.gif


    大大真是太讚了,群益還有一個海外報價的API

    一起寫進去啦⊙▽⊙

meimeichen 發表於 12-1-6 14:10

回復 34# kilroy

我手上只有 別人寫的 群益報價API沒有相關文件


http://www.capital.com.tw/Service2/Download/api.asp


把資料壓縮給我吧

我沒有 群益的帳號 不能下載元件說明檔

kilroy 發表於 12-1-6 15:09

回復kilroy

我手上只有 別人寫的 群益報價API沒有相關文件


http://www.capital.com.tw/Service2/Dow ...
meimeichen 發表於 12-1-6 02:10 PM http://www.coco-in.net/images/common/back.gif


   Hi 大大 如附件
   感動~~

   

meimeichen 發表於 12-1-8 19:47

被打槍了, 居然是用 Delphi 搞得咚咚,好些人用C#搞得暈頭轉向,還不支援我的 X64 實在有夠傷腦筋{:7_447:}
文件看了之後,對網路上所有寫群益API中槍哀號的人,感同身受,您們的哀號,好像都沒有被重視{:7_468:},到今天還不出C#版的API給大家轉用就好了。

山不轉路轉,搬出Delphi老傢伙來,省點工 直接偷雞好了,小改一下畫面 重新編譯看能不能正常執行,如果運作正常,就給他轉成UDP 廣播到區網,用網路接收機接收好了,不然我沒有群益的帳號,要測試也滿麻煩的咧。


tpkpm 發表於 12-1-8 20:04

本帖最後由 tpkpm 於 12-1-8 08:12 PM 編輯

回復 37# meimeichen

群益策略王本身就是 delphi 寫的
API 當然也就是 delphi
你沒看到他的價格還得用整數 / 小數位數 才能得到正確植
怕微軟浮點格式編碼 和 他的不一樣 (至少早期就是不一樣)
它的沒落在於選錯語言, 若選C 現在絕對不需要賣給別人

Android 發表於 12-1-8 22:43

本帖最後由 Android 於 12-1-8 10:57 PM 編輯

回復 37# meimeichen


   這個給妳參考,希望有幫助
ConnectionCallBack策略王報價函式庫使用說版本 2.2.4

...自刪。
沒注意看附件CapitalApi.zip裡已有。

meimeichen 發表於 12-1-10 12:47

寶來版XddeSvr 小修正

修改 Threading Idle降低 CPU 負擔增加 DDE 連接欄位 開盤前就可以開始看到 BID ASK 委掛口數  我上周才發現 真{:7_405:}



群益API 我的電腦跟我鬧彆扭,等我拿到真實群益帳號,再來處理...

moneymaker 發表於 12-1-10 13:57

感謝MEIMEI的善心 捧場是一定要的..{:4_153:}

stupidkuei 發表於 12-1-10 14:17

感謝分享

不過我打開的時候好像會發生錯誤也

meimeichen 發表於 12-1-10 14:32

回復 42# stupidkuei


   ? 甚麼樣的錯誤 可以跟我說一下嗎?

usana642 發表於 12-1-10 22:42

萬用dde真的很實用,謝謝大大分享 ~

kuli 發表於 12-1-13 10:59

謝謝 meimeichen 大大分享。真快樂 :)
頁: 1 2 [3] 4 5 6 7 8 9 10 11 12
查看完整版本: 萬用xDDESvr Beta 版釋出