import time, pythoncom, sys
import comtypes.client as cc
#import skcom package
import comtypes.gen.SKCOMLib as sk
#Create com objects
skC = cc.CreateObject(sk.SKCenterLib, interface=sk.ISKCenterLib)
skO = cc.CreateObject(sk.SKOrderLib,interface=sk.ISKOrderLib)
#Order event handlers
class skO_events:
def __init__(self):
#TXAccount
self.TXAcc=''
def OnFutureRights(self, bstrData):
print(bstrData)
def OnAccount(self, LogInID, AccountData):
if AccountData.split(',')[0]=='TF':
self.TXAcc= AccountData.split(',')[1]+ AccountData.split(',')[3]
print('TXAcc', ID, self.TXAcc)
#implant event instances
EventO=skO_events()
#connect event to com object
EventO_conn=cc.GetEvents(skO,EventO)
#輸入身分證與密碼
ID=''
PW=''
#Login
nCode=skC.SKCenterLib_Login(ID,PW)
print('Login', skC.SKCenterLib_GetReturnCodeMessage(nCode))
#初始 Order 物件
nCode=skO.SKOrderLib_Initialize()
print("Initialize ", skC.SKCenterLib_GetReturnCodeMessage(nCode))
#Get User TF Account
nCode=skO.GetUserAccount()
print("GetUserAccount ", skC.SKCenterLib_GetReturnCodeMessage(nCode))
#GetFutureRights, 不能呼叫太頻繁,不然會出現 SK_ERROR_QUERY_IN_PROCESSING
nCode=skO.GetFutureRights(ID, EventO.TXAcc ,1)
print("GetFutureRights ", skC.SKCenterLib_GetReturnCodeMessage(nCode))
#每秒推一次 event, 推5秒
for i in range(5):
pythoncom.PumpWaitingMessages()
time.sleep(1)
#exit
sys.exit(0)
網頁
▼
2019年6月14日 星期五
GetFutureRight example
示範一下 GetFutureRight 最簡版本