Ejemplo n.º 1
0
        private void DMUpdateInternationalLong(object sender, AxDBCCTRLLib._IDataManagerEvents_UpdateInternationalLongEvent e)
        {
            //Debug.WriteLine("UPDATE SYMBOL!");
            // build a StockInfo object for the update event
            StockInfo stockInfo = new StockInfo();

            // symbol
            stockInfo.Symbol = e.symbol;

            // TODO: Do we care about category?  e.il.cat?

            // time
            if (e.il.MonthUpdate != null)
            {
                string t = e.il.MonthUpdate.ToString() + "/" + e.il.DayUpdate.ToString() + "/" +
                           e.il.YearUpdate.ToString() + " " + Convert.ToSByte(e.il.HourUpdate).ToString() + ":" +
                           e.il.MinuteUpdate.ToString() + ":" + e.il.SecondUpdate.ToString();
                DateTime tDate = Convert.ToDateTime(t);
                stockInfo.LastTime = DataManager.UTCToLocalTime(tDate);
            }

            if (e.il.Last != null)
            {
                stockInfo.LastPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.Last), Convert.ToInt16(e.il.Base));
            }

            if (e.il.Bid != null)
            {
                stockInfo.BidPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.Bid), Convert.ToInt16(e.il.Base));
            }

            if (e.il.BidSize != null)
            {
                stockInfo.BidSize = Convert.ToUInt32(e.il.BidSize);
            }

            if (e.il.BidExg != null)
            {
                stockInfo.BidExchange = e.il.BidExg.ToString();
            }

            if (e.il.Ask != null)
            {
                stockInfo.AskPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.Ask), Convert.ToInt16(e.il.Base));
            }

            if (e.il.AskSize != null)
            {
                stockInfo.AskSize = Convert.ToUInt32(e.il.AskSize);
            }

            if (e.il.AskExg != null)
            {
                stockInfo.AskExchange = e.il.AskExg.ToString();
            }

            if (e.il.High != null)
            {
                stockInfo.HighPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.High), Convert.ToInt16(e.il.Base));
            }

            if (e.il.Low != null)
            {
                stockInfo.LowPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.Low), Convert.ToInt16(e.il.Base));
            }

            if (e.il.Open != null)
            {
                stockInfo.OpenPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.Open), Convert.ToInt16(e.il.Base));
            }

            if (e.il.Prev != null)
            {
                stockInfo.PreviousPrice = dataManager.BLToDouble(Convert.ToInt32(e.il.Prev), Convert.ToInt16(e.il.Base));
            }

            if (e.il.TradeVol != null)
            {
                stockInfo.TradeVolume = Convert.ToUInt32(e.il.TradeVol.ToString());
            }

            if (e.il.TradeExg != null)
            {
                stockInfo.TradeExchange = e.il.TradeExg.ToString();
            }

            if (e.il.TotalVol != null)
            {
                stockInfo.TotalVolume = Convert.ToUInt32(e.il.TotalVol);
            }

            // call our wrapped event handler
            DMUpdateSymbolArgs args = new DMUpdateSymbolArgs(stockInfo);

            if (OnUpdateSymbolDM != null)
            {
                OnUpdateSymbolDM(this, args);
            }
        }
Ejemplo n.º 2
0
 public DMUpdateSymbolArgs(StockInfo stockInfo)
 {
     this.stockInfo = stockInfo;
 }
Ejemplo n.º 3
0
        public static void OnUpdateSymbolDM(object wrapper, DMUpdateSymbolArgs args)
        {
            // StockInfo object holding the new symbol data for this update
            StockInfo stockInfo = args.stockInfo;

            try
            {
                // Lock the tables.
                Debug.Assert(!ServerMarketData.IsLocked);
                ServerMarketData.EquityLock.AcquireReaderLock(Timeout.Infinite);
                ServerMarketData.PriceLock.AcquireWriterLock(Timeout.Infinite);
                ServerMarketData.SecurityLock.AcquireReaderLock(Timeout.Infinite);

                // make sure the symbol is in the hash table - and that we added it to the data manager
                if (!symbolToSecurityIdTable.ContainsKey(stockInfo.Symbol))
                {
                    throw new Exception("Received update for unknown symbol: " + stockInfo.Symbol);
                }

                // get the security id of the symbol
                int securityID = (int)symbolToSecurityIdTable[stockInfo.Symbol];

                // get the security row
                ServerMarketData.SecurityRow securityRow = ServerMarketData.Security.FindBySecurityId(securityID);
                if (securityRow == null)
                {
                    throw new Exception("Warning: Could not find security row for symbol: " + stockInfo.Symbol);
                }

                //int equityId = Security.FindRequiredKey(configurationId, "equityId", externalEquityId);
                // Only Equities are priced by this simulator.  All others are ignored.
                ServerMarketData.EquityRow equityRow = ServerMarketData.Equity.FindByEquityId(securityRow.SecurityId);
                if (equityRow != null)
                {
                    // Find a price that matches the equity's default settlement.  This is the price record that will be updated
                    // with the simulated market conditions.
                    ServerMarketData.PriceRow priceRow = ServerMarketData.Price.FindBySecurityId(securityRow.SecurityId);
                    if (priceRow == null)
                    {
                        priceRow = ServerMarketData.Price.NewPriceRow();
                        //priceRow.RowVersion = ServerMarketData.RowVersion.Increment();
                        priceRow.SecurityId = equityRow.EquityId;
                        priceRow.CurrencyId = equityRow.SettlementId;
                        priceRow.LastPrice  = 0.0M;
                        priceRow.AskPrice   = 0.0M;
                        priceRow.BidPrice   = 0.0M;
                        priceRow.Volume     = 0.0M;
                        priceRow.ClosePrice = 0.0M;
                        priceRow.VolumeWeightedAveragePrice = 0.0M;
                        priceRow.HighPrice = 0.0M;
                        priceRow.LowPrice  = 0.0M;
                        ServerMarketData.Price.AddPriceRow(priceRow);
                    }

                    // set the new values from the real time event into the price row
                    priceRow.BidSize   = stockInfo.BidSize;
                    priceRow.BidPrice  = Convert.ToDecimal(stockInfo.BidPrice);
                    priceRow.AskPrice  = Convert.ToDecimal(stockInfo.AskPrice);
                    priceRow.AskSize   = Convert.ToDecimal(stockInfo.AskSize);
                    priceRow.LastPrice = Convert.ToDecimal(stockInfo.LastPrice);
                    priceRow.LastSize  = stockInfo.TradeVolume;
                    priceRow.Volume    = Convert.ToDecimal(stockInfo.TotalVolume);
                    priceRow.VolumeWeightedAveragePrice = (Convert.ToDecimal(stockInfo.LastPrice) + Convert.ToDecimal(stockInfo.OpenPrice)) / 2;
                    priceRow.OpenPrice  = Convert.ToDecimal(stockInfo.OpenPrice);
                    priceRow.LowPrice   = Convert.ToDecimal(stockInfo.LowPrice);
                    priceRow.HighPrice  = Convert.ToDecimal(stockInfo.HighPrice);
                    priceRow.ClosePrice = Convert.ToDecimal(stockInfo.PreviousPrice);

                    // increment the RowVersion so the client notices!!!
                    priceRow.RowVersion = ServerMarketData.RowVersion.Increment();

                    // commit the changes
                    priceRow.AcceptChanges();
                }
            }
            catch (Exception exception)
            {
                String msg = String.Format("{0}, {1}", exception.Message, exception.StackTrace);

                // Write the error and stack trace out to the debug listener
                //Debug.WriteLine(msg);
                MarkThree.EventLog.Warning(msg);
            }
            finally
            {
                // Release the global tables.
                if (ServerMarketData.EquityLock.IsReaderLockHeld)
                {
                    ServerMarketData.EquityLock.ReleaseReaderLock();
                }
                if (ServerMarketData.PriceLock.IsWriterLockHeld)
                {
                    ServerMarketData.PriceLock.ReleaseWriterLock();
                }
                if (ServerMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ServerMarketData.SecurityLock.ReleaseReaderLock();
                }
                Debug.Assert(!ServerMarketData.IsLocked);
            }
        }