2018年5月1日 星期二
群益api, 模擬平台申請
在群益api附的範例中看到模擬平台的選項,打勾後卻登陸失敗,google 了解後,原來是要先跟群益申請模擬帳號,google "群益 模擬主機"應該就可以看到申請網頁了
https://www.capital.com.tw/Activity/20150128_futures/default.asp
填入資料後,會給一組密碼。下載群益的模擬平台軟體,先登陸後再修改密碼,才能在群益API裡使用。
申請好後
用SKCenterLib_ResetServer,將主機位置改為 morder1.capital.com.tw,即可登陸模擬單伺服器主機
skC.SKCenterLib_ResetServer ("morder1.capital.com.tw")
skC.SKCenterLib_Login(Id, Pw)
目前模擬單主機沒有台指電子盤資訊
模擬帳號3個月以上沒使用,會被刪除,需要重新申請!!!
群益 api 升級後,python comtypes 某些功能無作用
#debug 小記事
我把群益 api 2.13.9 升級成2.13.11 後,python comtypes 某些功能無作用。今天終於發現問題所在:
import comtypes.client as cc
cc.GetModule('C:\SKCOM\x86\SKCOM.dll')
GetModule 這一步會在 comtypes資料夾下自動產生一個 gen 資料夾,裡面有comtypes 生成的 skcom 相關的.py 檔。 第一次呼叫後會再產生一個__pycache__資料夾,並將這些code編譯成 .pyc 檔加速運行速度。
我的comtypes資料夾路徑,給大家參考,可以去相關路徑下找找
Python\Lib\site-packages\comtypes\gen
問題似乎就在這哩,當把api升級後,重新呼叫 GetModule 後,python並沒有重新編譯。因此我把 __pycache__ 裡相關的 .pyc 刪除後,再重新呼叫 GetModule ,新版的 api 就又可以正確執行了。
我把群益 api 2.13.9 升級成2.13.11 後,python comtypes 某些功能無作用。今天終於發現問題所在:
import comtypes.client as cc
cc.GetModule('C:\SKCOM\x86\SKCOM.dll')
GetModule 這一步會在 comtypes資料夾下自動產生一個 gen 資料夾,裡面有comtypes 生成的 skcom 相關的.py 檔。 第一次呼叫後會再產生一個__pycache__資料夾,並將這些code編譯成 .pyc 檔加速運行速度。
我的comtypes資料夾路徑,給大家參考,可以去相關路徑下找找
Python\Lib\site-packages\comtypes\gen
問題似乎就在這哩,當把api升級後,重新呼叫 GetModule 後,python並沒有重新編譯。因此我把 __pycache__ 裡相關的 .pyc 刪除後,再重新呼叫 GetModule ,新版的 api 就又可以正確執行了。
Labels:
沒反應 comtypes,
群益API 更新,
callback 失效,
python
2018年4月6日 星期五
安裝 pytorch
想用 AI 預測走勢,AI模組選了pytorch當作入門,主要是因為他的語法跟python一致,比較容易上手。今天在 windows 安裝了pytorch, 因為沒有nv顯卡,所以選了 cpu 版
這樣就安裝完了
# for CPU only packages
conda install -c peterjc123 pytorch-cpu
然後在python命令列下
import torch
沒有報錯就安裝成功了,繼續練功!
參考:
#pytorch easy installation on windows
#Windows支持Pytorch?如何在windows10中使用Pytorch?
#PyTorch還是TensorFlow?這有一份新手指南
#pytorch.org tutorials
#Neural networks for algorithmic trading. Correct time series forecasting + backtesting
這樣就安裝完了
# for CPU only packages
conda install -c peterjc123 pytorch-cpu
然後在python命令列下
import torch
沒有報錯就安裝成功了,繼續練功!
#pytorch easy installation on windows
#Windows支持Pytorch?如何在windows10中使用Pytorch?
#PyTorch還是TensorFlow?這有一份新手指南
#pytorch.org tutorials
#Neural networks for algorithmic trading. Correct time series forecasting + backtesting
2018年3月7日 星期三
嘗試用 wx, python 實做 群益附的範例 SKCOMtester 的功能
2021 edit: 群益的 python demo 範例已經提供 tkinter 很好的實作範例了
初次使用python GUI, 不太孰悉,未來GUI的layout 應該要單獨一個檔,才會比較好管理,目前已能動為優先。
很多人跟我說 Event 出不來,我覺得有GUI介面的話,很高機率可以解決這個問題!
使用流程,
1. 輸入ID&PW後Login,會等個幾秒,console出現一串錯誤訊息
2. 按 Connect 登錄報價伺服器,當出現 nCode=3003後, 表示完成登錄
3. 在Quote 欄填寫代碼,按下 Request 即可取得報價,預設是取台指近月期貨(TX00)
環境:
WinXP 32 bit, Capital API 2.3.9, python 3.4.3
#demoGUI code
import wx, time import comtypes.client as cc cc.GetModule('C:\\SKCOM\\2.13.9\\x86\\SKCOM.dll') import comtypes.gen.SKCOMLib as sk #Event class class skQ_events: def __init__(self): tc1.write('skQ event class created'+ '\n') def OnConnection(self, nKind, nCode): tc1.write('SKQ_OnConnection, ' + 'nKind= ' + str(nKind) + ', nCode= ' + str(nCode) + '\n') def OnNotifyQuote(self, sMarketNo, sStockIdx): getStock(sMarketNo, sStockIdx, ts) class skR_events: def __init__(self): tc1.write('skR event class created' + '\n') def OnConnect(self, bstrUserID, bstrData): tc1.write(str(bstrUserID) + ", skR_OnConnect" + '\n') def OnComplete(self, bstrUserID): tc1.write('skR OnCompleted' + '\n') def OnSolaceReplyConnection(self, bstrUserID, nErrorCode): tc1.write('skR OnSolaceReplyConnection, ' + str(bstrUserID) + ', nErrorCode= '+ str(nErrorCode) + '\n') #custom functions def getStock(nMarket, nIndex, ts): nCode=skQ.SKQuoteLib_GetStockByIndex(nMarket, nIndex, ts) tc2.write(str(ts.bstrStockNo) + ' ' + str(ts.nClose/10**ts.sDecimal) + '\n') #GUI class Example(wx.Frame): def __init__(self, *args, **kw): super(Example, self).__init__(*args, **kw) self.InitUI() self.CreatSKCOMObject() self.CreatSKCOMEvent() def InitUI(self): pnl = wx.Panel(self) vbox = wx.BoxSizer(wx.VERTICAL) hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox2 = wx.BoxSizer(wx.HORIZONTAL) hbox3 = wx.BoxSizer(wx.HORIZONTAL) #labels st1 = wx.StaticText(pnl, label='ID ') st2 = wx.StaticText(pnl, label='PW ') st3 = wx.StaticText(pnl, label='Quote') #text input self.tcID = wx.TextCtrl(pnl, size=(80, -1)) self.tcPW = wx.TextCtrl(pnl, size=(80, -1), style=wx.TE_PASSWORD) self.tcQuery = wx.TextCtrl(pnl, size=(80, -1), value="TX00") global tc1, tc2 tc1 = wx.TextCtrl(pnl, style=wx.TE_MULTILINE) tc2 = wx.TextCtrl(pnl, style=wx.TE_MULTILINE) self.bt_login = wx.Button(pnl, label='1. Login') self.bt_connect = wx.Button(pnl, label='2. Connect') self.bt_request = wx.Button(pnl, label='3. Request') #layout hbox1.Add(st1, flag=wx.LEFT, border=10) hbox1.Add(self.tcID, flag=wx.LEFT, border=35) hbox1.Add(self.bt_login, flag=wx.LEFT, border=35) hbox1.Add(self.bt_connect, flag=wx.LEFT, border=35) hbox2.Add(st2, flag=wx.LEFT, border=10) hbox2.Add(self.tcPW, flag=wx.LEFT, border=35) hbox3.Add(st3, flag=wx.LEFT, border=10) hbox3.Add(self.tcQuery, flag=wx.LEFT, border=35) hbox3.Add(self.bt_request, flag=wx.LEFT, border=35) vbox.Add(hbox1, flag=wx.TOP, border=10) vbox.Add(hbox2, flag=wx.TOP, border=10) vbox.Add(hbox3, flag=wx.TOP, border=10) vbox.Add(tc1, proportion=1, flag=wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border=15) vbox.Add(tc2, proportion=1, flag=wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border=15) #Set event handlers self.Bind(wx.EVT_BUTTON, self.OnLogin, self.bt_login) self.Bind(wx.EVT_BUTTON, self.OnConnect, self.bt_connect) self.Bind(wx.EVT_BUTTON, self.OnRequest, self.bt_request) pnl.SetSizer(vbox) self.SetSize((400,600)) self.SetTitle('pySKCOMtester') self.Centre() self.Show(True) def CreatSKCOMObject(self): global ts, skC, skQ, skR #股票物件 ts=sk.SKSTOCK() #SKCOM object skC=cc.CreateObject(sk.SKCenterLib,interface=sk.ISKCenterLib) skQ=cc.CreateObject(sk.SKQuoteLib,interface=sk.ISKQuoteLib) skR=cc.CreateObject(sk.SKReplyLib,interface=sk.ISKReplyLib) def CreatSKCOMEvent(self): global EveQ, EveR, ConQ, ConR #instant of event sinks EveQ=skQ_events() EveR=skR_events() #make connection to event sink ConQ = cc.GetEvents(skQ, EveQ) ConR = cc.GetEvents(skR, EveR) #Callback def OnLogin(self, e): ID=self.tcID.GetValue() PW=self.tcPW.GetValue() nCode=skC.SKCenterLib_Login( ID, PW) tc1.write('Login, nCode= ' + str(nCode) + '\n') nCode=skR.SKReplyLib_ConnectByID(ID) tc1.write('skR Connected, nCode= ' + str(nCode) + '\n') e.Skip() def OnConnect(self, e): nCode=skQ.SKQuoteLib_EnterMonitor() tc1.write('skQ EnterMonitor, nCode= ' + str(nCode) + '\n') def OnRequest(self, e): Stocks=self.tcQuery.GetValue() nCode=skQ.SKQuoteLib_RequestStocks(1, Stocks) tc1.write('skQ RequestStocks ' + Stocks + ', nCode= ' + str(nCode[1])+ '\n') e.Skip() def main(): ex = wx.App() Example(None) ex.MainLoop() if __name__ == '__main__': main()
訂閱:
文章 (Atom)

