# 永豐金證券 coaching KM ## 注意事項 - 請勿外流連結給公司外的人員 - 有疑問可以登記在問題區 ## 第一週 ### 產品相關 - 主管監控系統 - 監控所有交易員的權證資訊 - `TradeService` - 建立單元測試並重構測試 - 重構 production code - GitLab - create build job - run auto testing - branch: RefactorWithJoey ## 第二週 ### Visual Studio Code - `Ctrl+P`: 用檔名快速以 **Preview Mode** 打開檔案預覽(tab tile 會以 *斜體* 呈現),如需進入編輯模式,請 double click tab title,即可進入編輯模式。Preview Mode 永遠只會有一個 tab。也可以從設定檔設定 disable Preview Mode. - [參考](https://stackoverflow.com/questions/38713405/open-files-always-in-a-new-tab) - `Ctrl+Shift+P`: 快速輸入命令 - language,可設定相關檔案類型要以哪些關聯檔案開啟,例如 .pc 檔可以 .c 檔的形式來編輯,[參考](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_change-language-mode) - `Ctrl+K, Ctrl+F`: 選取內容格式化,格式化完整檔案則是 `Shift+Alt+F` - `Shift+Alt+左右方向鍵`: 區塊選取外擴與內縮 - `Shift+Alt+上下方向鍵`:複製選取區塊,往上或下插入 - `Ctrl+Space`: Intellisense 視窗或選取程式碼後插入 snippet - Custom Snippets: File > Preferences > User Snippets - [參考](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_snippets) - Multi Cursor Selection - `Ctrl+Shift+L`: all occurrences of the current selection - `Ctrl+D`: selects the next occurrence after the one you selected - `Ctrl+L`: Selected current line - `Alt+F12`: peek symbol - `Shift+F12`: peek reference - `F12`: go to definition - `Ctrl+T` or `#`: go to symbol in workspace - `Ctrl+Shift+O` or `@`: go to symbol in file - `@:`: go to and group symbol in file - `Ctrl+.`: quick fix - [得廷] Regular search and replace by `Ctrl+H` - 需求:針對兩種結構 jmmstr, jmsise 的 integer 與 longlong 轉成 string - regex 搜尋出需要調整的結構,並把 longlong 轉成字串,將 `target = source;` 直接再用 regex 取代成 `llongToString(target, sizeof(target), source);`並將修改前的代碼註解掉。 - regex 搜尋出需要的 `sprintf()` 的內容,快速取代成對應的 `llongToString()` - `(`為 x28,`)`為 x29 - 範例 ``` //only focus on jmsise->xxx 或是 jmsise.xxx 或是 jmmstr->xxx 或是 jmmstr.xxx //search pattern: (\S*?)\s*=\s*(jmmstr|jmsise)((->|.)\w.+); //replace pattern: foo($1, sizeof($1), $2$3); ==== tr->a = jmmstr->last; //期望 foo(tr->a, sizeof(tr->a), jmmstr->last); ==== ==== tr->a = jmmstr.last; //期望 foo(tr->a, sizeof(tr->a), jmmstr.last); ==== ==== tr.b = jmsise->first; //期望 foo(tr.b, sizeof(tr.b), jmsise->first); ==== ==== tr->b = jmsise.first; //期望 foo(tr->b, sizeof(tr->b), jmsise.first); ==== ``` - demo 範例 {%youtube TvzbAMgpkyQ %} - [正則表示式規則參考](https://docs.microsoft.com/zh-tw/dotnet/standard/base-types/regular-expression-language-quick-reference) - **Plugins**: - **Clipboard Manager**: 循環剪貼簿,支援filter - **Ftp-Simple** 注意事項:使用 remote workspace 只有 open file 才會實際下載檔案內容,close file 就會再清掉。因此使用 remote workspace 會導致無法針對所有檔案進行 search content/symbol 等指令。建議 download all files/some directionary 到 local 開發,ftp-simple 只用來做下載上傳的動作。 --- - Git for Local version control to avoid problems by SVN with CI/CD - 提前在 UAT End-to-End 驗證逐筆撮合情境,提前發現問題 - Trsrvd (得庭):long long 轉字串的修改,從 sprintf() 改成自訂的 function,如 llongToString(),以因應未來如果這個數字格式再改變時,可以減少修改的範圍。也可以幫助我們快速分辨,如果是 sprintf() 的,代表原本就需要轉字串。如果是 llongToString(),代表是這一次的修改結果。如果仍是 target = source; 代表要留意這一行是否需要調整成 llongToString() - Sol2Shm (Michael):end-to-end 時發現 double 精準度問題,原用 `ceil()` 無條件進位,仍發現有問題,後改回 `round()`。同時利用 test case 來重現問題與修正問題。 - 發現 Client UI 呈現的問題(以畫面8888,最常用的功能當驗收情境) - Cellfmt.txt 裡面 SAL 的設定被手動改過,與 production 版本不符合,期望目前環境設定值 SALL 為 100,但實際設定為 10000,所以UI呈現的值為 1/100。 - Grid 中的報價數字是正確的,但目前程式碼是 hard-code * 100,故 Client UI 屆時需要整理所有 hard-code * 100 之類的內容,改讀設定檔。 - 建議與 concern - Local makefile/build, 加快開發、編譯、驗證的頻率 - 要從 UAT 的 makefile 拉下來,調整成開發機 windows 可以用的版本,或是在開發機與測試機之間的同步、編譯、執行測試能縮到6秒內執行完畢。 - terminal UAT 修改 - 一樣要用 git 進行 local 的版控,應避開在 server 上直接修改程式,以避免成員或專案之間互相影響 - 上版 release to server 除非緊急的 incident,否則都應該透過上版程序,CI 打包,佈署 server。線上 incident 的處理,建議方式為 **hotfix branch** - Branch strategy: [feature branching VS feature toggle](https://devops.com/feature-branching-vs-feature-flags-whats-right-tool-job/) - 建議採 feature flag/toggle,並透過設計(例如 strategy pattern, decorator pattern, factory pattern, adapter/proxy pattern and etc..)或框架(例如 DI framework, middleware/interceptor)來降低 feature toggle 所產生的 if 複雜度問題與維護成本 - 針對逐筆撮合,要有全局的系統需求,透明化已完成的 item, 正在進行的 item,未完成的 item,end-to-end 的情境來校準 item 順序,避免遺漏,方便評估進度、風線,才能因應變化。 - 目前各自管理各自的檔案或 task,看板上的 item 顆粒度較大,無法呈現全貌、進展、瓶頸點 - C/C++ 測試框架方案評估 - UnitTestCpp - 優:過去團隊有使用經驗,輕量化的測試框架 - 缺:作者與相關社群開發人員,已有三四年不再維護,與現行的開發工具整合程度較低 - GoogleTest - 優:業界主流之一,華為/BMW 都使用這,Owner 是 Google,與工具的整合程度較高 - 缺:仍須趕快在某個專案或需求上,確認 GoogleTest 是否符合我們目前 C/C++ 產品的特性 - Visual Studio Code 可搭配 GoogleTest Adapter extension - [Michael] 現況:目前只有自己寫 main() 去呼叫 n 個 test function,透過 print 來看結果。目前的程式異動邏輯簡單,尚能如此進行。未來需要工具能探索測試案例、呈現測試結果與錯誤訊息、執行測試時前後的 event hook、相關的 expected, assertion API,都可以大幅減少重複發明輪子的時間。 - Map struct 傳指標,要留意以 4 bytes 為單位,避免指針記憶體偏移 - [Sky] 新產品或舊產品翻新評估技術方案時,除考量實務業務場景、目前團隊能力外,還需額外考量人力市場上招募的難易度與成本,老舊版本的C與C++,在招募上難度較高,未來可考慮往比較 mordern 且公司內已有產品團隊熟悉的技術,例如 Python, C#(.NET Core), Go,也可讓核心模組、效能處理瓶頸仍透過 C/C++ 處理,但與外部界接溝通則採生產力高、好維護、低成本、容易招募的現代化語言優先。 - [Sky] 減少專人 own 特定產品的情況,增加多人同時 own 多產品的機會,增加彼此交流機會,互補、提昇 domain,避免重複發明輪子、重複踩坑、程式碼一式多份而增加維護上的困難。增加團隊公車指數,會讓團隊更像個團隊,發揮 1+1>2 的綜效。當特定產品突然需要大量開發能量時,整個團隊都可以投入,讓每單位開發能量能產出最大價值,因為平時就已經在互相支援互相 backup 了。 - [燕婷] Project 能在 kickoff 之後產出全局的目標,daily meeting 時重新確認目標是否變化、計畫是否變化、期望是否變化、是否需因應變化做出調整 - Daily meeting 的白板目前透明度仍不夠,反應不出實際大家的工作情況、item/task 的情況 - Fill(or Bill) arguments, mapping source struct to target struct,API設計或實作內容,可以參考 C# 的 [AutoMapper](https://github.com/AutoMapper/AutoMapper) 作法 ## 第三週 (淑芬 team/new web) ### VSCode Vim - [vim setting reference](https://hackmd.io/@Bk3KJ51URzimMkW029jcMg/rku2NPGhr) - easymotion - 快速定位到特定 character 上 - [官網](https://github.com/VSCodeVim/Vim/blob/master/README.md#vim-easymotion) - [自訂 vim key mapping](https://github.com/VSCodeVim/Vim/blob/master/README.md#key-remapping) - Multiple Clipboards for VSCode - merge copy, cycle paste - [官網](https://marketplace.visualstudio.com/items?itemName=slevesque.vscode-multiclip) - surround - 快速在選取範圍前後加上符號或 tag - 針對選取範圍前後的成對符號或 tag 進行修改 - 針對單行前後加上符號或 tag - [官網](https://github.com/tpope/vim-surround) - Todo Tree - 針對 todo 註解 highlight 並呈現在 explorer - [官網](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree) ## 第四週 ### VSCode Extension: TabNine - 強化版的 intellisense, 很適合弱型別、動態型別語言,例如 javascript, python 甚至 C/C++ - [官網](https://tabnine.com/) ### JavaScript Test Framework: Jest - Facebook 推出的 javascript test framework - [官網](https://jestjs.io/docs/en/getting-started) ### WebStorm for Node.js Introduction - [影片](https://www.youtube.com/watch?v=QuZnba9Lk-o) ### Quokkajs - 即時呈現 js 執行結果 - [官網](https://quokkajs.com/) ### Chrome extension: Trello - 快速加入 trello item 與查詢 trello item - [官網](https://chrome.google.com/webstore/detail/trello/dmdidbedhnbabookbkpkgomahnocimke) ### Chrome extension: Kanban WIP for trello - 在 Trello list 上限制 WIP 數量,剛好滿呈現黃色,超過呈現紅色 - [官網](chrome://extensions/?id=oekefjibcnongmmmmkdiofgeppfkmdii) ### AceJump - Visual Studio/JetBrains IDE plugin,實現類似 vim easymotion 的效果 - [Visual Studio 套件 AceJump 官網](https://marketplace.visualstudio.com/items?itemName=jsturtevant.AceJump) - [JetBrains Plugin AceJump 官網](https://plugins.jetbrains.com/plugin/7086-acejump/) ### JavaScript Web Testing Library: Puppeteer - Google 推出的 web testing framework - [GitHub 官網](https://github.com/puppeteer/puppeteer) - [Google Dev 官網](https://developers.google.com/web/tools/puppeteer) - [Puppeteer Examples](https://github.com/checkly/puppeteer-examples) - [用 Puppeteer 實現網路爬蟲 - IT鐵人賽30天文章](https://ithelp.ithome.com.tw/users/20111656/ironman/1676) - [Jest-Puppeteer](https://github.com/smooth-code/jest-puppeteer) ### String format 轉換 (ex: camel to UPPER_SNAKE_CASE) - [string encoding & decoding](https://dencode.com/string) ### 建議 - 前端判斷環境的方式調整 - 目前判斷 domain or url 的方式,應先收斂到統一的 component/module 中,避免各處獨自判斷 - 未來該 module 可透過 ajax request server 獲得環境相關的 config setting,存在 該 component 中,如此一來前後端判斷環境與相關設定值作法就會一致 - 記得前端 request 後端取得的設定值,需把機敏資訊 filter 掉。 - 估算時程的方式 - 先估算下次 sync (例如一週後)時可以完成哪些 feature - 有需要再估算何時可以完整完成(通常不準確,因為有任何變化都會影響到這個時間) - Branch strategy: [feature branching VS feature toggle](https://devops.com/feature-branching-vs-feature-flags-whats-right-tool-job/) - 建議採 feature flag/toggle,並透過設計(例如 strategy pattern, decorator pattern, factory pattern, adapter/proxy pattern and etc..)或框架(例如 DI framework, middleware(http://www.blog.pythonlibrary.org/2016/06/09/python-how-to-create-an-exception-logging-decorator/)/interceptor)來降低 feature toggle 所產生的 if 複雜度問題與維護成本 - 用 map 來取代 `.each()` 中不必要的 N 層 if statement - [ES6, tennis kata 範例](https://www.youtube.com/watch?v=jOw0rmyaCkw) - api version 應該統一一致性,例如都從 v1 開始 - log 蒐集應統一至一個 centralized dashboard 或資料來源(ex: ELK),避免需 remote 至 server 才能查 log - 範圍:針對系統邊界的進出(尤其是 socket/http)、exception 內容紀錄 log - Error handling 機制,紀錄 log 通常只在系統邊界紀錄。需要知道 runtime 的關鍵資訊,應用 try/catch 轉發自訂 exception 附加 runtime 資訊供 error handling 使用 - 紀錄 log 的設計,可採用 Decorator Pattern 來設計 - [Python Decorator 入門教學](https://blog.techbridge.cc/2018/06/15/python-decorator-introduction/) - [Python: How to Create an Exception Logging Decorator](http://www.blog.pythonlibrary.org/2016/06/09/python-how-to-create-an-exception-logging-decorator/) - security design - 對外的 B2B 串接服務,建議只開放白名單 ip 存取 - 避免重送攻擊可以透過 timestamp 設計,搭配 signature 來降低風險([timestamp 參考](https://www.secureblackbox.com/kb/articles/11-TimeStamping.rst) - 使用者登入透過雙重帳戶資訊(例如:帳號+身份證字號),搭配密碼,來避免有心人刻意針對某帳號密碼錯誤次數鎖定帳戶的阻斷使用者服務。(帳號+身份證都是對的,只有密碼是錯的,超過三次才鎖帳號) - 搭配圖片驗證碼或 block 來避免機器人暴力破解(例如輸入帳號密碼錯誤三次時,暫時鎖定 ip 或帳號,五分鐘後自動解鎖) ## 技術 & 工具相關 ### GitKaraken - Git GUI Client - [官網](https://www.gitkraken.com/) - ### 單元測試 - 推薦書籍:[單元測試的藝術](https://www.tenlong.com.tw/products/9789864342471?list_name=srh) - 建議課程:[【針對遺留代碼加入單元測試的藝術】](https://dotblogs.com.tw/hatelove/2019/06/22/unit-testing-effectively-with-legacy-code-202002) ### NUnit - test framework, install from nuget - [官網](https://nunit.org/) ### NUnit 3 Test Adapter - Visual Studio extension, 讓 Visual Studio 可以直接執行 NUnit 測試,並呈現在測試總管視窗中 - [安裝](https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnit3TestAdapter) ### Fluent Assertions - Assertion package, install from Nuget - [官網](https://fluentassertions.com/) ### ReSharper - [下載](https://www.jetbrains.com/resharper/) - Extensions - Presentation Assistant: 呈現 Visual Studio/ReSharper 的操作命令與 shortcut - Configuration Sense: C# 讀取 config 內容,key 的部份支援 intellisense 選取 ### Wox - Windows 生產力工具 - [官網](http://www.wox.one/) - [簡介](https://www.playpcesor.com/2016/08/wox-windows.html) - 好用外掛 - [Everything](https://www.voidtools.com/) - stackoverflow - google search - wiki - Switcheroo - calculator - google translate - yd (有道辭典) - win 視窗選取 - application command - clipboard history ### Vimium - Chrome extension,更方便瀏覽、Navigate、操作網頁 - [官網](https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb) - [簡介](https://sspai.com/post/27723) ### VsVim - Visual Studio extension, 在 Visual Studio 上用 vim 的方式操作 - [官網](https://marketplace.visualstudio.com/items?itemName=JaredParMSFT.VsVim) - [極速開發學員筆記心得](https://dotblogs.com.tw/mystic_pieces/2018/03/03/003303) - 其他 JetBrains IDE 上請裝 [IdeaVim](https://github.com/JetBrains/ideavim) ### 詞彙表 (glossary) | 中文 | 英文, 業界常見縮寫 | 說明 | | ----- | ------------------------ | -- | | 期貨 | Futures | | | 選擇權 | Option | | | 保本型商品 | Equity-Linked Notes, ELN | | | 權證 | Warrant |可分自家權證, 他家權證, 自家權證拿來發行並且造市, 他家權證拿來避險 | |他家權證|Hedge|他家(非永豐金證券)券商發行並造市的權證| |避險|Hedge|當造市中自家權證被成交, 造成偏離擴大, 則需交易股票或他家權證, 期貨, 選擇權來減少偏離的行為, 稱為避險 |股票|Stock|證交所發行的商品| |隱含波動率|Implied Volatility|顯現權證價格的另一種值, 隱含波動率高, 則權證價格也高| |交易員|Trader|永豐發行權證代號的另一種表示法, 長度為3碼, 供後臺辨識(例: 5nr),為唯一值| |商品活單彙總資訊|AliveBook|(例):2330 委買250元個別委買1張, 3張, 成交2張 249元委賣1張, 則AliveBook 2330 250元委買2張, 249元委賣1張| |差額|Balance|(Sum(股票+期貨+他家權證+選擇權+ELN) - 永豐權證)->換算成約當股票N張| |偏離金額|Deviation|差額x股價| |Sorlance|Sorlance|接收與 parsing 交易所的資料成我們想要的struct| |SorToShm|SorToShm|接收 Sorlance 資料,轉成對的格式,存至 share memory| |Trsrvd|Trsrvd|依據 request 情境,讀取對應的 share memory 資料,回傳| |Meow|Meow|Client UI 的 socket 接口,用來跟 hiperT 同步、操作或查詢相關行情資訊與交易| |HiperT|eLeader server對client的socket接口| ### 證券 domain memo - ~~價錢資訊,小數最後一位只會有 .5 或 .0~~ - ## 待辦區 ### 第一周,晴熙 team,主管監控系統 - GitLab build job with specfic branch, including running test with test report - 將主管監控系統,能移動的資料來源從 Presenter 搬至 TradeService 中取 redis 資料 ### 第二周,燕婷, Sky team - Sor2Shm - `指數報價` 目前連線接收資料仍有 timeout 的情況 - [已解決] timeout 原因為接收 message size 量過大,得超過 40 秒才能接收完畢,timeout 設定為 30 秒,所以 timeout。解決方式為切小 message,讓接收能在 30 秒內完成。 - [補充] API 使用時有個設定或參數,是決定 download cache 與訂閱消息,之前設定只有 download cache, 而沒有訂閱消息,所以接收不到訊息 - `暫停交易`、`延後交易` priority 往後延,先全力衝刺交易、行情本身必要的資訊,資料來源也與原本的不同,也需交易所的資料何時會有暫停交易、延後交易(或是怎麼模擬) - Trsrvd - 之前已經修完的程式,使用 sprintf() 的要改回 longlongToString() 的用法 - Solace - 接收資料轉 double 時,可能會讓所有接收端與處理端,都需要留意精準度的問題 - 預計逐筆撮合結束,明年做外期時,會把格式都改回 string,保留交易所過來的原值 - Wox plugin: Everything, 需 admin 權限問題 ## 問題區 範例如下: - 發問人:問題描述、例子、截圖、sample code、連結、期望 - ## Arthur & Michael: - ## 問題描述: ### 1. 如何管理自家套件 (forked from Github),用在專案。 -- ### 2. API文件管理套件推薦, 3rd party 的方式。 -- **期望**: 因目前API docs產生方式為codegen,希望有更好的方式來減少為了產文件對code的限制 -- **sample code** ![](https://i.imgur.com/la55Yg4.png) *@swaggerautoschema* 需依附在每一個API class中的post function 去 generate 文件 ### 3. 如何讓 non-functional requirement 排入開發 (開發方) --