量化交易軟件:赫茲量化系統(tǒng)市場深度及其抽象請求思考
概述
在本文中,我將著手實現(xiàn)操控市場深度的功能。 從概念上講,操控 DOM 的類與以前實現(xiàn)的所有函數(shù)庫類都沒啥區(qū)別。 與此同時,我們將擁有一個 DOM 特征數(shù)據(jù)的模型,其中包含 DOM 中存儲的有關訂單數(shù)據(jù)信息。激活 OnBookEvent() 處理程序時,可由 MarketBookGet() 函數(shù)獲取數(shù)據(jù)。 在 DOM 發(fā)生任何變化的情況下,處理程序中會為訂閱 DOM 事件的每個品種激活一個事件。
市場深度中的抽象訂單對象類
與所有函數(shù)庫對象一樣,定義對象屬性常量均有相應的枚舉集合,我們也需要為 DOM 訂單創(chuàng)建整數(shù)型、實數(shù)型和字符串型對象屬性的枚舉。
在 \MQL5\Include\DoEasy\Defines.mqh 以下位置添加 DOM 訂單對象屬性和參數(shù)的枚舉。 鑒于我不打算實現(xiàn)處理每個 DOM 訂單的事件模型(在某時刻,訂單簿會顯示所有訂單的當前狀態(tài),它們的變化會引發(fā)下一個狀態(tài),并在下次激活 OnBookEvent() 時處理,只需在 DOM 事件的最后一個代碼之后添加指定下一個事件的代碼常量即可,如此只需維護所有對象的常量標識,令它們具有相同的形式即可:
//+------------------------------------------------------------------+ //| Data for working with DOM ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| List of possible DOM events ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ #define MBOOK_ORD_EVENTS_NEXT_CODE ?(SERIES_EVENTS_NEXT_CODE+1) ? // The code of the next event after the last DOM event code //+------------------------------------------------------------------+
定義枚舉指定單個 DOM 訂單的兩種可能狀態(tài) — 買方或賣方:
//+------------------------------------------------------------------+ //| Abstract DOM type (status) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ enum ENUM_MBOOK_ORD_STATUS ?{ ? MBOOK_ORD_STATUS_BUY, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Buy side ? MBOOK_ORD_STATUS_SELL, ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Sell side ?}; //+------------------------------------------------------------------+
依據(jù)這些屬性針對 DOM 的所有訂單進行分類,可令我們快速選擇屬于需求方或供應方的所有 DOM 訂單。
接下來,添加 DOM 訂單對象的整數(shù)型、實數(shù)型和字符串型屬性的枚舉:
//+------------------------------------------------------------------+ //| Integer properties of DOM order ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ enum ENUM_MBOOK_ORD_PROP_INTEGER ?{ ? MBOOK_ORD_PROP_STATUS = 0, ? ? ? ? ? ? ? ? ? ? ? ? // Order status ? MBOOK_ORD_PROP_TYPE, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Order type ? MBOOK_ORD_PROP_VOLUME, ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Order volume ?}; #define MBOOK_ORD_PROP_INTEGER_TOTAL (3) ? ? ? ? ? ? ?// Total number of integer properties #define MBOOK_ORD_PROP_INTEGER_SKIP ?(0) ? ? ? ? ? ? ?// Number of integer DOM properties not used in sorting //+------------------------------------------------------------------+ //| Real properties of DOM order ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ enum ENUM_MBOOK_ORD_PROP_DOUBLE ?{ ? MBOOK_ORD_PROP_PRICE = MBOOK_ORD_PROP_INTEGER_TOTAL, // Order price ? MBOOK_ORD_PROP_VOLUME_REAL, ? ? ? ? ? ? ? ? ? ? ? ?// Extended accuracy order volume ?}; #define MBOOK_ORD_PROP_DOUBLE_TOTAL ?(2) ? ? ? ? ? ? ?// Total number of real properties #define MBOOK_ORD_PROP_DOUBLE_SKIP ? (0) ? ? ? ? ? ? ?// Number of real properties not used in sorting //+------------------------------------------------------------------+ //| String properties of DOM order ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ enum ENUM_MBOOK_ORD_PROP_STRING ?{ ? MBOOK_ORD_PROP_SYMBOL = (MBOOK_ORD_PROP_INTEGER_TOTAL+MBOOK_ORD_PROP_DOUBLE_TOTAL), // Order symbol name ?}; #define MBOOK_ORD_PROP_STRING_TOTAL ?(1) ? ? ? ? ? ? ?// Total number of string properties //+------------------------------------------------------------------+