示例#1
0
        public void SetAttributes(Dictionary <string, string> attributes)
        {
            double         x;
            InstrumentName name;

            foreach (string key in attributes.Keys)
            {
                if (key.Equals("InstrumentName") && InstrumentName.TryDeserialize(attributes[key], out name))
                {
                    this.m_Name = name;
                }
                else if (key.Equals("CurrencyName") && !string.IsNullOrEmpty(attributes[key]))
                {
                    this.CurrencyName = attributes[key];
                }
                else if (key.Equals("RealGain") && Double.TryParse(attributes[key], out x))
                {
                    this.m_RealizedGain = x;
                }
                else if (key.Equals("RealStartingGain") && Double.TryParse(attributes[key], out x))
                {
                    this.m_RealizedStartingGain = x;
                }
                else if (key.Equals("CurrencyRate") && Double.TryParse(attributes[key], out x))
                {
                    this.CurrencyRate = x;
                }
            }
        }
示例#2
0
        public void SetAttributes(Dictionary <string, string> attributes)
        {
            double         x;
            bool           b;
            InstrumentName newInstr;

            foreach (KeyValuePair <string, string> attr in attributes)
            {
                if (attr.Key == "InstrumentName" && InstrumentName.TryDeserialize(attr.Value, out newInstr))
                {
                    this.InstrumentName = newInstr;
                }
                else if (attr.Key == "PriceMultiplier" && double.TryParse(attr.Value, out x))
                {
                    this.PriceMultiplier = x;
                }
                else if (attr.Key == "Weight" && double.TryParse(attr.Value, out x))
                {
                    this.Weight = x;
                }
                else if (attr.Key == "IsPriceEngineLeg" && bool.TryParse(attr.Value, out b))
                {
                    this.IsPriceEngineLeg = b;
                }
                else if (attr.Key == "UserTag")
                {
                    this.UserTag = attr.Value;
                }
            }
        }
示例#3
0
        //
        //
        //
        /// <summary>
        /// Convert instrument name to instrument data base name.
        /// </summary>
        /// <param name="instrumentName"></param>
        /// <param name="instrumentNameDatabase"></param>
        /// <returns></returns>
        public static bool TryConvertInstrumentNameToInstrumentNameDatabase(string instrumentFullName, LogHub log, out string instrumentNameDatabase)
        {
            bool isSuccess = false;

            instrumentNameDatabase = null;
            InstrumentName instrumentName;

            if (InstrumentName.TryDeserialize(instrumentFullName, out instrumentName))
            {
                if (TryConvertInstrumentNameToInstrumentNameDatabase(instrumentName, log, out instrumentNameDatabase))
                {
                    isSuccess = true;
                }
                else
                {
                    log.NewEntry(LogLevel.Error, "Failed to convert instrument to instrument database name for string {0}.", instrumentName);
                    return(isSuccess);
                }
            }
            else
            {
                log.NewEntry(LogLevel.Error, "Failed to deserialize instrument for string {0}.", instrumentFullName);
                return(isSuccess);
            }
            return(isSuccess);
        }
示例#4
0
        //
        //
        #endregion//Constructors


        private void ReadTable()
        {
            // Check whether the file exists, if otherwise, add a file with blank.
            if (!System.IO.File.Exists(this.FilePath))
            {
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.FilePath, true))
                {
                    writer.WriteLine("// END");
                    writer.Close();
                }
            }

            // The above code ensures that the file exists.
            using (System.IO.StreamReader reader = new System.IO.StreamReader(this.FilePath))
            {
                string aLine;
                bool   continueReading = true;
                while (continueReading)
                {
                    aLine = reader.ReadLine();
                    if (aLine == null)
                    {
                        break;
                    }
                    aLine = aLine.Trim();
                    if (string.IsNullOrWhiteSpace(aLine))
                    {
                        continue;                                                              // skip blank lines
                    }
                    if (aLine.StartsWith("// END", StringComparison.CurrentCultureIgnoreCase)) // this signals end of file at the moment.
                    {
                        continueReading = false;
                        continue;
                    }
                    else if (aLine.Contains("//"))
                    {
                        int n = aLine.IndexOf("//");
                        if (n == 0)
                        {
                            continue;
                        }
                        else if (n > 0)
                        {
                            aLine = aLine.Substring(0, n);
                        }
                    }

                    //
                    // Extract table entries
                    //
                    InstrumentName instrumentName;
                    if (InstrumentName.TryDeserialize(aLine.Trim(), out instrumentName))
                    {
                        m_ExceptionList.Add(instrumentName);
                    }
                }
                reader.Close();
            } //wend
        }
示例#5
0
 //
 //
 private void buttonFindResultingInstrument_Click(object sender, EventArgs e)
 {
     if (m_InstrumentMatrix != null)
     {
         ResultingInstrument resultingInstrument;
         InstrumentName      instrumentName1;
         InstrumentName      instrumentName2;
         if (InstrumentName.TryDeserialize(this.textBoxInstrument1.Text, out instrumentName1) &&
             InstrumentName.TryDeserialize(this.textBoxInstrument2.Text, out instrumentName2))
         {
             int filledQty1;
             int filledQty2;
             if (int.TryParse(this.textBoxQty1.Text, out filledQty1) && int.TryParse(this.textBoxQty2.Text, out filledQty2))
             {
                 int resultingQty;
                 int qty1Remaining;
                 int qty2Remaining;
                 if (m_InstrumentMatrix.TryFindResultingInstrument(instrumentName1, filledQty1, instrumentName2, filledQty2,
                                                                   out resultingInstrument, out resultingQty, out qty1Remaining, out qty2Remaining))
                 {
                     this.textBoxResultingInstrument.Text = resultingInstrument.ResultingInstrumentName.FullName;
                     this.textBoxResultingQty.Text        = resultingQty.ToString();
                     this.textBoxQty1Remaining.Text       = qty1Remaining.ToString();
                     this.textBoxQty2Remaining.Text       = qty2Remaining.ToString();
                 }
                 else
                 {
                     this.textBoxResultingInstrument.Text = string.Empty;
                     this.textBoxResultingQty.Text        = string.Empty;
                     this.textBoxQty1Remaining.Text       = string.Empty;
                     this.textBoxQty2Remaining.Text       = string.Empty;
                 }
             }
             else
             {
                 this.textBoxResultingInstrument.Text = string.Empty;
                 this.textBoxResultingQty.Text        = string.Empty;
                 this.textBoxQty1Remaining.Text       = string.Empty;
                 this.textBoxQty2Remaining.Text       = string.Empty;
             }
         }
         else
         {
             this.textBoxResultingInstrument.Text = string.Empty;
             this.textBoxResultingQty.Text        = string.Empty;
             this.textBoxQty1Remaining.Text       = string.Empty;
             this.textBoxQty2Remaining.Text       = string.Empty;
         }
     }
     else
     {
         m_Log.NewEntry(LogLevel.Minor, "Not setup the instrument matrix yet.");
     }
 }
示例#6
0
        public void SetAttributes(Dictionary <string, string> attributes)
        {
            double         x;
            int            n;
            DateTime       dt;
            InstrumentName name;

            foreach (string key in attributes.Keys)
            {
                if (key.Equals("DollarPerPoint") && Double.TryParse(attributes[key], out x))
                {
                    this.m_DollarPerPoint = x;
                }
                else if (key.Equals("SmallestFillPriceIncr") && Double.TryParse(attributes[key], out x))
                {
                    this.m_SmallestFillPriceIncr = x;
                }
                else if (key.Equals("LocalTimeLast") && DateTime.TryParse(attributes[key], out dt))
                {
                    this.LocalTimeLast = dt;
                }
                else if (key.Equals("ExchangeTimeLast") && DateTime.TryParse(attributes[key], out dt))
                {
                    this.ExchangeTimeLast = dt;
                }
                else if (key.Equals("InstrumentName") && InstrumentName.TryDeserialize(attributes[key], out name))
                {
                    this.Name = name;
                }
                else if (key.Equals("CurrencyName") && !string.IsNullOrEmpty(attributes[key]))
                {
                    this.m_CurrencyName = attributes[key];
                }
                else if (key.Equals("RealGain") && Double.TryParse(attributes[key], out x))
                {
                    this.m_RealizedGain = x;
                }
                else if (key.Equals("RealStartingGain") && Double.TryParse(attributes[key], out x))
                {
                    this.m_RealizedStartingGain = x;
                }
                else if (key.Equals("Volume") && int.TryParse(attributes[key], out n))
                {
                    this.m_Volume = n;
                }
                else if (key.Equals("StartingVolume") && int.TryParse(attributes[key], out n))
                {
                    this.m_StartingVolume = n;
                }
            }
        }
示例#7
0
        // *****************************************************************
        // ****                     Properties                          ****
        // *****************************************************************
        //
        //
        #endregion//Properties


        #region no Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        //
        //
        //
        //
        #endregion//Public Methods


        #region Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        private void buttonStart_Click(object sender, EventArgs e)
        {
            m_HedgeOptionsWriter        = new HedgeOptionsWriter(m_Log);
            m_InstrumentExistInDatabase = new List <InstrumentName>();
            m_InstrumentPendingWriting  = new List <InstrumentName>();
            m_BREInstrumentInfoItems    = new Dictionary <InstrumentName, InstrumentInfoItem>();

            // Generate query to get all instruments from the data base.
            InstrumentInfoQuery BREInstrumentInfoQuery = new InstrumentInfoQuery();
            ProductTypes        productTypes;

            if (Enum.TryParse <ProductTypes>(textBoxProductType.Text, out productTypes))
            {
                m_Product = new Product(textBoxExchangeName.Text, textBoxProductName.Text, productTypes);
                BREInstrumentInfoQuery.InstrumentName = new InstrumentName(m_Product, string.Empty);
                BREInstrumentInfoQuery.IsRead         = true;
                BREInstrumentInfoQuery.Status         = QueryStatus.New;
            }
            else
            {
                m_Log.NewEntry(LogLevel.Error, "Product type parse failed");
                return;
            }

            // Submit query and store existing instruments from the data base.
            m_DatabaseReaderWriter.SubmitSync(BREInstrumentInfoQuery);
            List <InstrumentInfoItem> BREInstrumentInfoItems = BREInstrumentInfoQuery.Results;

            foreach (InstrumentInfoItem BREInstrumentInfoItem in BREInstrumentInfoItems)
            {
                if (m_BREInstrumentInfoItem == null)
                {
                    m_BREInstrumentInfoItem = BREInstrumentInfoItem;                                // Need one of this only.
                }
                string         instrumentNameString = BREInstrumentInfoItem.InstrumentNameTT;
                InstrumentName instrumentName;
                if (instrumentNameString != null && InstrumentName.TryDeserialize(instrumentNameString, out instrumentName))
                {
                    m_InstrumentExistInDatabase.Add(instrumentName);
                    m_BREInstrumentInfoItems.Add(instrumentName, BREInstrumentInfoItem);
                }
            }

            // Launch market instruments request.
            m_Market.RequestProducts(new List <Product>()
            {
                m_Product
            });
            m_Market.RequestInstruments(m_Product);
        }
示例#8
0
        public void SetAttributes(Dictionary <string, string> attributes)
        {
            InstrumentName name;
            InstrumentKey  ttkey;

            foreach (string key in attributes.Keys)
            {
                if (key.Equals("Name") && InstrumentName.TryDeserialize(attributes["Name"], out name))
                {
                    this.Name = name;
                }
                else if (key.Equals("Key") && TTConvertNew.TryCreateInstrumentKey(attributes["Key"], out ttkey))
                {
                    this.Key = ttkey;
                }
            }
        }
        void IStringifiable.SetAttributes(Dictionary <string, string> attributes)
        {
            InstrumentName instr;
            int            n;

            foreach (string key in attributes.Keys)
            {
                if (key.Equals("InstrumentName") && InstrumentName.TryDeserialize(attributes[key], out instr))
                {
                    this.InstrumentName = instr;
                }
                else if (key.Equals("Leading") && int.TryParse(attributes[key], out n))
                {
                    this.LeadingContracts = n;
                }
            }
        }
        public void SetAttributes(Dictionary <string, string> attributes)
        {
            RejectionReason reason;
            InstrumentName  name;

            foreach (string aKey in attributes.Keys)
            {
                if (aKey.Equals("Reason") && Enum.TryParse <RejectionReason>(attributes[aKey], out reason))
                {
                    this.Reason = reason;
                }
                else if (aKey.Equals("Message"))
                {
                    this.Message = attributes[aKey];
                }
                else if (aKey.Equals("InstrumentName") && InstrumentName.TryDeserialize(attributes[aKey], out name))
                {
                    this.m_Name = name;
                }
            }
        }
示例#11
0
        //
        //
        /// <summary>
        /// Creator provides for differnt Topic types, created dynamically based on the
        /// request arguments provided by the user.
        /// </summary>
        /// <returns>A new object that inherits from Topic and TopicBase.</returns>
        public static bool TryCreate(int topicID, string[] args, string currentValue, out Topic newTopic)
        {
            newTopic = null;
            if (args.Length < 2)
            {
                return(false);
            }

            // Determine instrument
            InstrumentName instrument;

            if (!InstrumentName.TryDeserialize(args[0].Trim(), out instrument))
            {
                return(false);
            }


            // Determine subscription type.
            SubscriptionType type;

            if (!Enum.TryParse <SubscriptionType>(args[1].Trim(), out type))
            {
                return(false);
            }

            // Create the object now, and exit.
            newTopic            = new Topic(topicID, args, currentValue);
            newTopic.Instrument = instrument;
            newTopic.Type       = type;

            // Add optional arguments
            if (args.Length > 2)
            {
                newTopic.HubName = args[2];
            }

            return(true);
        }// Create()
示例#12
0
        // *****************************************************************
        // ****                     Properties                          ****
        // *****************************************************************
        //
        //
        #endregion//Properties


        #region no Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        //
        //
        //
        //
        #endregion//Public Methods


        #region no Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        #endregion//Private Methods


        #region Event Handlers
        // *****************************************************************
        // ****                     Event Handlers                     ****
        // *****************************************************************
        //
        //
        private void buttonSetupInstrumentMatrix_Click(object sender, EventArgs e)
        {
            // Process clicks of buttons.
            m_HedgeOptionsReader    = new HedgeOptionsReader(m_Log);
            m_InstrumentNames       = new List <InstrumentName>();
            m_InstrumentNameStrings = new List <string>();

            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep14:-1xDec14");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec14:-1xMar15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar15:-1xJun15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun15:-1xSep15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep15:-1xDec15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec15:-1xMar16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar16:-1xJun16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun16:-1xSep16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep16:-1xDec16");

            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep14:-1xMar15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec14:-1xJun15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar15:-1xSep15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun15:-1xDec15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep15:-1xMar16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec15:-1xJun16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar16:-1xSep16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun16:-1xDec16");

            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep14:-1xJun15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec14:-1xSep15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar15:-1xDec15");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun15:-1xMar16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep15:-1xJun16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec15:-1xSep16");
            m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar16:-1xDec16");

            foreach (string instrumentString in m_InstrumentNameStrings)
            {
                InstrumentInfoQuery BREInstrumentInfoQuery = new InstrumentInfoQuery();
                InstrumentName      instrumentName;
                if (InstrumentName.TryDeserialize(instrumentString, out instrumentName))
                {
                    m_InstrumentNames.Add(instrumentName);
                    BREInstrumentInfoQuery.InstrumentName = instrumentName;
                    BREInstrumentInfoQuery.IsRead         = true;
                    BREInstrumentInfoQuery.Status         = QueryStatus.New;
                    m_DatabaseReaderWriter.SubmitSync(BREInstrumentInfoQuery);
                    m_HedgeOptionsReader.TryReadHedgeOptionsInformation(BREInstrumentInfoQuery);
                }
                else
                {
                    return;
                }
            }

            Dictionary <InstrumentName, HedgeOptions> hedgeOptionsByInstrument = m_HedgeOptionsReader.GetHedgeOptionsByInstrumentName();

            m_InstrumentMatrix = new InstrumentMatrix(m_InstrumentNames, m_Log);
            if (m_InstrumentMatrix.TrySetupInstrumentMatrix(hedgeOptionsByInstrument))
            {
                m_Log.NewEntry(LogLevel.Minor, "Successfully setup the instrument matrix.");
                ProcessShowData();
            }
        }
示例#13
0
        }//ReadNodesFromFile()

        //
        //
        //
        //
        /// <summary>
        /// This method has the task of analyzing each node, and adding fills to the series, OR
        /// when FillBooks are encountered, test for self-consistency.
        /// If we can't identify whose event it is, flag it as don't consume, and leave it in the list.
        /// The method is called each time a new drop file is read, and the resulting nodes are passed in.
        /// The method can be called when a file at the end is read (then we want to append nodes) or prior
        /// to the beginning files (which is an insert).  The flag needs to be set to "insert".
        /// </summary>
        /// <param name="isInsert">true to insert, and false to append (default)</param>
        /// <param name="rawNodeList"></param>
        private void AddToEventSeries(ref List <Node> rawNodeList, bool isInsert = false)
        {
            //
            // Separate all the nodes according to their InstrumentNames
            //
            Dictionary <InstrumentName, List <Node> > masterNodeList = new Dictionary <InstrumentName, List <Node> >();
            InstrumentName name            = new InstrumentName();
            bool           consumeThisNode = false;
            int            ptr             = 0;

            while (ptr < rawNodeList.Count)
            {
                Node aNode = rawNodeList[ptr];
                if (aNode.Name.Contains("FillEventArgs"))
                {
                    if (m_KeyToName.TryGetValue(aNode.Attributes["InstrumentKey"], out name)) // determine which Instrument was filled.
                    {
                        consumeThisNode = true;                                               // If we recognize the instrument, we can accept this FillEventArgs.
                    }
                    else
                    {
                        consumeThisNode = false;
                    }
                }
                else if (aNode.Name.Contains("BookLifo"))
                {
                    if (InstrumentName.TryDeserialize(aNode.Attributes["InstrumentName"], out name) && m_KeyToName.ContainsValue(name))
                    {
                        consumeThisNode = true;                             // consume only those books for which we have a Key mapping.
                    }
                    else
                    {
                        consumeThisNode = false;
                    }
                }
                else
                {
                    consumeThisNode = false;
                }
                //
                // Consume this node, or not.
                //
                if (consumeThisNode)
                {
                    if (!masterNodeList.ContainsKey(name))
                    {
                        masterNodeList.Add(name, new List <Node>());         // Create a new entry for this instrument.
                    }
                    masterNodeList[name].Add(aNode);
                    rawNodeList.RemoveAt(ptr);                              // this node was processed, remove it from list.
                }
                else
                {
                    ptr++;                                                  // leave unprocessed node in the list, move to next one.
                }
            }// while nodes remain to process.

            //
            // Load new EventSeries objects
            //
            foreach (InstrumentName aName in masterNodeList.Keys)
            {
                if (!SeriesList.ContainsKey(aName))
                {
                    SeriesList.Add(aName, new EventSeries(aName));           // Create a new series.
                }
                if (isInsert)
                {
                    SeriesList[aName].Insert(masterNodeList[aName]);
                }
                else
                {
                    SeriesList[aName].Append(masterNodeList[aName]);            // load all the events.
                }
                masterNodeList[aName].Clear();
            }// aName

            //
            // Save all the nodes we could not process.
            // These are usually nodes for instruments that are unknown to us.
            // TODO: How can we add these when we discover (by reading a different file)?
            if (rawNodeList.Count > 0)
            {
                if (isInsert)
                {
                    m_UnProcessedNodes.InsertRange(0, rawNodeList);
                }
                else
                {
                    m_UnProcessedNodes.AddRange(rawNodeList);
                }
            }
        }// ValidateNodes()
示例#14
0
        }// TryGetAllUserNames()

        //
        //
        //
        //
        //
        //
        #endregion//Public Static Methods



        #region Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        //
        //
        // ****                  ReadNodesFromFile()                    ****
        /// <summary>
        /// Reads nodes from file associate with fileIndex.
        /// Some nodes (such as FillHubs) are exploded and their components are added to the list.
        /// </summary>
        private List <Node> ReadNodesFromFile(int fileIndex)
        {
            List <Node> nodeList = new List <Node>();

            Misty.Lib.IO.Xml.StringifiableReader   reader   = new Misty.Lib.IO.Xml.StringifiableReader(m_Files.Values[fileIndex]);
            List <Misty.Lib.IO.Xml.IStringifiable> iStrList = reader.ReadToEnd(true);   // Load stringifiable objects in there.

            foreach (IStringifiable istr in iStrList)                                   // loop thru each, storing those of interest.
            {
                Node aNode = (Node)istr;
                if (aNode.Name.Contains("FillHub"))
                {                                                               // We don't add FillHubs directly, but do add some of their elements (BookLifo objects for example).
                    foreach (IStringifiable iStrElement in aNode.GetElements()) // loop thru elements of the FillHub.
                    {
                        Node element = (Node)iStrElement;
                        if (element.Name.Contains("InstrumentMapEntry"))
                        {
                            string         sKey;
                            InstrumentName name;
                            if (element.Attributes.TryGetValue("Key", out sKey) && !m_KeyToName.ContainsKey(sKey) && InstrumentName.TryDeserialize(element.Attributes["Name"], out name))
                            {
                                m_KeyToName.Add(sKey, name);
                            }
                        }
                        else if (element.Name.Contains("BookLifo"))
                        {
                            nodeList.Add(element);
                        }
                    } // next element in FillHub.
                }
                else
                {
                    nodeList.Add(aNode);                                                // add everything else to the list.
                }
            }
            return(nodeList);
        }//ReadNodesFromFile()