十一、 C# 函數庫

11.1 域名 Namespace

MdcCSApi

11.2 MdcSession 連線物件

11.2.1 連線資訊

11.2.1.1 Start 方法

要求物件開始連線登入程序 細節請參 mdca_connection_start,除 Handle 外。

11.2.1.2 Close 方法

要求關閉回收連線 細節請參 mdca_connection_close,除 Handle 外。

11.2.2 行情快照訂閱

11.2.2.1 QuotationSubscribe 方法

訂閱即時行情

函數原型:

void QuotationSubscribe(string Exchange, string[] Commoditys)

參數: Exchange: 查詢交易所 Commoditys: 訂閱商品陣列

例外 (RuntimeErrorException):mdca_quotation_subscribe 的Result 產生例外。

11.2.2.2 QuotationUnsubscribe 方法

解訂閱即時行情

函數原型:

void QuotationUnsubscribe(string Exchange, string[] Commoditys)

參數: Exchange: 查詢交易所 Commoditys: 解訂閱商品陣列

例外 (RuntimeErrorException):mdca_quotation_unsubscribe 的Result 產生例外。

11.2.2.3 QuotationRequest 方法

行情快照查詢

函數原型:

void QuotationRequest (UInt32 RequestId, string Exchange, string[] Commoditys)

參數: RequestId: 查詢識別ID Exchange: 查詢交易所 Commoditys: 查詢商品陣列

例外 (RuntimeErrorException):mdca_quotation_request 的Result 產生例外。

11.2.3 即時與歷史查詢

11.2.3.1 HistoryRequest 方法

歷史資料查詢訂閱

說明: 此呼叫向伺服端要求資料,取得伺服回應時,會從 OnHistoryResponse 中得到一次性完整的資料結構內容。

函數原型:

void HistoryRequest(RequestArgument argument)

參數:

argument: 查詢參數 (參 Mdcs_RequestArgument)

例外 (RuntimeErrorException):mdca_history_request 的Result 產生例外。

11.2.3.2 HistoryUnsubscribe 方法

取消歷史資料訂閱

說明: 此呼叫會解除即時行情的訂閱活動,並回收工作。

函數原型:

void HistoryUnsubscribe(uint RequestId)

參數: RequestId: 查詢唯一識別碼 例外 (RuntimeErrorException):mdca_history_unsubscribe 的Result 產生例外。

11.2.4 事件虛函式

11.2.4.1 OnConnectionState 事件方法

連線狀態事件 細節請參 mdca_listener::connection_state,除 Handle 外。

11.2.4.2 OnQuotationChange 事件方法

初始化快照資料 及 即時行情變動 事件 細節請參 mdca_listener::quotation_change,除 Handle 外。

11.2.4.3 OnHistoryResponse 事件方法

歷史資料查詢訂閱回應 細節請參 mdca_listener::history_response,除 Handle 外。

11.2.4.4 OnQuotationResponse 事件方法

快照行情查詢回傳事件 細節請參 mdca_listener::quotation_response,除 Handle 外。

11.2.4.5 OnCommodityResponse 事件方法

商品資訊查詢回傳事件 細節請參 mdca_listener::commodity_response,除 Handle 外。

11.2.4.6 OnCommodityChange 事件方法

商品資訊變動回傳事件 細節請參 mdca_listener::commodity_change,除 Handle 外。

11.2.4.7 OnContinuousChange 事件方法

連續月資訊變動回傳事件 細節請參 mdca_listener::continuous_change,除 Handle 外。

11.3 MdcToolkit 工具函式物件

11.3.1 價格處理函式

11.3.1.1 PriceString 方法

價格轉換字串

函數原型:

string PriceString(CommodityRoot commodity_root, Commodity commodity, double price)

參數: commodity_root: 商品根物件 commodity: 商品物件 price: 待轉換價格

返回值: 轉換出來的價格字串

例外 (RuntimeErrorException):mdca_price_string 的Result 產生例外。

11.3.1.2 StringPrice 方法

字串轉換為價格

函數原型:

double StringPrice(CommodityRoot commodity_root, Commodity commodity, string price)

參數: commodity_root: 商品根物件 commodity: 商品物件 price: 待轉換價格字串

返回值: 轉換出來的價格 例外 (RuntimeErrorException):mdca_string_price 的Result 產生例外。

11.3.1.3 PricescaleOffset 方法

價格檔位偏移工具

函數原型:

double PricescaleOffset(CommodityRoot commodity_root, Commodity commodity, double price, int tick_offset)

參數: commodity_root: 商品根物件 commodity: 商品物件 price: 待轉換價格字串 tick_offset: 檔位偏移值

返回值: 偏移的價格

例外 (RuntimeErrorException):mdca_pricescale_offset 的Result 產生例外。

11.3.1.4 PricescaleValues 方法

展開價格檔位至價格陣列

函數原型:

double[] PricescaleValues(double lower_limit_price, double upper_limit_price, CommodityRoot commodity_root, Commodity
commodity)

參數: lower_limit_price: 跌停價 (起始展價的價格) upper_limit_price: 跌停價 (起始展價的價格) commodity_root: 商品根物件 commodity: 商品物件

返回值: 價格陣列

例外 (RuntimeErrorException):mdca_pricescale_values 的Result 產生例外。

11.3.1.5 PricescaleStrings 方法

展開價格檔位至字串串列

函數原型:

string[] PricescaleStrings(double lower_limit_price, double upper_limit_price, CommodityRoot commodity_root, Commodity
commodity)

參數: lower_limit_price: 跌停價 (起始展價的價格) upper_limit_price: 跌停價 (起始展價的價格) commodity_root: 商品根物件 commodity: 商品物件

返回值: 價格字串陣列 例外 (RuntimeErrorException):mdca_pricescale_strings 的Result 產生例外。

11.3.1.6 PricescaleDetail 方法

取出價格資訊

函數原型:

void PricescaleDetail(CommodityRoot commodity_root, Commodity commodity, double price, out double integer, out float
numerator, out float denominator, out int numerator_decimal_place, out int denominator_digit_place)

參數: commodity_root: 商品根物件 commodity: 商品物件 price: 價格 integer: 整數 numerator: 分子 denominator: 分母 numerator_decimal_place: 分子小數位數 denominator_digit_place: 分母整數位數 例外 (RuntimeErrorException):mdca_pricescale_detail 的Result 產生例外。

11.4 MdcCommon 通用資訊物件

11.4.1 Version 方法

函數庫相容版本號 細節請參 mdca_version

11.4.2 FileVersion 方法

函數庫相容版本號 細節請參 mdca_file_version

11.4.3 LogFile 方法

設定 Log 檔案路徑及檔名 細節請參 mdca_log_file

11.4.4 FileVersion 方法

函數庫相容版本號 細節請參 mdca_log_flag

11.5 Mdcs_Quotation 商品行情快照物件

物件原型:

class Mdcs_Quotation {
public string Exchange; /* 交易所 */
public string Commodity; /* 商品代碼 */
public UInt32 UniqueID; /*唯一識別ID */
public Mdcs_Quot_Basic Basic; /* 基本資料 */
public Mdcs_Quot_Deal Deal; /* 成交資料 */
public Mdcs_Quot_Depth Depth; /* 委託簿資料 */
public Mdcs_Depth_Detail Depth_Detail; /* 檔位變動資訊 */
}

說明: 當 Depth 沒有變動時,Depth_Detial 將為 NULL,當 Depth 有變動時,Depth_Detail 將提供委買(Bids[])、委賣(Asks[]) 委託簿可視(N 檔) 範圍的價量異動資訊清單。

※ UniqueID 特性請參 附錄二、UniqueID 應用邏輯與特性

11.6 Mdcs_Depth_Detail 檔位變動資訊物件

物件原型:

class Mdcs_Depth_Detail {
public KeyValuePair<double, uint>[] Asks { get; } /* 委賣變動清單 */
public KeyValuePair<double, uint>[] Bids { get; } /* 委買變動清單 */
}

說明: 我們使用了 KeyValuePair 來存下價格(Key)、量(Value)的變動資訊,Bids / Asks 為唯讀陣列,當陣列 Length = 0 時,表示該邊委託不存在異動,反之,存在異動的項目,您可依價格Key)、量(Value) 來維護UI,當量為0 時,該價已移出委託視野或因成交消失。

Last updated