/// <summary> /// /// </summary> /// <param name="InvestorID"></param> /// <param name="Start"></param> /// <param name="Limit"></param> /// <returns></returns> internal List<Business.OrderData> GetOrderByInvestorID(int InvestorID, int Start, int Limit) { List<Business.OrderData> Result = new List<Business.OrderData>(); System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.InvestorTableAdapter adapInvestor = new DSTableAdapters.InvestorTableAdapter(); DSTableAdapters.OnlineCommandTableAdapter adapOpenTrade = new DSTableAdapters.OnlineCommandTableAdapter(); DSTableAdapters.CommandHistoryTableAdapter adapHistory = new DSTableAdapters.CommandHistoryTableAdapter(); DSTableAdapters.InvestorAccountLogTableAdapter adapAccountLog = new DSTableAdapters.InvestorAccountLogTableAdapter(); DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable(); DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable(); DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable(); DS.InvestorAccountLogDataTable tbInvestorAccountLog = new DS.InvestorAccountLogDataTable(); try { conn.Open(); adapInvestor.Connection = conn; adapOpenTrade.Connection = conn; adapHistory.Connection = conn; adapAccountLog.Connection = conn; tbOnlineCommand = adapOpenTrade.GetOpenTradeByInvestorID(Start, InvestorID, Limit); tbCommandHistory = adapHistory.GetHistoryByInvestorID(Start, InvestorID, Limit); tbInvestorAccountLog = adapAccountLog.GetInvestorLogByInvestorID(Start, InvestorID, Limit); if (tbOnlineCommand != null) { int count = tbOnlineCommand.Count; for (int i = 0; i < count; i++) { Business.OrderData newOrderData = new Business.OrderData(); newOrderData.OrderCode = "OPT001"; newOrderData.Code = tbOnlineCommand[i].CommandCode; newOrderData.ID = tbOnlineCommand[i].OnlineCommandID; tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbOnlineCommand[i].InvestorID); if (tbInvestor != null) newOrderData.Login = tbInvestor[0].Code; newOrderData.InvestorID = tbOnlineCommand[i].InvestorID; newOrderData.AgentCommission = 0; newOrderData.ClosePrice = tbOnlineCommand[i].ClosePrice; newOrderData.CloseTime = tbOnlineCommand[i].CloseTime; //newOrderData.Comment = tbOnlineCommand[i] newOrderData.Commission = tbOnlineCommand[i].Commission; newOrderData.ExpDate = tbOnlineCommand[i].ExpTime; newOrderData.Lots = tbOnlineCommand[i].Size; //newOrderData.MarginRate = //newOrderData.OneConvRate newOrderData.OpenPrice = tbOnlineCommand[i].OpenPrice; newOrderData.OpenTime = tbOnlineCommand[i].OpenTime; newOrderData.Profit = tbOnlineCommand[i].Profit; newOrderData.StopLoss = tbOnlineCommand[i].StopLoss; newOrderData.Swaps = tbOnlineCommand[i].Swap; newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbOnlineCommand[i].SymbolID); newOrderData.TakeProfit = tbOnlineCommand[i].TakeProfit; newOrderData.Taxes = tbOnlineCommand[i].Taxes; //newOrderData.TwoConvRate newOrderData.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbOnlineCommand[i].CommandTypeID); //newOrderData.ValueDate Result.Add(newOrderData); } } if (tbCommandHistory != null) { int count = tbCommandHistory.Count; for (int i = 0; i < count; i++) { Business.OrderData newOrderData = new Business.OrderData(); newOrderData.OrderCode = "CMH01"; newOrderData.Code = tbCommandHistory[i].CommandCode; newOrderData.ID = tbCommandHistory[i].CommandHistoryID; tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbCommandHistory[i].InvestorID); if (tbInvestor != null) newOrderData.Login = tbInvestor[0].Code; newOrderData.InvestorID = tbCommandHistory[i].InvestorID; newOrderData.AgentCommission = 0; newOrderData.ClosePrice = tbCommandHistory[i].ClosePrice; newOrderData.CloseTime = tbCommandHistory[i].CloseTime; //newOrderData.Code = tbOnlineCommand[i].inves //newOrderData.Comment = tbOnlineCommand[i] newOrderData.Commission = tbCommandHistory[i].Commission; newOrderData.ExpDate = tbCommandHistory[i].ExpTime; newOrderData.Lots = tbCommandHistory[i].Size; //newOrderData.MarginRate = //newOrderData.OneConvRate newOrderData.OpenPrice = tbCommandHistory[i].OpenPrice; newOrderData.OpenTime = tbCommandHistory[i].OpenTime; newOrderData.Profit = tbCommandHistory[i].Profit; newOrderData.StopLoss = tbCommandHistory[i].StopLoss; newOrderData.Swaps = tbCommandHistory[i].Swap; newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[i].SymbolID); newOrderData.TakeProfit = tbCommandHistory[i].TakeProfit; newOrderData.Taxes = tbCommandHistory[i].Taxes; //newOrderData.TwoConvRate switch (tbCommandHistory[i].CommandTypeID) { case 13: { newOrderData.Type = "ADP01"; } break; case 14: { newOrderData.Type = "WRD01"; } break; case 15: { newOrderData.Type = "ACD01"; } break; case 16: { newOrderData.Type = "CRD01"; } break; default: { newOrderData.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[i].CommandTypeID); } break; } //newOrderData.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[i].CommandTypeID); //newOrderData.ValueDate Result.Add(newOrderData); } } if (tbInvestorAccountLog != null) { int count = tbInvestorAccountLog.Count; for (int i = 0; i < count; i++) { Business.OrderData newOrderData = new Business.OrderData(); newOrderData.OrderCode = "IAL01"; newOrderData.Code = tbInvestorAccountLog[i].DealID; newOrderData.ID = tbInvestorAccountLog[i].ID; tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbInvestorAccountLog[i].InvestorID); if (tbInvestor != null) newOrderData.Login = tbInvestor[0].Code; newOrderData.InvestorID = tbInvestorAccountLog[i].InvestorID; //newOrderData.AgentCommission = 0; //newOrderData.ClosePrice = tbCommandHistory[i].ClosePrice; //newOrderData.CloseTime = tbCommandHistory[i].CloseTime; //newOrderData.Code = tbOnlineCommand[i].inves //newOrderData.Comment = tbOnlineCommand[i] //newOrderData.Commission = tbCommandHistory[i].Commission; //newOrderData.ExpDate = tbCommandHistory[i].ExpTime; //newOrderData.Lots = tbCommandHistory[i].Size; //newOrderData.MarginRate = //newOrderData.OneConvRate //newOrderData.OpenPrice = tbCommandHistory[i].OpenPrice; newOrderData.OpenTime = tbInvestorAccountLog[i].Date; //newOrderData.Profit = tbCommandHistory[i].Profit; //newOrderData.StopLoss = tbCommandHistory[i].StopLoss; //newOrderData.Swaps = tbCommandHistory[i].Swap; //newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[i].SymbolID); //newOrderData.TakeProfit = tbCommandHistory[i].TakeProfit; //newOrderData.Taxes = tbCommandHistory[i].Taxes; //newOrderData.TwoConvRate newOrderData.Type = tbInvestorAccountLog[i].Code; newOrderData.Comment = tbInvestorAccountLog[i].Comment; newOrderData.Profit = tbInvestorAccountLog[i].Amount; //newOrderData.ValueDate Result.Add(newOrderData); } } } catch (Exception ex) { return null; } finally { adapInvestor.Connection.Close(); adapOpenTrade.Connection.Close(); adapHistory.Connection.Close(); adapAccountLog.Connection.Close(); conn.Close(); } return Result; }
/// <summary> /// /// </summary> /// <param name="Code"></param> /// <returns></returns> internal Business.OrderData GetOrderByCode(string Code) { Business.OrderData Result = new Business.OrderData(); System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adapOnlineCommand = new DSTableAdapters.OnlineCommandTableAdapter(); DSTableAdapters.CommandHistoryTableAdapter adapCommandHistory = new DSTableAdapters.CommandHistoryTableAdapter(); DSTableAdapters.InvestorAccountLogTableAdapter adapAccountLog = new DSTableAdapters.InvestorAccountLogTableAdapter(); DSTableAdapters.InvestorTableAdapter adapInvestor = new DSTableAdapters.InvestorTableAdapter(); DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable(); DS.CommandHistoryDataTable tbCommandHistory = new DS.CommandHistoryDataTable(); DS.InvestorAccountLogDataTable tbAccountLog = new DS.InvestorAccountLogDataTable(); DS.InvestorDataTable tbInvestor = new DS.InvestorDataTable(); try { bool flag = false; conn.Open(); adapAccountLog.Connection = conn; adapCommandHistory.Connection = conn; adapOnlineCommand.Connection = conn; adapInvestor.Connection = conn; tbOnlineCommand = adapOnlineCommand.GetOnlineCommandByCommandCode(Code); if (tbOnlineCommand != null && tbOnlineCommand.Count > 0) { Result.OrderCode = "OPT001"; Result.Code = tbOnlineCommand[0].CommandCode; tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbOnlineCommand[0].InvestorID); if (tbInvestor != null) Result.Login = tbInvestor[0].Code; Result.InvestorID = tbOnlineCommand[0].InvestorID; Result.AgentCommission = 0; Result.ClosePrice = tbOnlineCommand[0].ClosePrice; Result.CloseTime = tbOnlineCommand[0].CloseTime; //newOrderData.Comment = tbOnlineCommand[i] Result.Commission = tbOnlineCommand[0].Commission; Result.ExpDate = tbOnlineCommand[0].ExpTime; Result.Lots = tbOnlineCommand[0].Size; //newOrderData.MarginRate = //newOrderData.OneConvRate Result.OpenPrice = tbOnlineCommand[0].OpenPrice; Result.OpenTime = tbOnlineCommand[0].OpenTime; Result.Profit = tbOnlineCommand[0].Profit; Result.StopLoss = tbOnlineCommand[0].StopLoss; Result.Swaps = tbOnlineCommand[0].Swap; Result.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbOnlineCommand[0].SymbolID); Result.TakeProfit = tbOnlineCommand[0].TakeProfit; Result.Taxes = tbOnlineCommand[0].Taxes; //newOrderData.TwoConvRate Result.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbOnlineCommand[0].CommandTypeID); //newOrderData.ValueDate flag = true; } if (!flag) { tbCommandHistory = adapCommandHistory.GetCommandHistoryByCommandCode(Code); if (tbCommandHistory != null && tbCommandHistory.Count > 0) { Result.OrderCode = "CMH01"; Result.Code = tbCommandHistory[0].CommandCode; tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbCommandHistory[0].InvestorID); if (tbInvestor != null) Result.Login = tbInvestor[0].Code; Result.InvestorID = tbCommandHistory[0].InvestorID; Result.AgentCommission = 0; Result.ClosePrice = tbCommandHistory[0].ClosePrice; Result.CloseTime = tbCommandHistory[0].CloseTime; //newOrderData.Code = tbOnlineCommand[i].inves //newOrderData.Comment = tbOnlineCommand[i] Result.Commission = tbCommandHistory[0].Commission; Result.ExpDate = tbCommandHistory[0].ExpTime; Result.Lots = tbCommandHistory[0].Size; //newOrderData.MarginRate = //newOrderData.OneConvRate Result.OpenPrice = tbCommandHistory[0].OpenPrice; Result.OpenTime = tbCommandHistory[0].OpenTime; Result.Profit = tbCommandHistory[0].Profit; Result.StopLoss = tbCommandHistory[0].StopLoss; Result.Swaps = tbCommandHistory[0].Swap; Result.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[0].SymbolID); Result.TakeProfit = tbCommandHistory[0].TakeProfit; Result.Taxes = tbCommandHistory[0].Taxes; //newOrderData.TwoConvRate Result.Type = TradingServer.Facade.FacadeGetTypeNameByTypeID(tbCommandHistory[0].CommandTypeID); //newOrderData.ValueDate flag = true; } } if (!flag) { tbAccountLog = adapAccountLog.GetInvestorAccountLogByCode(Code); if (tbAccountLog != null && tbAccountLog.Count > 0) { Result.OrderCode = "IAL01"; Result.Code = tbAccountLog[0].DealID; tbInvestor = adapInvestor.GetInvestorNameByInvestorID(tbAccountLog[0].InvestorID); if (tbInvestor != null) Result.Login = tbInvestor[0].Code; Result.InvestorID = tbAccountLog[0].InvestorID; //newOrderData.AgentCommission = 0; //newOrderData.ClosePrice = tbCommandHistory[i].ClosePrice; //newOrderData.CloseTime = tbCommandHistory[i].CloseTime; //newOrderData.Code = tbOnlineCommand[i].inves //newOrderData.Comment = tbOnlineCommand[i] //newOrderData.Commission = tbCommandHistory[i].Commission; //newOrderData.ExpDate = tbCommandHistory[i].ExpTime; //newOrderData.Lots = tbCommandHistory[i].Size; //newOrderData.MarginRate = //newOrderData.OneConvRate //newOrderData.OpenPrice = tbCommandHistory[i].OpenPrice; Result.OpenTime = tbAccountLog[0].Date; //newOrderData.Profit = tbCommandHistory[i].Profit; //newOrderData.StopLoss = tbCommandHistory[i].StopLoss; //newOrderData.Swaps = tbCommandHistory[i].Swap; //newOrderData.Symbol = TradingServer.Facade.FacadeGetSymbolNameBySymbolID(tbCommandHistory[i].SymbolID); //newOrderData.TakeProfit = tbCommandHistory[i].TakeProfit; //newOrderData.Taxes = tbCommandHistory[i].Taxes; //newOrderData.TwoConvRate Result.Type = tbAccountLog[0].Code; Result.Comment = tbAccountLog[0].Comment; Result.Profit = tbAccountLog[0].Amount; } } } catch (Exception ex) { return null; } finally { adapAccountLog.Connection.Close(); adapCommandHistory.Connection.Close(); adapInvestor.Connection.Close(); adapOnlineCommand.Connection.Close(); conn.Close(); } return Result; }
/// <summary> /// /// </summary> /// <returns></returns> internal List<Business.OpenTrade> InitOnlineCommand() { List<Business.OpenTrade> result = new List<Business.OpenTrade>(); System.Data.SqlClient.SqlConnection conn = new SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter(); DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable(); try { conn.Open(); adap.Connection = conn; tbOnlineCommand = adap.GetData(); if (tbOnlineCommand != null) { int count = tbOnlineCommand.Count; for (int i = 0; i < count; i++) { //Business.OpenTrade newOpenTradeSymbol = new Business.OpenTrade(); //Business.OpenTrade newOpenTradeInvestor = new Business.OpenTrade(); //Business.OpenTrade newOpenTradeExe = new Business.OpenTrade(); Business.OpenTrade newOpenTradeSymbol = new Business.OpenTrade(tbOnlineCommand[i].IsActivePendig, tbOnlineCommand[i].IsStopLossTakeProfit); Business.OpenTrade newOpenTradeInvestor = new Business.OpenTrade(tbOnlineCommand[i].IsActivePendig, tbOnlineCommand[i].IsStopLossTakeProfit); Business.OpenTrade newOpenTradeExe = new Business.OpenTrade(tbOnlineCommand[i].IsActivePendig, tbOnlineCommand[i].IsStopLossTakeProfit); #region FIND SYMBOL AND TYPE INSTANCE FOR COMMAND(COMMAND IN SYMBOL, COMMAND IN INVESTOR, COMMAND IN COMMAND EXECUTOR if (Business.Market.SymbolList != null && Business.Market.SymbolList.Count > 0) { int countSymbol = Business.Market.SymbolList.Count; for (int j = 0; j < countSymbol; j++) { if (Business.Market.SymbolList[j].SymbolID == tbOnlineCommand[i].SymbolID) { newOpenTradeExe.Symbol = Business.Market.SymbolList[j]; newOpenTradeInvestor.Symbol = Business.Market.SymbolList[j]; newOpenTradeSymbol.Symbol = Business.Market.SymbolList[j]; break; } } } #endregion #region SEARCH MARKET AND GET TYPE COMMAND if (Business.Market.MarketArea != null) { int countMarketArea = Business.Market.MarketArea.Count; bool flagMarketArea = false; for (int j = 0; j < countMarketArea; j++) { if (flagMarketArea) break; if (Business.Market.MarketArea[j].Type != null) { int countType = Business.Market.MarketArea[j].Type.Count; for (int n = 0; n < countType; n++) { if (Business.Market.MarketArea[j].Type[n].ID == tbOnlineCommand[i].CommandTypeID) { newOpenTradeExe.Type = Business.Market.MarketArea[j].Type[n]; newOpenTradeInvestor.Type = Business.Market.MarketArea[j].Type[n]; newOpenTradeSymbol.Type = Business.Market.MarketArea[j].Type[n]; flagMarketArea = true; break; } } } } } #endregion #region FIND INVESTOR AND IGROUPSECURITY INSTANCE OF COMMAND(COMMAND IN SYMBOL, COMMAND IN INVESTOR, COMMAND IN COMMAND EXECUTOR if (Business.Market.InvestorList != null) { int countInvestor = Business.Market.InvestorList.Count; for (int j = 0; j < countInvestor; j++) { if (Business.Market.InvestorList[j].InvestorID == tbOnlineCommand[i].InvestorID) { newOpenTradeSymbol.Investor = Business.Market.InvestorList[j]; newOpenTradeInvestor.Investor = Business.Market.InvestorList[j]; newOpenTradeExe.Investor = Business.Market.InvestorList[j]; #region GET IGROUP SECURITY if (Business.Market.IGroupSecurityList != null) { int countIGroupSecurity = Business.Market.IGroupSecurityList.Count; for (int n = 0; n < countIGroupSecurity; n++) { if (Business.Market.IGroupSecurityList[n].SecurityID == newOpenTradeSymbol.Symbol.SecurityID && Business.Market.IGroupSecurityList[n].InvestorGroupID == newOpenTradeSymbol.Investor.InvestorGroupInstance.InvestorGroupID) { newOpenTradeSymbol.IGroupSecurity = Business.Market.IGroupSecurityList[n]; newOpenTradeInvestor.IGroupSecurity = Business.Market.IGroupSecurityList[n]; newOpenTradeExe.IGroupSecurity = Business.Market.IGroupSecurityList[n]; break; } } } #endregion break; } } } #endregion #region GET SPREAD DIFFIRENCE FOR COMMAND //GET SPREAD DIFFRENCE OF OPEN TRADE double spreadDifference = TradingServer.Model.CommandFramework.CommandFrameworkInstance.GetSpreadDifference(newOpenTradeInvestor.Symbol.SecurityID, newOpenTradeInvestor.Investor.InvestorGroupInstance.InvestorGroupID); newOpenTradeExe.SpreaDifferenceInOpenTrade = spreadDifference; newOpenTradeInvestor.SpreaDifferenceInOpenTrade = spreadDifference; newOpenTradeSymbol.SpreaDifferenceInOpenTrade = spreadDifference; #endregion //=============================== #region SET CLOSE PRICES COMMAND if (tbOnlineCommand[i].CommandTypeID == 1 || tbOnlineCommand[i].CommandTypeID == 11) { newOpenTradeExe.ClosePrice = newOpenTradeExe.Symbol.TickValue.Bid; newOpenTradeInvestor.ClosePrice = newOpenTradeInvestor.Symbol.TickValue.Bid; newOpenTradeSymbol.ClosePrice = newOpenTradeSymbol.Symbol.TickValue.Bid; } if (tbOnlineCommand[i].CommandTypeID == 2 || tbOnlineCommand[i].CommandTypeID == 12) { newOpenTradeExe.ClosePrice = (newOpenTradeExe.Symbol.TickValue.Ask + Business.Symbol.ConvertNumberPip(newOpenTradeExe.Symbol.Digit, newOpenTradeExe.SpreaDifferenceInOpenTrade)); newOpenTradeInvestor.ClosePrice = (newOpenTradeInvestor.Symbol.TickValue.Ask + Business.Symbol.ConvertNumberPip(newOpenTradeInvestor.Symbol.Digit, newOpenTradeInvestor.SpreaDifferenceInOpenTrade)); newOpenTradeSymbol.ClosePrice = (newOpenTradeSymbol.Symbol.TickValue.Ask + Business.Symbol.ConvertNumberPip(newOpenTradeSymbol.Symbol.Digit, newOpenTradeSymbol.SpreaDifferenceInOpenTrade)); } #endregion //================================= #region NEW INSTANCES FOR COMMAND EXECUTOR newOpenTradeExe.AgentCommission = tbOnlineCommand[i].AgentCommission; newOpenTradeExe.ClientCode = tbOnlineCommand[i].ClientCode; newOpenTradeExe.CloseTime = tbOnlineCommand[i].CloseTime; newOpenTradeExe.CommandCode = tbOnlineCommand[i].CommandCode; newOpenTradeExe.Comment = tbOnlineCommand[i].Comment; newOpenTradeExe.Commission = tbOnlineCommand[i].Commission; newOpenTradeExe.ExpTime = tbOnlineCommand[i].ExpTime; newOpenTradeExe.FreezeMargin = 0; newOpenTradeExe.ID = tbOnlineCommand[i].OnlineCommandID; newOpenTradeExe.IsClose = tbOnlineCommand[i].IsClose; newOpenTradeExe.OpenPrice = tbOnlineCommand[i].OpenPrice; newOpenTradeExe.OpenTime = tbOnlineCommand[i].OpenTime; newOpenTradeExe.Profit = tbOnlineCommand[i].Profit; newOpenTradeExe.Size = tbOnlineCommand[i].Size; newOpenTradeExe.StopLoss = tbOnlineCommand[i].StopLoss; newOpenTradeExe.Swap = tbOnlineCommand[i].Swap; newOpenTradeExe.TakeProfit = tbOnlineCommand[i].TakeProfit; newOpenTradeExe.Taxes = tbOnlineCommand[i].Taxes; newOpenTradeExe.TotalSwap = tbOnlineCommand[i].TotalSwaps; newOpenTradeExe.RefCommandID = tbOnlineCommand[i].RefCommandID; newOpenTradeExe.AgentRefConfig = tbOnlineCommand[i].AgentRefConfig; #endregion #region NEW INSTANCE FOR SYMBOL LIST newOpenTradeSymbol.AgentCommission = tbOnlineCommand[i].AgentCommission; newOpenTradeSymbol.ClientCode = tbOnlineCommand[i].ClientCode; newOpenTradeSymbol.CloseTime = tbOnlineCommand[i].CloseTime; newOpenTradeSymbol.CommandCode = tbOnlineCommand[i].CommandCode; newOpenTradeSymbol.Comment = tbOnlineCommand[i].Comment; newOpenTradeSymbol.Commission = tbOnlineCommand[i].Commission; newOpenTradeSymbol.ExpTime = tbOnlineCommand[i].ExpTime; newOpenTradeSymbol.FreezeMargin = 0; newOpenTradeSymbol.ID = tbOnlineCommand[i].OnlineCommandID; newOpenTradeSymbol.IsClose = tbOnlineCommand[i].IsClose; newOpenTradeSymbol.OpenPrice = tbOnlineCommand[i].OpenPrice; newOpenTradeSymbol.OpenTime = tbOnlineCommand[i].OpenTime; newOpenTradeSymbol.Profit = tbOnlineCommand[i].Profit; newOpenTradeSymbol.Size = tbOnlineCommand[i].Size; newOpenTradeSymbol.StopLoss = tbOnlineCommand[i].StopLoss; newOpenTradeSymbol.Swap = tbOnlineCommand[i].Swap; newOpenTradeSymbol.TakeProfit = tbOnlineCommand[i].TakeProfit; newOpenTradeSymbol.Taxes = tbOnlineCommand[i].Taxes; newOpenTradeSymbol.TotalSwap = tbOnlineCommand[i].TotalSwaps; newOpenTradeSymbol.InsExe = newOpenTradeExe; newOpenTradeSymbol.RefCommandID = tbOnlineCommand[i].RefCommandID; newOpenTradeSymbol.AgentRefConfig = tbOnlineCommand[i].AgentRefConfig; #endregion #region NEW INSTANCE FOR INVESTOR LIST newOpenTradeInvestor.AgentCommission = tbOnlineCommand[i].AgentCommission; newOpenTradeInvestor.ClientCode = tbOnlineCommand[i].ClientCode; newOpenTradeInvestor.CloseTime = tbOnlineCommand[i].CloseTime; newOpenTradeInvestor.CommandCode = tbOnlineCommand[i].CommandCode; newOpenTradeInvestor.Comment = tbOnlineCommand[i].Comment; newOpenTradeInvestor.Commission = tbOnlineCommand[i].Commission; newOpenTradeInvestor.ExpTime = tbOnlineCommand[i].ExpTime; newOpenTradeInvestor.FreezeMargin = 0; newOpenTradeInvestor.ID = tbOnlineCommand[i].OnlineCommandID; newOpenTradeInvestor.IsClose = tbOnlineCommand[i].IsClose; newOpenTradeInvestor.OpenPrice = tbOnlineCommand[i].OpenPrice; newOpenTradeInvestor.OpenTime = tbOnlineCommand[i].OpenTime; newOpenTradeInvestor.Profit = tbOnlineCommand[i].Profit; newOpenTradeInvestor.Size = tbOnlineCommand[i].Size; newOpenTradeInvestor.StopLoss = tbOnlineCommand[i].StopLoss; newOpenTradeInvestor.Swap = tbOnlineCommand[i].Swap; newOpenTradeInvestor.TakeProfit = tbOnlineCommand[i].TakeProfit; newOpenTradeInvestor.Taxes = tbOnlineCommand[i].Taxes; newOpenTradeInvestor.TotalSwap = tbOnlineCommand[i].TotalSwaps; newOpenTradeInvestor.InsExe = newOpenTradeExe; newOpenTradeInvestor.RefCommandID = tbOnlineCommand[i].RefCommandID; newOpenTradeInvestor.AgentRefConfig = tbOnlineCommand[i].AgentRefConfig; #endregion //====================================== #region ADD COMMAND TO COMMAND EXECUTOR if (Business.Market.CommandExecutor == null) Business.Market.CommandExecutor = new List<Business.OpenTrade>(); Business.Market.CommandExecutor.Add(newOpenTradeExe); #endregion #region ADD COMMAND TO INVESTOR LIST if (Business.Market.InvestorList != null) { int countInvestor = Business.Market.InvestorList.Count; for (int j = 0; j < countInvestor; j++) { if (Business.Market.InvestorList[j].InvestorID == tbOnlineCommand[i].InvestorID) { if (Business.Market.InvestorList[j].CommandList == null) Business.Market.InvestorList[j].CommandList = new List<Business.OpenTrade>(); Business.Market.InvestorList[j].CommandList.Add(newOpenTradeInvestor); break; } } } #endregion #region ADD COMMAND TO SYMBOL LIST if (Business.Market.SymbolList != null) { int countSymbol = Business.Market.SymbolList.Count; for (int j = 0; j < countSymbol; j++) { if (Business.Market.SymbolList[j].SymbolID == tbOnlineCommand[i].SymbolID) { if (Business.Market.SymbolList[j].CommandList == null) Business.Market.SymbolList[j].CommandList = new List<Business.OpenTrade>(); Business.Market.SymbolList[j].CommandList.Add(newOpenTradeSymbol); break; } } } #endregion result.Add(newOpenTradeInvestor); } } } catch (Exception ex) { return null; } finally { adap.Connection.Close(); conn.Close(); } return result; }
/// <summary> /// /// </summary> /// <param name="SymbolID"></param> /// <returns></returns> internal List<Business.OpenTrade> GetOnlineCommandBySymbolID(int SymbolID) { List<Business.OpenTrade> Result = new List<Business.OpenTrade>(); System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter(); DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable(); try { conn.Open(); adap.Connection = conn; tbOnlineCommand = adap.GetOnlineCommandBySymbolID(SymbolID); if (tbOnlineCommand != null) { int count = tbOnlineCommand.Count; for (int i = 0; i < count; i++) { Business.OpenTrade newOpenTrade = new Business.OpenTrade(); newOpenTrade.ID = tbOnlineCommand[i].OnlineCommandID; //Find Trade Type if (Business.Market.MarketArea != null) { bool Flag = false; int countMarketArea = Business.Market.MarketArea.Count; for (int j = 0; j < countMarketArea; j++) { if (Flag == true) break; if (Business.Market.MarketArea[j].Type != null) { int countTradeType = Business.Market.MarketArea[j].Type.Count; for (int n = 0; n < countTradeType; n++) { if (Business.Market.MarketArea[j].Type[n].ID == tbOnlineCommand[i].CommandTypeID) { newOpenTrade.Type = Business.Market.MarketArea[j].Type[n]; Flag = true; break; } } } } } newOpenTrade.Investor = new Business.Investor(); newOpenTrade.Investor.InvestorID = tbOnlineCommand[i].InvestorID; newOpenTrade.Symbol = new Business.Symbol(); newOpenTrade.Symbol.SymbolID = tbOnlineCommand[i].SymbolID; newOpenTrade.ClientCode = tbOnlineCommand[i].ClientCode; newOpenTrade.ClosePrice = tbOnlineCommand[i].ClosePrice; newOpenTrade.CloseTime = tbOnlineCommand[i].CloseTime; newOpenTrade.ExpTime = tbOnlineCommand[i].ExpTime; newOpenTrade.IsClose = tbOnlineCommand[i].IsClose; newOpenTrade.OpenPrice = tbOnlineCommand[i].OpenPrice; newOpenTrade.OpenTime = tbOnlineCommand[i].OpenTime; newOpenTrade.Size = tbOnlineCommand[i].Size; newOpenTrade.StopLoss = tbOnlineCommand[i].StopLoss; newOpenTrade.TakeProfit = tbOnlineCommand[i].TakeProfit; //newOpenTrade.NumberUpdate = tbOnlineCommand[i].NumberUpdate; newOpenTrade.Commission = tbOnlineCommand[i].Commission; newOpenTrade.Swap = tbOnlineCommand[i].Swap; newOpenTrade.Profit = tbOnlineCommand[i].Profit; newOpenTrade.CommandCode = tbOnlineCommand[i].CommandCode; newOpenTrade.Commission = tbOnlineCommand[i].Commission; newOpenTrade.Taxes = tbOnlineCommand[i].Taxes; newOpenTrade.Comment = tbOnlineCommand[i].Comment; newOpenTrade.AgentCommission = tbOnlineCommand[i].AgentCommission; newOpenTrade.RefCommandID = tbOnlineCommand[i].RefCommandID; Result.Add(newOpenTrade); } } } catch (Exception ex) { return null; } finally { adap.Connection.Close(); conn.Close(); } return Result; }
/// <summary> /// /// </summary> /// <param name="InvestorID"></param> /// <returns></returns> internal List<Business.OpenTrade> GetOnlineCommandByInvestorID(int InvestorID) { List<Business.OpenTrade> Result = new List<Business.OpenTrade>(); System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter(); DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable(); try { conn.Open(); adap.Connection = conn; tbOnlineCommand = adap.GetOnlineCommandByInvestorID(InvestorID); if (tbOnlineCommand != null) { int count = tbOnlineCommand.Count; for (int i = 0; i < count; i++) { Business.OpenTrade newOpenTrade = new Business.OpenTrade(); newOpenTrade.ID = tbOnlineCommand[i].OnlineCommandID; //CommandType newOpenTrade.Investor = new Business.Investor(); newOpenTrade.Investor.InvestorID = tbOnlineCommand[i].InvestorID; newOpenTrade.Symbol = new Business.Symbol(); newOpenTrade.Symbol.SymbolID = tbOnlineCommand[i].SymbolID; newOpenTrade.ClientCode = tbOnlineCommand[i].ClientCode; newOpenTrade.ClosePrice = tbOnlineCommand[i].ClosePrice; newOpenTrade.CloseTime = tbOnlineCommand[i].CloseTime; newOpenTrade.ExpTime = tbOnlineCommand[i].ExpTime; newOpenTrade.IsClose = tbOnlineCommand[i].IsClose; newOpenTrade.OpenPrice = tbOnlineCommand[i].OpenPrice; newOpenTrade.OpenTime = tbOnlineCommand[i].OpenTime; newOpenTrade.Size = tbOnlineCommand[i].Size; newOpenTrade.StopLoss = tbOnlineCommand[i].StopLoss; newOpenTrade.TakeProfit = tbOnlineCommand[i].TakeProfit; //newOpenTrade.NumberUpdate = tbOnlineCommand[i].NumberUpdate; newOpenTrade.Commission = tbOnlineCommand[i].Commission; newOpenTrade.Swap = tbOnlineCommand[i].Swap; newOpenTrade.Profit = tbOnlineCommand[i].Profit; newOpenTrade.CommandCode = tbOnlineCommand[i].CommandCode; newOpenTrade.Commission = tbOnlineCommand[i].Commission; newOpenTrade.Taxes = tbOnlineCommand[i].Taxes; newOpenTrade.Comment = tbOnlineCommand[i].Comment; newOpenTrade.AgentCommission = tbOnlineCommand[i].AgentCommission; newOpenTrade.RefCommandID = tbOnlineCommand[i].RefCommandID; Result.Add(newOpenTrade); } } } catch (Exception ex) { return null; } finally { adap.Connection.Close(); conn.Close(); } return Result; }
/// <summary> /// /// </summary> /// <returns></returns> internal List<Business.OpenTrade> GetAllOnlineCommand() { List<Business.OpenTrade> Result = new List<Business.OpenTrade>(); System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter(); DS.OnlineCommandDataTable tbOnlineCommand = new DS.OnlineCommandDataTable(); try { conn.Open(); adap.Connection = conn; tbOnlineCommand = adap.GetData(); if (tbOnlineCommand != null) { int count = tbOnlineCommand.Count; for (int i = 0; i < count; i++) { Business.OpenTrade newOpenTrade = new Business.OpenTrade(); newOpenTrade.ID = tbOnlineCommand[i].OnlineCommandID; #region Find Symbol In Symbol List if (Business.Market.SymbolList != null) { bool Flag = false; int countSymbol = Business.Market.SymbolList.Count; for (int k = 0; k < countSymbol; k++) { if (Business.Market.SymbolList[k].SymbolID == tbOnlineCommand[i].SymbolID) { #region SEARCH IN MARKET OF SYMBOL AND GET TYPE OF COMMAND bool tempFlag = false; if (Business.Market.MarketArea != null) { int countMarketArea = Business.Market.MarketArea.Count; for (int n = 0; n < countMarketArea; n++) { if (tempFlag) break; if (Business.Market.MarketArea[n].Type != null) { int countType = Business.Market.MarketArea[n].Type.Count; for (int m = 0; m < countType; m++) { if (Business.Market.MarketArea[n].Type[m].ID == tbOnlineCommand[i].CommandTypeID) { newOpenTrade.Type = Business.Market.MarketArea[n].Type[m]; tempFlag = true; break; } } } } } #endregion newOpenTrade.Symbol = Business.Market.SymbolList[k]; newOpenTrade.ClientCode = tbOnlineCommand[i].ClientCode; switch (newOpenTrade.Type.ID) { case 1: newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Bid; break; case 2: newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Ask; break; case 11: newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Bid; break; case 12: newOpenTrade.ClosePrice = newOpenTrade.Symbol.TickValue.Ask; break; } newOpenTrade.CloseTime = tbOnlineCommand[i].CloseTime; newOpenTrade.ExpTime = tbOnlineCommand[i].ExpTime; newOpenTrade.IsClose = tbOnlineCommand[i].IsClose; newOpenTrade.OpenPrice = tbOnlineCommand[i].OpenPrice; newOpenTrade.OpenTime = tbOnlineCommand[i].OpenTime; newOpenTrade.Size = tbOnlineCommand[i].Size; newOpenTrade.StopLoss = tbOnlineCommand[i].StopLoss; newOpenTrade.TakeProfit = tbOnlineCommand[i].TakeProfit; newOpenTrade.Commission = tbOnlineCommand[i].Commission; newOpenTrade.Swap = Math.Round(tbOnlineCommand[i].Swap, 2); newOpenTrade.Profit = tbOnlineCommand[i].Profit; newOpenTrade.CommandCode = tbOnlineCommand[i].CommandCode; newOpenTrade.Taxes = tbOnlineCommand[i].Taxes; newOpenTrade.Comment = tbOnlineCommand[i].Comment; newOpenTrade.AgentCommission = tbOnlineCommand[i].AgentCommission; newOpenTrade.TotalSwap = tbOnlineCommand[i].TotalSwaps; newOpenTrade.RefCommandID = tbOnlineCommand[i].RefCommandID; #region Find Investor In Investor List if (Business.Market.InvestorList != null) { int countInvestor = Business.Market.InvestorList.Count; for (int m = 0; m < countInvestor; m++) { if (Business.Market.InvestorList[m].InvestorID == tbOnlineCommand[i].InvestorID) { newOpenTrade.Investor = Business.Market.InvestorList[m]; #region Find IGroupSecurity In IGroupSecurity List if (Business.Market.IGroupSecurityList != null) { int countIGroupSecurity = Business.Market.IGroupSecurityList.Count; for (int p = 0; p < countIGroupSecurity; p++) { if (Business.Market.IGroupSecurityList[p].SecurityID == newOpenTrade.Symbol.SecurityID && Business.Market.IGroupSecurityList[p].InvestorGroupID == newOpenTrade.Investor.InvestorGroupInstance.InvestorGroupID) { newOpenTrade.IGroupSecurity = Business.Market.IGroupSecurityList[p]; break; } } } #endregion if (Business.Market.InvestorList[m].CommandList == null) Business.Market.InvestorList[m].CommandList = new List<Business.OpenTrade>(); Business.Market.InvestorList[m].CommandList.Add(newOpenTrade); break; } } } #endregion //GET SPREAD DIFFRENCE OF OPEN TRADE double spreadDifference = TradingServer.Model.CommandFramework.CommandFrameworkInstance.GetSpreadDifference(newOpenTrade.Symbol.SecurityID, newOpenTrade.Investor.InvestorGroupInstance.InvestorGroupID); newOpenTrade.SpreaDifferenceInOpenTrade = spreadDifference; if (Business.Market.SymbolList[k].CommandList == null) Business.Market.SymbolList[k].CommandList = new List<Business.OpenTrade>(); Business.Market.SymbolList[k].CommandList.Add(newOpenTrade); #region ADD COMMAND TO COMMAND EXECUTORY if (Business.Market.CommandExecutor == null) Business.Market.CommandExecutor = new List<Business.OpenTrade>(); Business.Market.CommandExecutor.Add(newOpenTrade); #endregion Flag = true; break; } //if (Flag == false) //{ // if (Business.Market.SymbolList[k].RefSymbol != null && Business.Market.SymbolList[k].RefSymbol.Count > 0) // { // newOpenTrade.Symbol = this.FindSymbolReference(Business.Market.SymbolList[k].RefSymbol, newOpenTrade, tbOnlineCommand[i].SymbolID); // } //} } } #endregion Result.Add(newOpenTrade); } } } catch (Exception ex) { return null; } finally { adap.Connection.Close(); conn.Close(); } return Result; }