private static _ProductInfo CreateProductInfo(string exchangeName, string dataSource, Product product, AbstractProductProperty property) { _ProductInfo cProductInfo = new _ProductInfo() { CommodityId = (property == null) ? string.Empty : property.CommodityId, Description = (property == null) ? string.Empty : property.Description, DataSource = (dataSource == null) ? string.Empty : dataSource, ExchangeName = exchangeName, ProductId = product.SymbolId, ProductName = product.SymbolName }; return cProductInfo; }
internal void Remove(Product product) { string sSymbolId = product.SymbolId; lock (__cKeys) { if (__cKeys.Contains(sSymbolId)) { ESymbolCategory cType = product.Category; List<string> cList = null; if (__cClassify.TryGetValue(cType, out cList)) { cList.Remove(sSymbolId); //效率可能會比較慢(考量到股票支數可能不多, 所以還可以接受這樣的效率) } __cKeys.Remove(sSymbolId); } } }
protected override OptionType GetCallOrPut(Product product) { OptionType cOptionType = OptionType.None; if (product.Category == ESymbolCategory.IndexOption || product.Category == ESymbolCategory.StockOption) { string sSymbolId = product.SymbolId; int iEndIndex = sSymbolId.LastIndexOf("."); int iLength = sSymbolId.Length; for (int i = 4; i < iLength; i++) { if (sSymbolId[i] > 'A') { cOptionType = ((sSymbolId[i] == 'C') ? OptionType.Call : (sSymbolId[i] == 'P') ? OptionType.Put : OptionType.None); break; } } } return cOptionType; }
/// <summary> /// 取得商品屬性 /// </summary> /// <param name="product">商品類別</param> /// <returns>返回值:AbstractProductProperty類別</returns> public AbstractProductProperty GetProperty(Product product) { AbstractProductProperty cProperty = null; if (product != null) { lock (__cPropertys) { __cPropertys.TryGetValue(product.SymbolId, out cProperty); if (cProperty == null) { string sCommodity = product.CommodityId; if (sCommodity != null) { __cPropertys.TryGetValue(sCommodity, out cProperty); } } } } return cProperty; }
internal void Add(Product product) { string sSymbolId = product.SymbolId; lock (__cKeys) { if (!__cKeys.Contains(sSymbolId)) { ESymbolCategory cType = product.Category; List<string> cList = null; if (!__cClassify.TryGetValue(cType, out cList)) { cList = new List<string>(); __cClassify.Add(cType, cList); } cList.Add(sSymbolId); __cKeys.Add(sSymbolId); //將分類過的股票加入至 HashSet 避免加入到重複的股票 } } }
internal void SetParameters(string exchangeName, string dataSource, Product product, AbstractProductProperty property) { __sExchangeName = exchangeName; __sDataSource = dataSource; __cProduct = product; __cProperty = property; //設定保證金資訊 sourceCautions = new SimpleBoundList<CautionMoney>(__cProperty.CautionMoneys); sourceCautions.AllowNew = true; sourceCautions.AllowEdit = true; sourceCautions.AllowDelete = true; //設定開收盤時間 sourceSessions = new SimpleBoundList<SessionObject>(__cProperty.Sessions); sourceSessions.AllowNew = true; sourceSessions.AllowEdit = true; sourceSessions.AllowDelete = true; }
private void btnOk_Click(object sender, EventArgs e) { string sSymbolId = txtProductId.Text; if (sSymbolId.Length == 0) { //如果沒有輸入商品代號就離開 return; } __sExchangeName = comboExchange.Text; string sCommodityId = txtCommodity.Text; AbstractExchange cExchange = ProductManager.Manager.GetExchange(__sExchangeName); __cProduct = cExchange.GetProduct(sSymbolId); if (__cProduct == null) { string sProductName = txtProductName.Text; ESymbolCategory cCategory = (ESymbolCategory) Enum.Parse(typeof(ESymbolCategory), comboCategory.Text); __cProduct = new Product(); __cProduct.SymbolId = sSymbolId; __cProduct.SymbolName = sProductName; __cProduct.Category = cCategory; if(sCommodityId.Length > 0) { __cProduct.CommodityId = sCommodityId; } cExchange.AddProduct(__cProduct); } sSymbolId = __cProduct.SymbolId; __sDataSource = comboDataSource.Text; __sDataSource = (__sDataSource.Length == 0) ? null : __sDataSource; string sCommodity = (sCommodityId.Length == 0) ? sSymbolId : sCommodityId; cExchange.AddProperty(sCommodity, __sDataSource); __cProperty = cExchange.GetProperty(sSymbolId, __sDataSource); this.DialogResult = DialogResult.OK; }
/// <summary> /// 取得選擇權履約價格(如果是其他商品則為 0 ) /// </summary> /// <param name="product">商品資訊類別</param> /// <returns>返回值: 履約價格</returns> internal protected abstract double GetStrikePrice(Product product);
/// <summary> /// 取得選擇權為 Call 或 Put(如果是其他商品則為 None) /// </summary> /// <param name="product">商品資訊類別</param> /// <returns>返回值: OptionType列舉</returns> internal protected abstract OptionType GetCallOrPut(Product product);
protected override double GetStrikePrice(Product product) { double dValue = 0; if (product.Category == ESymbolCategory.IndexOption || product.Category == ESymbolCategory.StockOption) { string sSymbolId = product.SymbolId; int iEndIndex = sSymbolId.LastIndexOf("."); int iLength = sSymbolId.Length; for (int i = 4; i < iLength; i++) { if (sSymbolId[i] > 'A') { ++i; dValue = double.Parse(sSymbolId.Substring(i, iEndIndex - i)); break; } } } return dValue; }
/// <summary> /// 建構子 /// </summary> /// <param name="request">InstrumentDataRequest類別</param> public InstrumentSettings(ref InstrumentDataRequest request) { AbstractExchange cExchange = ProductManager.Manager.GetExchange(request.Exchange); __sSymbolId = request.Symbol; __sExchange = request.Exchange; __sDataSource = request.DataFeed; __dTimeZone = cExchange.TimeZone; __cProduct = cExchange.GetProduct(__sSymbolId); __cProperty = cExchange.GetProperty(__sSymbolId, __sDataSource); if (__cProperty != null) { __cOptionType = __cProperty.GetCallOrPut(__cProduct); //取得選擇權 Call or Put 類型 __dStrikePrice = __cProperty.GetStrikePrice(__cProduct); //取得選擇權履約價格 //取得合約到期日索引值 IContractTime cContractTime = __cProperty.ContractRule as IContractTime; if (cContractTime != null) { __iContractIndex = cContractTime.GetContractIndex(__sSymbolId); } } this.Create(ref request); __cResolution = request.Resolution; }
/// <summary> /// 移除商品屬性 /// </summary> /// <param name="product">商品類別</param> public void RemoveProperty(Product product) { if (product != null) { lock (__cPropertys) { string sKey = product.SymbolId; if (__cPropertys.ContainsKey(sKey)) { __cPropertys.Remove(sKey); } else { sKey = product.CommodityId; if (sKey != null && __cPropertys.ContainsKey(sKey)) { __cPropertys.Remove(sKey); } } } } }
/// <summary> /// 新增商品(如果商品已經存在會覆寫之前商品) /// </summary> /// <param name="product">商品類別</param> public void AddProduct(Product product) { Product cProduct = null; string sSymbolId = product.SymbolId.ToLower(); lock (this.Products) { if (this.Products.TryGetValue(sSymbolId, out cProduct)) { cProduct.CommodityId = product.CommodityId; cProduct.Category = product.Category; cProduct.SymbolName = product.SymbolName; } else { this.Products.Add(sSymbolId, product); __cProductClassify.Add(product); } } }
/// <summary> /// 建構子 /// </summary> /// <param name="exchangeName">交易所簡稱</param> /// <param name="quoteService">即時報價服務</param> /// <param name="product">商品資訊</param> public DataSourceInformation(string exchangeName, AbstractQuoteService quoteService, Product product) { __sExchangeName = exchangeName; __cQuoteService = quoteService; __cProduct = product; }