Skip to main content

台湾金融家(Netstock)提供的台股报价API

Project description

PyNetstockQuoteLib簡介

一款臺灣金融市場的證券,期貨,期權多合一的輕量級報價API模塊,由臺灣Netstock公司開發,做到極致化的高效和輕量級。整包大小僅有不到200kb。

安裝方法:pip install PyNetstockQuoteLib
申請賬號請訪問公司網站:https://www.netstock.net/
電話:+886-2-25775688
地址:臺灣臺北市松山區105敦化南路一段21號2樓

函數列表:

1,連接
def Connect(Address: str, nPort: unsigned short)-> bool: ...
2,斷開連接
def Disconnect() -> None: ...
3,登錄
def Login(UserName: str, Password: str, Software: str, Version: str, Company: str, Branch: str) -> None: ...
4,運行阻塞函數
def Go() -> None: ...
5,注冊報價函數
def SubscribeToQuote(Symbol: str, Exc: int, sExc: int = -1, rlot:bool = False) -> int: ...
6,關閉注冊報價
def CloseSubscribe(Index: int) -> bool: ...
7,注冊Tick函數
def SubscribeToTick(Symbol: str, Exc: int, sExc: int = -1, rlot:bool = False) -> int: ...
8,獲得報價
def GetQuote(Index: int, Field: int) -> int | float: ...
9,獲得Tick數據
def GetTick(Index:int)-> List[Dict[str, Union[int, float]]]: ...
10,獲得基本資料(9-16)
def GetInfo(Exc:int, Symbol:str, Field:str, sExc:int)-> str: ...
11,設置主動回報callback
def SetNoticeCallback(callback: Callable[[int, int, object, int], None]) -> None: ...
12,設置登錄回報函數
def SetLoginCallback(callback: Callable[[int, str, int], None]) -> None: ...
13,設置交易日資訊回報函數
def SetExcInfoCallback(callback: Callable[[int, int], None]) -> None: ...
14,設置基本資料更新回報函數
def SetStkiCallback(callback: Callable[[int, int, int], None]) -> None: ...
15,設置報價回報callback
def SetQuoteCallback(callback: Callable[[int, int], None]) -> None: ...
16,設置Tick回報函數
def SetTickCallback(callback: Callable[[int], None]) -> None: ...

示例1:Quote.py

import PyNetstockQuoteLib as NsQuote

Ind = 0
Ind1 = 0
#登錄回報
def OnLogin(Type,pInfo,InfoSize):
    if(Type == NsQuote.SMSGL_LOGIN_OKAY):
        global Ind,Ind1
        print("登錄成功!")
        #登錄成功后對商品進行報價訂閱
        Ind = NsQuote.SubscribeToQuote("FITX",NsQuote.EXC_FITXN,NsQuote.EXC_FITX_T2)
        Ind1 = NsQuote.SubscribeToQuote("2330",NsQuote.EXC_STOCK)
    else:
        print("登錄失敗")        
#報價回報
def OnQuote(Index,Type):
    if(Type == 1):
        global Ind,Ind1
        if(Index == Ind):
            print("Sym:FITX,Name:" + NsQuote.GetInfo(NsQuote.EXC_FITXN,"FITX","name") +
                  "," + NsQuote.SYM_GLOBAL_DESC[NsQuote.SYM_LAST] +":" +
                  str(NsQuote.GetQuote(Index,NsQuote.SYM_LAST)) + 
                  "," + NsQuote.SYM_GLOBAL_DESC[NsQuote.SYM_VOLUME] +":" +
                  str(NsQuote.GetQuote(Index,NsQuote.SYM_VOLUME)))
        if(Index == Ind1):
            print("Sym:2330,Last:" + str(NsQuote.GetQuote(Index,NsQuote.SYM_LAST)) + 
                  ",Vol:" + str(NsQuote.GetQuote(Index,NsQuote.SYM_VOLUME)))

#啟動入口
if NsQuote.Connect():
    print("連接成功")
    NsQuote.SetLoginCallback(OnLogin)
    NsQuote.SetQuoteCallback(OnQuote)
    NsQuote.Login("xxxxx", "xxxxx")
    NsQuote.Go()
else:
    print("連接失敗")
print("Over")

示例2:Tick.py

import PyNetstockQuoteLib as NsQuote

indTick = 0
#登錄回報
def OnLogin(Type,pInfo,InfoSize):
    if(Type == NsQuote.SMSGL_LOGIN_OKAY):
        print("登錄成功!")
    else:
        print("登錄失敗")        
#Tick回報
def OnTick(Index):
    #獲得Tick數據,返回字典列表迭代器
    TickList = NsQuote.GetTick(Index)
    #獲得Tick總數
    Ticklen = len(TickList)
    count = 0
    #用基本資料獲取商品名稱
    print(NsQuote.GetInfo(NsQuote.EXC_FITXN,"FITX","name"))
    #顯示本次Tick信息
    print("Index:" + str(Index) + " TickCount:",str(Ticklen))
    #顯示10條數據用于測試
    for Item in TickList:
        print(Item)#Item是字典對象,實際使用時可以用Key取單元數據例如:Item["Last"]
        count = count + 1
        if (count >=10): break
#交易日資訊回報
def OnExcInfo(Type,Exc):
    if(Exc == NsQuote.EXC_FITXN):#收到對應市場交易日資訊后注冊(較為單純)
        global indTick
        indTick = NsQuote.SubscribeToTick("FITX",NsQuote.EXC_FITXN,NsQuote.EXC_FITX_T2)
#程序入口
if NsQuote.Connect():
    print("連接成功")
    NsQuote.SetLoginCallback(OnLogin)
    NsQuote.SetExcInfoCallback(OnExcInfo)
    NsQuote.SetTickCallback(OnTick)
    NsQuote.Login("xxxxx", "xxxxx")
    NsQuote.Go()
else:
    print("連接失敗")
print("Over")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynetstockquotelib-1.0.8.tar.gz (187.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynetstockquotelib-1.0.8-py3-none-any.whl (185.2 kB view details)

Uploaded Python 3

File details

Details for the file pynetstockquotelib-1.0.8.tar.gz.

File metadata

  • Download URL: pynetstockquotelib-1.0.8.tar.gz
  • Upload date:
  • Size: 187.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for pynetstockquotelib-1.0.8.tar.gz
Algorithm Hash digest
SHA256 a2a8f5f99ef268a87cce1ea7a8aee1c2fbfc356efe0928737bc5621b134bad8a
MD5 8d76f8a517e60a66e450caf2ffcfeb99
BLAKE2b-256 340c2ec75269499fe487376f5d47c6b6d91090a3ec24380c85531c5e7ea73e3b

See more details on using hashes here.

File details

Details for the file pynetstockquotelib-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pynetstockquotelib-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee6d3876180ac0adefda3b1120861ede5bf0414d84d5b439a8bb4ba323163ef
MD5 b0061346e0167f280521b73137e68365
BLAKE2b-256 6412191c11a95eff73a2dbaf72491ce130853bfdf2129ade2b3d63208638a853

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page