private void CreateTickByTickHistoryDatas2(object state) { var tickByTickHistoryDataArgument = (TickByTickHistoryDataArgument2)state; try { TradingConsoleState tradingConsoleState = tickByTickHistoryDataArgument.TradingConsoleState; if (tradingConsoleState.Instruments.ContainsKey(tickByTickHistoryDataArgument.InstrumentId)) { Guid quotePolicyId = (Guid)tradingConsoleState.Instruments[tickByTickHistoryDataArgument.InstrumentId]; TradingConsoleServer tradingConsoleServer = tickByTickHistoryDataArgument.TradingConsoleServer; DataSet dataSet = tradingConsoleServer.GetTickByTickHistoryDatas2(tickByTickHistoryDataArgument.InstrumentId, quotePolicyId, tickByTickHistoryDataArgument.From, tickByTickHistoryDataArgument.To); AsyncResultManager asyncResultManager = tickByTickHistoryDataArgument.AsyncResultManager; asyncResultManager.SetResult(tickByTickHistoryDataArgument.AsyncResult, dataSet); CommandManager.Default.AddCommand(new AsyncCommand(0, tickByTickHistoryDataArgument.AsyncResult)); } else { _Logger.Warn(string.Format("Instrument {0} doesn't exists in TradingConsoleState", tickByTickHistoryDataArgument.InstrumentId)); CommandManager.Default.AddCommand(new AsyncCommand(0, tickByTickHistoryDataArgument.AsyncResult, true, null)); } } catch (Exception e) { _Logger.Error(e); CommandManager.Default.AddCommand(new AsyncCommand(0, tickByTickHistoryDataArgument.AsyncResult, true, e)); } }
private static void CreateChartData2(object state) { ChartDataArgument2 chartDataArgument = (ChartDataArgument2)state; try { //DataSet dataSet = this.GetChartData2(chartDataArgument.InstrumentId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); //SChart.Datas.StockData stockData = new SChart.Datas.StockData(cookieContainer); //DataSet dataSet = stockData.GetChartData2(chartDataArgument.InstrumentId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); TradingConsoleState tradingConsoleState = chartDataArgument.TradingConsoleState; Guid quotePolicyId = (Guid)tradingConsoleState.Instruments[chartDataArgument.InstrumentId]; TradingConsoleServer tradingConsoleServer = chartDataArgument.TradingConsoleServer; DataSet dataSet = tradingConsoleServer.GetChartData2(chartDataArgument.InstrumentId, quotePolicyId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); AsyncResultManager asyncResultManager = chartDataArgument.AsyncResultManager; asyncResultManager.SetResult(chartDataArgument.AsyncResult, dataSet); CommandManager.Default.AddCommand(new AsyncCommand(0, chartDataArgument.AsyncResult)); //else //{ // string userIdString = string.Empty; // if (chartDataArgument.Token != null) // { // Token token = chartDataArgument.Token; // userIdString = token.UserID.ToString(); // } // AppDebug.LogEvent("TradingConsole.Service.CreateChartData2", "CookieContainer Timeout" + " UserId: " + userIdString, EventLogEntryType.Warning); // Commands commands = chartDataArgument.Commands; // commands.Add(chartDataArgument.Token, new AsyncCommand(0, chartDataArgument.AsyncResult, true, null)); //} } catch (Exception e) { _Logger.Error(e); CommandManager.Default.AddCommand(new AsyncCommand(0, chartDataArgument.AsyncResult, true, e)); } }
public HttpContextHolder(long session) { string version = SessionManager.Default.GetVersion(session); this._Version = version == null ? "ENG" : version; this._TradingConsoleServer = Application.Default.TradingConsoleServer; this._AsyncResultManager = Application.Default.AsyncResultManager; this._Token = SessionManager.Default.GetToken(session); this._TradingConsoleState = SessionManager.Default.GetTradingConsoleState(session); }
public TraderState(TradingConsoleState state) : base(state.SessionId) { if (state != null) { Copy(state.AccountGroups, this.AccountGroups); Copy(state.Accounts, this.Accounts); Copy(state.Instruments, this.Instruments); this.Language = state.Language; this.IsEmployee = state.IsEmployee; } }
public HttpContextHolder(Session session) { string version = SessionManager.Default.GetVersion(session); this._Version = version == null ? "ENG" : version; this._TradingConsoleServer = Application.Default.TradingConsoleServer; this._AsyncResultManager = Application.Default.AsyncResultManager; this._Token = SessionManager.Default.GetToken(session); this._TradingConsoleState = SessionManager.Default.GetTradingConsoleState(session); }
public void UpdateAccount(Session session, Guid accountID, Guid groupID, bool isDelete, bool isDeleteGroup) { try { TradingConsoleState state = SessionManager.Default.GetTradingConsoleState(session); Application.Default.TradingConsoleServer.UpdateAccount(accountID, groupID, isDelete, isDeleteGroup, state); } catch (System.Exception exception) { _Logger.Error((exception)); } }
public XmlNode GetCommands(Token token, State state, int firstSequence, int lastSequence) { this._ReaderWriterLock.EnterReadLock(); try { XmlDocument xmlDoc = new XmlDocument(); XmlElement commands = xmlDoc.CreateElement("Commands"); xmlDoc.AppendChild(commands); List <Command> commandList = this.InnerGet(firstSequence, lastSequence); if (commandList == null) { this._Logger.ErrorFormat("get lost command {0} -------{1} return null", firstSequence, lastSequence); return(null); } TradingConsoleState tradingConsoleState = state as TradingConsoleState; ArrayList quotationCommands = new ArrayList(); foreach (var command in commandList) { QuotationCommand quotation = command as QuotationCommand; if (quotation != null) { quotationCommands.Add(quotation); } else { if (quotationCommands.Count > 0) { QuotationCommand mergingCommand = this.Merge(quotationCommands); quotationCommands.Clear(); this.AppendChild(commands, mergingCommand, token, state); } this.AppendChild(commands, command, token, state); } } if (quotationCommands.Count > 0) { QuotationCommand mergingCommand = this.Merge(quotationCommands); quotationCommands.Clear(); this.AppendChild(commands, mergingCommand, token, state); } commands.SetAttribute("FirstSequence", firstSequence.ToString()); commands.SetAttribute("LastSequence", lastSequence.ToString()); return(commands); } finally { this._ReaderWriterLock.ExitReadLock(); } }
public DataSet GetInstruments(Session session, List <Guid> instrumentIDs) { try { TradingConsoleState state = SessionManager.Default.GetTradingConsoleState(session); Token token = SessionManager.Default.GetToken(session); DataSet dataSet = Application.Default.TradingConsoleServer.GetInstruments(token, instrumentIDs, state); return(dataSet); } catch (System.Exception exception) { _Logger.Error(exception); return(null); } }
public TraderState(TradingConsoleState state) : base(state.SessionId) { _InstrumentsAdapter = new InstrumentsAdapter(Instruments); if (state != null) { Copy(state.AccountGroups, this.AccountGroups); Copy(state.Accounts, this.Accounts); foreach (DictionaryEntry item in state.Instruments) { _InstrumentsAdapter.Add((Guid)item.Key, (Guid)item.Value); } this.Language = state.Language; this.IsEmployee = state.IsEmployee; } }
private static void CreateChartData2ForMobile(object state) { ChartDataArgument2 chartDataArgument = (ChartDataArgument2)state; try { TradingConsoleState tradingConsoleState = chartDataArgument.TradingConsoleState; Guid quotePolicyId = (Guid)tradingConsoleState.Instruments[chartDataArgument.InstrumentId]; TradingConsoleServer tradingConsoleServer = chartDataArgument.TradingConsoleServer; //DataSet dataSet = tradingConsoleServer.GetChartData2(chartDataArgument.InstrumentId, quotePolicyId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); string dataCycle = chartDataArgument.DataCycle.ToLower(); string dateFormat = ChartQuotation.FormatMinute; //DataSet dataSet = DataAccess.GetChartData(instrumentId, quotePolicyId, dataCycle, fromTime.Value, toTime, commandTimeOut); DataSet dataSet = tradingConsoleServer.GetChartData2(chartDataArgument.InstrumentId, quotePolicyId, chartDataArgument.DataCycle, chartDataArgument.From, chartDataArgument.To); ChartQuotationCollection chartQuotationCollection = ChartQuotationCollection.Create(dataSet, dataCycle, dateFormat); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ChartQuotationCollection)); string result; using (MemoryStream stream = new MemoryStream()) { serializer.WriteObject(stream, chartQuotationCollection); stream.Seek(0, SeekOrigin.Begin); StreamReader streamReader = new StreamReader(stream); result = streamReader.ReadToEnd(); } AsyncResultManager asyncResultManager = chartDataArgument.AsyncResultManager; XElement element = XmlResultHelper.NewResult("ChartData", result); asyncResultManager.SetResult(chartDataArgument.AsyncResult, element); AsyncCommand command = new AsyncCommand(0, chartDataArgument.AsyncResult); command.Content = element.ToXmlNode(); CommandManager.Default.AddCommand(command); } catch (Exception e) { _Logger.Error(e); CommandManager.Default.AddCommand(new AsyncCommand(0, chartDataArgument.AsyncResult, true, e)); } }
private DataSet GetTickDatas(Guid instrumentId, DateTime dateTime, int minutes, TradingConsoleState state, TradingConsoleServer tradingConsoleServer) { try { if (state.Instruments.ContainsKey(instrumentId)) { Guid quotePolicyId = (Guid)state.Instruments[instrumentId]; DataSet dataSet = tradingConsoleServer.GetTickDatas(instrumentId, quotePolicyId, dateTime, minutes); return dataSet; } else { AppDebug.LogEvent("TradingConsole.GetTickDatas", string.Format("Instrument {0} doesn't exists in TradingConsoleState", instrumentId), EventLogEntryType.Warning); return null; } } catch (Exception e) { AppDebug.LogEvent("TradingConsole.GetTickDatas", e.ToString(), EventLogEntryType.Error); return null; } }
public void RefreshInstrumentsState2(DataSet dataSet, ref TradingConsoleState state2, string sessionId) { TradingConsoleState state = state2 == null ? new TradingConsoleState(sessionId) : state2; if (state.Instruments.Count > 0) { state.Instruments.Clear(); } if (dataSet.Tables.Count > 0) { StringBuilder quotePolicyInfo = new StringBuilder(); quotePolicyInfo.Append("SessionId = " + state.SessionId + "\t"); DataRowCollection rows = dataSet.Tables["QuotePolicyDetail"].Rows; foreach (DataRow quotePolicyDetailRow in rows) { state.Instruments.Add(quotePolicyDetailRow["InstrumentID"], quotePolicyDetailRow["QuotePolicyID"]); if (quotePolicyInfo.Length > 0) quotePolicyInfo.Append(";"); quotePolicyInfo.Append(quotePolicyDetailRow["InstrumentID"]); quotePolicyInfo.Append("="); quotePolicyInfo.Append(quotePolicyDetailRow["QuotePolicyID"]); } } state2 = state; }
public void UpdateInstrumentSetting(DataSet instruments, string[] instrumentIDs, TradingConsoleState state) { DataRowCollection rows; if (instrumentIDs.Length <= 0) { state.Instruments.Clear(); } else { ArrayList keys = new ArrayList(); foreach (Guid key in state.Instruments.Keys) { bool isExists = false; foreach (string instrumentID in instrumentIDs) { if (key.ToString().ToUpper() == instrumentID.ToUpper()) { isExists = true; break; } } if (!isExists) keys.Add(key); } for (int i = 0; i < keys.Count; i++) { state.Instruments.Remove(keys[i]); } if (instruments != null && instruments.Tables.Count > 0) { StringBuilder quotePolicyInfo = new StringBuilder(); quotePolicyInfo.Append("SessionId = " + state.SessionId + "\t"); rows = instruments.Tables["Instrument"].Rows; foreach (DataRow instrumentRow in rows) { if (!state.Instruments.ContainsKey(instrumentRow["ID"])) { state.Instruments.Add(instrumentRow["ID"], instrumentRow["QuotePolicyID"]); if (quotePolicyInfo.Length > 0) quotePolicyInfo.Append(";"); quotePolicyInfo.Append(instrumentRow["ID"]); quotePolicyInfo.Append("="); quotePolicyInfo.Append(instrumentRow["QuotePolicyID"]); } } } } }
public XElement UpdateQuotePolicyDetail(Guid instrumentID, Guid quotePolicyID, TradingConsoleState state) { try { AppDebug.LogEvent("TradingConsole.UpdateQuotePolicyDetail]QuotePolicy", string.Format("SessionId = {0}, InstrumentId = {1}, QuotePolicyId = {2}{3}{4}", state.SessionId, instrumentID, quotePolicyID, Environment.NewLine, Environment.StackTrace), EventLogEntryType.Information); if (state.Instruments.ContainsKey(instrumentID)) { state.Instruments[instrumentID] = quotePolicyID; } else { state.Instruments.Add(instrumentID, quotePolicyID); } return XmlResultHelper.NewResult(StringConstants.OK_RESULT); } catch (Exception ex) { return XmlResultHelper.ErrorResult; } }
public DataSet GetInstruments(Token token, List<Guid> instrumentIDs, TradingConsoleState state) { string xmlInstrumentIDs = string.Empty; System.Collections.IEnumerator instrumentIDs2 = instrumentIDs.GetEnumerator(); while (instrumentIDs2.MoveNext()) { xmlInstrumentIDs += "<Instrument ID=\"" + instrumentIDs2.Current.ToString() + "\" />"; } if (xmlInstrumentIDs != string.Empty) xmlInstrumentIDs = "<Instruments>" + xmlInstrumentIDs + "</Instruments>"; DataSet dataSet = new DataSet(); SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand("dbo.P_GetInstrumentForTradingConsole2", sqlConnection); sqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter sqlParameter = sqlCommand.Parameters.Add("@userID", SqlDbType.UniqueIdentifier, 38); sqlParameter.Value = token.UserID; sqlParameter = sqlCommand.Parameters.Add("@xmlInstrumentIDs", SqlDbType.NText); sqlParameter.Value = xmlInstrumentIDs; sqlConnection.Open(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); sqlDataAdapter.Fill(dataSet); if (dataSet.Tables.Count > 0) dataSet.Tables[0].TableName = "Instrument"; if (dataSet.Tables.Count > 1) dataSet.Tables[1].TableName = "TradingTime"; if (dataSet.Tables.Count > 2) dataSet.Tables[2].TableName = "TradePolicyDetail"; if (dataSet.Tables.Count > 3) dataSet.Tables[3].TableName = "Quotation"; sqlConnection.Close(); instrumentIDs2.Reset(); while (instrumentIDs2.MoveNext()) { Guid instrumentID = (Guid)instrumentIDs2.Current; if (!state.Instruments.ContainsKey(instrumentID)) { StringBuilder quotePolicyInfo = new StringBuilder(); quotePolicyInfo.Append("SessionId=" + state.SessionId + "\t"); DataRowCollection rows = dataSet.Tables["Instrument"].Rows; foreach (DataRow instrumentRow in rows) { state.Instruments.Add(instrumentRow["ID"], instrumentRow["QuotePolicyID"]); if (quotePolicyInfo.Length > 0) quotePolicyInfo.Append(";"); quotePolicyInfo.Append(instrumentRow["ID"]); quotePolicyInfo.Append("="); quotePolicyInfo.Append(instrumentRow["QuotePolicyID"]); } } } return (dataSet); }
public XElement UpdateQuotePolicyDetail(Guid instrumentID, Guid quotePolicyID, TradingConsoleState state) { try { _Logger.Info(string.Format("SessionId = {0}, InstrumentId = {1}, QuotePolicyId = {2}{3}{4}", state.SessionId, instrumentID, quotePolicyID, Environment.NewLine, Environment.StackTrace)); if (state.Instruments.ContainsKey(instrumentID)) { state.Instruments[instrumentID] = quotePolicyID; } else { state.Instruments.Add(instrumentID, quotePolicyID); } return XmlResultHelper.NewResult(StringConstants.OkResult); } catch (Exception ex) { _Logger.Error(ex); return XmlResultHelper.NewErrorResult(); } }
public void UpdateAccount(Guid accountID, Guid groupID, bool isDelete, bool isDeleteGroup, TradingConsoleState state) { if (isDelete) { if (state.Accounts.ContainsKey(accountID)) { state.Accounts.Remove(accountID); if (isDeleteGroup) { state.AccountGroups.Remove(groupID); } } } else { if (state.Accounts.ContainsKey(accountID)) { state.Accounts[accountID] = null; state.AccountGroups[groupID] = null; } else { state.Accounts.Add(accountID, null); state.AccountGroups.Add(groupID, null); } } }