群益API要求報價SKQuoteLib_RequestStocks(intPage, strStock)

Steven Wang
Aug 9, 2017 · 3 min read

前集題要
Login > EnterMonitor>群益主機傳回nkind 3001 3003(3003表示商品下載完成) > 群益主幾乎叫我本地方的onConnection報價事件(別人呼叫的稱為事件)

完成報價事件後>當我要要求報價的時候SKQuoteLib_RequestStocks(intPage, strStock)>需要向群益Server登記說我需要2330的報價>當主機2330有更新的時候>會呼叫onNotifyQuote通知2330報價有更新(並沒有給你更新報價你要自己去取回)>這時用GetStockbyIndex(Index,STSTOCK類別物件)向群益主機取得報價>群益主機傳回報價

STSTOCK物件

呼叫報價
sk.skQ.SKQuoteLib_RequestStocks(intPage, strStock)
#intPage 每一個page最大100檔 Page至多49Page
#strStock 股票代號 可逗點隔開多個代號

Request後>Server每次有報價更新會到 "物件類別模組"內通知呼叫這個事件
skQ_OnNotifyQuote(ByVal sMarketNo As Integer, ByVal sStockIdx As Integer)
#sMarketNo 上市櫃股期分類
#sStockIdx 群益伺服器內的位置編號

事件內取回更新報價資料
定義一個物件Dim stockA As SKCOMLib.SKSTOCK
Call sk.skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockIdx, stockA)

說明
(sMarketNo, sStockIdx, stockA)
sMarketNo 傳值給群益Server
sStockIdx 傳值給群益Server
stockA 傳址給群益Server,由群益Srever傳回報價更新資料到這個位址
放到Excel上的某處ex : sheet1.Cells(intRow, 3).Value = stockA.nClose / 10 ^ stockA.sDecimal (收盤價)

#stockA.nClose / 10 ^ stockA.sDecimal
stockA.nClose傳回整數 在除以stockA.sDecimal 才能避免浮點數的誤差
10 ^ stockA.sDecimal 表示10的幾次方 用來除之前的整數

Steven Wang

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade