public static byte[] GetDataForCommand(Token token, TraderState state, Command command)
 {
     if (string.IsNullOrEmpty(state.QuotationFilterSign))
     {
         return null;
     }
     return GetDataBytesInUtf8Format(token, state, command);
 }
 public static byte[] GetPriceInBytes(Token token,TraderState state,QuotationCommand command,int beginSequence,int endSequence)
 {
     if (token.AppType == AppType.TradingConsole)
     {
         return GetDataIn4BitFormat(state, command,beginSequence,endSequence);
     }
     return GetDataInGeneralFormat(token, state, command,beginSequence,endSequence);
 }
        public TraderState GetTokenAndState(Session session, out Token token)
        {
            token = null;
            this._TokenDict.TryGetValue(session, out token);
            TraderState state = null;

            this._TradingConsoleStateDict.TryGetValue(session, out state);
            return(state);
        }
 private static byte[] GetDataBytesInUtf8Format(Token token, TraderState state, Command command)
 {
     var node = ConvertCommand(token, state, command);
     if (node == null)
     {
         return null;
     }
     string xml = node.OuterXml;
     return string.IsNullOrEmpty(xml) ? null : PacketConstants.ContentEncoding.GetBytes(xml);
 }
 public byte[] GetPriceInBytes(Token token,TraderState state)
 {
     byte[] price;
     ConcurrentDictionary<long,byte[]>  dict;
     if (!this._PriceCache.TryGetValue(token.AppType, out dict))
     {
         dict = new ConcurrentDictionary<long, byte[]>();
         this._PriceCache.TryAdd(token.AppType,dict);
     }
     if (dict.TryGetValue(state.SignMapping, out price))
     {
         return price;
     }
     if (token.AppType == AppType.TradingConsole)
     {
         price = GetDataIn4BitFormat(state,this._QuotationCommand);
     }
     else
     {
         price = GetDataInGeneralFormat(token, state,this._QuotationCommand);
     }
     dict.TryAdd(state.SignMapping, price);
     return price;
 }
 public void AddTradingConsoleState(Session session, TraderState state)
 {
     AddCommon(session, state, this._TradingConsoleStateDict);
 }
 private static byte[] GetDataInGeneralFormat(Token token, TraderState state,QuotationCommand command,int? beginSequence=null,int? endSequence=null)
 {
     XmlDocument xmlDoc = new XmlDocument();
     XmlElement commands = xmlDoc.CreateElement("Commands");
     xmlDoc.AppendChild(commands);
     XmlNode commandNode = command.ToXmlNode(token, state);
     if (commandNode == null)
     {
         return null;
     }
     XmlNode commandNode2 = commands.OwnerDocument.ImportNode(commandNode, true);
     commands.AppendChild(commandNode2);
     commands.SetAttribute("FirstSequence", (beginSequence ?? command.Sequence).ToString());
     commands.SetAttribute("LastSequence", (endSequence ?? command.Sequence).ToString());
     return PacketConstants.ContentEncoding.GetBytes(commands.OuterXml);
 }
 private static byte[] GetDataIn4BitFormat(TraderState state,QuotationCommand command,int? beginSequence=null,int? endSequence=null)
 {
     var stringBuilder = new StringBuilder(CAPACITY);
     string seqenceStr = string.Format("{0}{1}{2}", (beginSequence ?? command.Sequence), _SequenceSeparator, (endSequence ?? command.Sequence));
     stringBuilder.Append(seqenceStr);
     stringBuilder.Append(_StartSeparator);
     OverridedQuotation[] overridedQuotations = command.OverridedQs;
     if (overridedQuotations != null && overridedQuotations.Length > 0)
     {
         for (int i = 0; i < overridedQuotations.Length; i++)
         {
             OverridedQuotation overridedQuotation = overridedQuotations[i];
             if (!state.InstrumentsView.ContainsKey(overridedQuotation.InstrumentID))
             {
                 continue;
             }
             if (overridedQuotation.QuotePolicyID != state.InstrumentsView[overridedQuotation.InstrumentID])
             {
                 continue;
             }
             if (i != 0)
             {
                 stringBuilder.Append(_OutterSeparator);
             }
             AppendQuotationParts(stringBuilder, overridedQuotation);
         }
     }
     stringBuilder.Append(_StartSeparator);
     return Quotation4BitEncoder.Encode(stringBuilder.ToString());
 }
Exemple #9
0
 private DataSet InternalGetQuotePolicyDetailsAndRefreshInstrumentsState(Session session,Guid customerID)
 {
     DataSet dataSet = Application.Default.TradingConsoleServer.GetQuotePolicyDetails(customerID);
     TraderState state = SessionManager.Default.GetTradingConsoleState(session);
     Application.Default.TradingConsoleServer.RefreshInstrumentsState2(dataSet, ref state, session.ToString());
     if (state == null) return dataSet;
     TraderState traderState = new TraderState(state);
     traderState.CaculateQuotationFilterSign();
     SessionManager.Default.AddTradingConsoleState(session, traderState);
     return dataSet;
 }
Exemple #10
0
        //no use
        public XmlNode GetParameterForJava(Session  session,string companyCode, string version)
        {
            //Get xml
            try
            {
                string physicalPath = SettingManager.Default.PhysicPath + "\\" + companyCode + "\\" + version + "\\";
                string xmlPath = physicalPath + "Setting\\Parameter.xml";
                var doc = new System.Xml.XmlDocument();
                doc.Load(xmlPath);
                xmlPath = physicalPath + "Setting\\Login.xml";
                var doc2 = new System.Xml.XmlDocument();
                doc2.Load(xmlPath);
                var node2 = doc2.GetElementsByTagName("Login")[0];

                var parameterXmlNode = doc.GetElementsByTagName("Parameter")[0];

                string newsLanguage = node2.SelectNodes("NewsLanguage").Item(0).InnerXml;
                TraderState state = SessionManager.Default.GetTradingConsoleState(session);
                if (state == null)
                {
                    state = new TraderState(session.ToString());
                }
                state.Language = newsLanguage.ToLower();
                SessionManager.Default.AddTradingConsoleState(session, state);
                XmlElement newChild = doc.CreateElement("NewsLanguage");
                newChild.InnerText = newsLanguage;
                parameterXmlNode.AppendChild(newChild);
                var node = doc.GetElementsByTagName("Parameters")[0];
                return node;
            }
            catch (System.Exception ex)
            {
                _Logger.Error(ex);
                return null;
            }
        }
 public void UpdateInstrumentSetting(DataSet instruments, string[] instrumentIDs, TraderState state)
 {
     DataRowCollection rows;
     if (instrumentIDs.Length <= 0)
     {
         state.ClearInstrumentQuotePolicyIdMapping();
     }
     else
     {
         List<Guid> notExistKeys = state.InstrumentsView.GetKeys().Where(key => !instrumentIDs.Contains(key.ToString())).ToList();
         foreach(var key in notExistKeys)
         {
             state.RemoveInstrumentIDToQuotePolicyMapping(key);
         }
         if (instruments != null && instruments.Tables.Count > 0)
         {
             rows = instruments.Tables["Instrument"].Rows;
             foreach (DataRow instrumentRow in rows)
             {
                 if (!state.InstrumentsView.ContainsKey((Guid)instrumentRow["ID"]))
                 {
                     state.AddInstrumentIDToQuotePolicyMapping((Guid)instrumentRow["ID"], (Guid)instrumentRow["QuotePolicyID"]);
                 }
             }
         }
     }
 }
        public void RefreshInstrumentsState2(DataSet dataSet, ref TraderState state2, string sessionId)
        {
            TraderState state = state2 ?? new TraderState(sessionId);
            if (state.InstrumentsView.Count > 0)
            {
                state.InstrumentsView.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.InstrumentsView.Add((Guid)quotePolicyDetailRow["InstrumentID"], (Guid)quotePolicyDetailRow["QuotePolicyID"]);
                    if (quotePolicyInfo.Length > 0) quotePolicyInfo.Append(";");
                    quotePolicyInfo.Append(quotePolicyDetailRow["InstrumentID"]);
                    quotePolicyInfo.Append("=");
                    quotePolicyInfo.Append(quotePolicyDetailRow["QuotePolicyID"]);
                }
            }
            state2 = state;
        }