2023/06/12

Shioaji 篩選 目前週選的TX代號

 現在選擇權代號通常會有當週,下週,跟月選3個合約,如果現在是第一週,就是有TX1,TX2,TXO,三個。只有第三週是2個(TXO跟TX4)。

目前的python語法裡TX是寫死的,每周要自己手動改,有點煩,所以就想了一個動判斷的語法,來抓今天是該是TX幾。

主要就是判斷連續兩週的合約有沒有值,如果都有的話,那TX就是比較小的那個。

像是TX1跟TX2都有值,那今天就會是TX1。

第三週因為是抓TXO跟TX4,但第四週也會有TXO跟TX4,所以這一個判斷要放在最後面才行,不然第四週會被先判斷成是TXO。

#抓當週的週選的TX代號
if api.Contracts.Options['TX1'] != None and api.Contracts.Options['TX2'] != None:
    TX = 'TX1'
    print(api.Contracts.Options[TX])
elif api.Contracts.Options['TX2'] != None and api.Contracts.Options['TXO'] != None:
    TX = 'TX2'
    print(api.Contracts.Options[TX])
elif api.Contracts.Options['TX4'] != None and api.Contracts.Options['TX1'] != None:
    TX = 'TX4'
    print(api.Contracts.Options[TX])
elif api.Contracts.Options['TX4'] != None and api.Contracts.Options['TX5'] != None:
    TX = 'TX4'
    print(api.Contracts.Options[TX])
elif api.Contracts.Options['TX5'] != None and api.Contracts.Options['TX1'] != None:
    TX = 'TX5'
    print(api.Contracts.Options[TX])
elif api.Contracts.Options['TXO'] != None and    api.Contracts.Options['TX4'] != None:
    TX = 'TXO'
    print(api.Contracts.Options[TX])

2023/06/04

FreeFileSync 同步檔案時出現 sync.ffs_lock的相關錯誤 code error 5: Access refuse [create file]

 在win2019透過freefilesync要把遠端win2003的檔案同步過來本機的時後,有些資料夾都會出現錯誤,內容都是在本機端的資料夾中 sync.ffs_lock有錯誤, code error 5: Access refuse [create file]。

照字面上的意思應該就是同步的過程程式要產生一個sync檔,但無法建立。

可是我在本機端自己建立檔案時,都沒什麼異狀,就覺得很怪。

後來就手動用複製貼上檔案的方式,發現有時後會跳出錯誤訊息,大概就是說沒有權限,要用系統管理者執行之類的,可是我就是用本機管理者帳號在執行啊。

這時突然想到,那執行freefilesync時,要用系統管理者身份去執行,有三四個在同步會跳錯誤的資料夾,就通通都沒問題了。


When using FreeFileSync on Windows Server 2019 to sync files from a remote Windows Server 2003 to the local machine, some folders encounter errors. The error message states that there is an issue with the "sync.ffs_lock" file in the local folder, with error code 5: Access refused [create file].

According to the literal meaning of the error, it seems that the sync process is unable to create the "sync" file.

However, I noticed that there were no issues when manually creating files on the local machine, which struck me as odd.

Later, while manually copying and pasting files, I encountered occasional error messages indicating a lack of permission and suggesting the need for administrator privileges. However, I was already using the local administrator account to perform the operation.

At this point, it occurred to me that when running FreeFileSync, it should be executed with administrator privileges. When I ran the program as an administrator, the folders that were previously causing errors during synchronization, about three or four of them, synced without any problems.

2023/06/02

pyinstaller py轉exe出現錯誤:The 'pathlib' package is an obsolete

 在用pyinstaller把一個py檔要轉成exe執行檔時,出現下列錯誤

The 'pathlib' package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please remove this package (located in C:\Users\helloeveryone\Anaconda3\lib\site-packages) using  conda remove then try again.

這時就執行 pip uninstall pathlib ,把pathlib移除就好,移除後不需要再重裝一次。

之後執行pyinstaller,就可以成功把py轉成exe了。



When using PyInstaller to convert a .py file into an executable (.exe) file, the following error occurs:

"The 'pathlib' package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please remove this package (located in C:\Users\helloeveryone\Anaconda3\lib\site-packages) using conda remove then try again."

To resolve this, execute "pip uninstall pathlib" to remove the pathlib package. After removing it, there is no need to reinstall it.

Afterward, running PyInstaller should successfully convert the .py file into an .exe file.


2023/06/01

Shioaji 篩選 期貨 日盤的kbars

Shioaji 在撈Kbar資料時,可以指定開始跟結束的"日期",然後就產出這段時間的一分k資料 。

假如是撈期貨的資料,就會把日盤跟夜盤的kbar全部列出來。



如果只想要日盤或夜盤,或是某幾小時內的資料時,就要做個篩選。
篩選的方式就是:
1. 先把dataframe裡的ts欄位設成index
df.set_index('ts',inplace=True) 
2. 在用between_time的功能,選出要的時間區間,就完成了。
df=df.between_time('08:44', '13:46')


可以參 考這篇
https://geek-docs.com/pandas/pandas-dataframe/python-pandas-dataframe-between_time.html





2023/05/31

永豐 e-leader 選擇權搭配autoit 做自動下單平倉 bug

 本來都有設定autoit做收盤前的自動平倉單功能。

昨天並沒開倉下單,所以就算執行了自動平倉也不會生效。

但晚上就發現居然有庫存,autoit的自動平倉居然變成開倉雙買了。

然後還賺了一點錢,好佳在,如果是雙賣就虧慘了。

然後仔細檢查了一下autoit裡面的程式,發現下單的下拉選單(開倉,停損,停利,自動)這個鈕的按鈕參數,在完全沒下過單跟有先下過單(任個一種單因)的狀況下,是不相同的。TR<>裡面那串數字會變動。

ControlCommand("e-Leader - [[6508]多次IOC :(0) TR<540001>]","","ComboBox8","SelectString",'平倉停損')

實在太奇怪了,所以如果沒下單,要把視窗關了,不然到時就會變自動開倉下單了。

2023/05/25

永豐 e-leader 選擇權收盤前搭配autoit 做自動下單平倉

 選擇權下單跟股票或期貨不一樣,沒有當沖這個功能可以選,讓單子可以在收盤自動平倉。

如果想要實現在這功能,就需要搭配autoit這個軟體來實現。

現在就是使用永豐的e-leader裡的組合單操作

1. 假設已手動下好多次IOC的組合單,而且成交了,這時後畫面就會停在原本下單的條件。


2. 這時後就開啟autoit ,設定讓程式自動做下列幾個動作
#第一個是點選"更新",抓到當下的價格
ControlClick("e-Leader","","Scintilla1")
#第二個是選到倉別的下拉選單,選到平倉停損
ControlCommand("e-Leader - [[6508]多次IOC :(0) TR<540001>]","","ComboBox8","SelectString",'平倉停損')
#第三個是下單的下拉選單,選到多次IOC,這個其實不一定要做,因為正常的話這個本來欄位本來就會停在多次IOC的選項
ControlCommand("e-Leader - [[6508]多次IOC :(0) TR<540001>]","","ComboBox7","SelectString",'多次IOC')
#第四個是點選"新增",送出這張停損單。
ControlClick("e-Leader","","Button19")
做好後轉成exe檔。

3. 在工作排程中,設定收盤前一點點的時間執行這個exe檔,為了怕沒成交要讓IOC跑一下,執行時間可能就要設在收盤前的幾十秒就要執行了。

這樣就完成了自動平倉單的設定了,在還沒寫好用shioaji的環境下,就先用autoit來做也是蠻方便的。

autoit的操作方法就自行上網找吧,上面提供的指令,還是要自己在實在時確認一下,會比較保險。



查詢DHCP IP的發送記錄

 如果想查詢近期DHCP server 的IP發送給哪一台主機,可以用下列方式查詢。

先開啟DHCP的管理工具,在server名稱按下滑鼠右鍵,選擇內容。 


接著就可以看到資料庫的路徑,進到該路徑後,就可以看到近期每天DHCP的發送記錄。



To determine which host was assigned a specific IP address by the DHCP server, you can follow these steps:

  1. Open the DHCP management tool.
  2. Right-click on the server name and select "Properties."
  3. In the properties window, you will find the database path.
  4. Navigate to the specified path, and you will be able to view the DHCP lease history for each day.
Note: Please note that the exact steps may vary depending on the DHCP management tool you are using and the version of Windows Server.

2023/05/24

chrome 部署自動清除cookie 設定

透過chrome登入某些網站後,都會產生cookie,下次在登入時,就可以不用輸入帳密就登入了,像是spotify,teams等等的網站。

但有時後卻希望網頁關閉,這些cookie就清除掉,避免下一次登入又自動使用上一次的帳密登入。

chrome的設定裡有一個清除cookie的功能,但這會清除所有的cookie,沒辦法只清除特定網站的cookie,也不太方便。






如果希望某網站的cookie在網頁關閉後清除,其實有另一個地方可以設定。
一律在視窗關閉時清除 Cookie這邊就可以把要自動清除cookie的網站加入就行了。





如果公司裡電腦很多台,要一台一台設定太麻煩了。
可以去下載chrome的adm檔(https://enterprise.google.com/chrome/chrome-browser/#download)
然後在群組原則管理工具中,新建一個gpo,先把chrome的adm新增到系統管理範本中,就可以看到裡面有google chrome的設定可以做部署。
在"將來自相符網址的cookie限制在目前的工作階段中",把網址加入,之後使用者開啟這些網站,只要關掉chrome,cookie就會刪除,不保留。


To enhance and translate the content provided:

When logging into certain websites using Chrome, cookies are generated. These cookies allow subsequent logins without the need to enter the username and password again. Websites like Spotify, Teams, and others utilize this feature.

However, there are times when you may prefer to clear these cookies upon closing the webpages to avoid automatically using the previous login credentials during the next login.

Chrome's settings include a cookie-clearing function, but it clears all cookies and lacks the ability to selectively remove cookies from specific websites, which can be inconvenient.

If you wish to automatically clear cookies from a particular website upon closing the webpage, there is another way to configure this setting. You can choose to "Clear cookies and site data when you quit Chrome" by adding the desired websites to this option.

If there are multiple computers within your company, individually configuring the settings on each one can be tedious. You can download the Chrome ADM template from (https://enterprise.google.com/chrome/chrome-browser/#download).

Next, in the Group Policy Management tool, create a new GPO and add the Chrome ADM file to the Administrative Templates section. This will allow you to see the available Google Chrome settings for deployment.

Under the "Limit cookies from sites that match the following URL" option, add the website URLs. Once users open these websites, closing Chrome will automatically delete the cookies, ensuring they are not retained.




2023/05/15

安裝ocs agent 出現錯誤 api-ms-win-crt-heap-l1-1-0.dll

 64位系統安裝請安裝:

Visual C++ Redistributable for Visual Studio 2015 (Windows 64-bit)

32位系統安裝請安裝:

Visual C++ Redistributable for Visual Studio 2015 (Windows 32-bit)



When installing the OCS agent, an error occurs: api-ms-win-crt-heap-l1-1-0.dll.

For 64-bit systems, please install:

Visual C++ Redistributable for Visual Studio 2015 (Windows 64-bit).

For 32-bit systems, please install:

Visual C++ Redistributable for Visual Studio 2015 (Windows 32-bit).

shioaji 組合單多次IOC大失誤

在shioaji下單的模式中,只有ROD 、FOK、IOC三種。

如果要下組合單,需要使用到多次IOC的話,但shioaji系統內無多次IOC可以直接使用,就必須用迴圈讓系統一直重覆執行IOC,但在執行前,必須先確認庫存是否已有單,有單就表示成交,就不能在繼續跑,不然就可能會一直下單下到滿為止。

所以在下IOC前,有先做檢查庫存,但檢查庫存的功能卻失效,一直下單,還好戶頭裡錢不多,下了10口就停了。

檢查程式才發現,原來是檢查庫存的變數在更外圈的程式中,所以第一次成交後,下單前檢查庫存的變數未更新,還保持是0,所以就繼續下IOC,繼續成交。

在測試多次IOC真的要小心,錢不能放太多,以免不小心就直接被下滿。