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 == 25):
        global Ind,Ind1
        print("登录成功!")
        #登录成功后对商品进行报价订阅
        Ind = NsQuote.SubscribeToQuote("FITX",12,2)
        Ind1 = NsQuote.SubscribeToQuote("2330",1)
    else:
        print("登录失败")        
#报价回报
def OnQuote(Index,Type):
    if(Type == 1):
        global Ind,Ind1
        if(Index == Ind):
            print("Sym:FITX,Last:" + str(NsQuote.GetQuote(Index,4)) + ",Vol:" + str(NsQuote.GetQuote(Index,8)))
        if(Index == Ind1):
            print("Sym:2330,Last:" + str(NsQuote.GetQuote(Index,4)) + ",Vol:" + str(NsQuote.GetQuote(Index,8)))

#启动入口
if NsQuote.Connect("www.netstock.net", 000):
    print("连接成功")
    NsQuote.SetLoginCallback(OnLogin)
    NsQuote.SetQuoteCallback(OnQuote)
    NsQuote.Login("xxxxx", "xxxxx", "csxxx", "0.0", "SNxx", "")
    NsQuote.Go()
else:
    print("连接失败")
print("Over")

示例2:Tick.py

import PyNetstockQuoteLib as NsQuote

indTick = 0
#登录回报
def OnLogin(Type,pInfo,InfoSize):
    if(Type == 25):
        print("登录成功!")
    else:
        print("登录失败")        
#Tick回报
def OnTick(Index):
    #获得Tick数据,返回字典列表迭代器
    TickList = NsQuote.GetTick(Index)
    #获得Tick总数
    Ticklen = len(TickList)
    count = 0
    #用基本资料获取商品名称
    print(NsQuote.GetInfo(12,"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 == 12):#收到对应市场交易日资讯后注册(较为单纯)
        global indTick
        indTick = NsQuote.SubscribeToTick("FITX",12,2)
#程序入口
if NsQuote.Connect("www.netstock.net", 000):
    print("连接成功")
    NsQuote.SetLoginCallback(OnLogin)
    NsQuote.SetExcInfoCallback(OnExcInfo)
    NsQuote.SetTickCallback(OnTick)
    NsQuote.Login("xxxxx", "xxxxx", "csxxx", "0.0", "SNxx", "")
    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.4.tar.gz (179.5 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.4-py3-none-any.whl (177.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pynetstockquotelib-1.0.4.tar.gz
  • Upload date:
  • Size: 179.5 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.4.tar.gz
Algorithm Hash digest
SHA256 345a866046ceb8a2a520d0bd5e214ed56010dfedb0ce9bb32df81f4f2392f658
MD5 631431c9fd0c6321c115bfed00e1221f
BLAKE2b-256 79365968296451a1273364d0a8c99f7eba9cda47913159505e4a4d5884e52ba7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pynetstockquotelib-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2679f011486d5b6a6ff04ecc5573179de6f8c661a447bb9b8f419ad51130ec2e
MD5 6f2ecb062a50a98972c8a683354641a8
BLAKE2b-256 8b09144b5d0cdedd6587213b297ef97237e0f9353876ecd036a0f066933f3da4

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