void PostQuoteUpdate(string forexPair, DataTick dataTick)
        {
            RuntimeDataSessionInformation sessionInformation = _dataSourceStub.GetSymbolSessionInformation(new Symbol("Forex", forexPair));

            if (sessionInformation != null &&
                _subscribedSymbols.ContainsKey(forexPair))
            {
                CombinedDataSubscriptionInformation info = _dataSourceStub.GetUnsafeSessionSubscriptions(sessionInformation.Info);

                if (info != null && info.GetCombinedDataSubscription().QuoteSubscription)
                {
                    _dataSourceStub.UpdateQuote(sessionInformation.Info, new Quote(dataTick.Ask, dataTick.Bid, null, dataTick.DateTime), null);
                    foreach (TimeSpan supportedPeriod in DefaultAvailablePeriods)
                    {
                        _dataSourceStub.UpdateDataHistory(sessionInformation.Info, new DataHistoryUpdate(supportedPeriod, new DataTick[] { dataTick }));
                    }
                }
            }
        }
        public void tdSink_ITradeDeskEvents_Event_OnRowChanged(object tableDisp, string rowID)
        {
            if (_manager.LoggedIn)
            {
                try
                {
                    FXCore.ITableAut t = (FXCore.ITableAut)tableDisp;

                    if ("offers".Equals(t.Type))
                    {
                        DataTick dataTick = new DataTick();
                        TableAut offersTable = (TableAut)_manager.Desk.FindMainTable("offers");

                        RowAut instrumentRow = (RowAut)offersTable.FindRow("OfferID", rowID, 0);
                        dataTick.Ask = (decimal)((double)instrumentRow.CellValue("Ask"));
                        dataTick.Bid = (decimal)((double)instrumentRow.CellValue("Bid"));
                        dataTick.DateTime = (DateTime)instrumentRow.CellValue("Time");

                        PostQuoteUpdate((string)instrumentRow.CellValue("Instrument"), dataTick);

                        // TODO: this may be way too often, since it will update on each tick of any symbol...
                        // Also update the accounts informations.
                        foreach (AccountInfo accountInfo in _manager.Orders.GetAvailableAccounts())
                        {
                            _orderExecutionStub.UpdateAccountInfo(accountInfo);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    SystemMonitor.Error(ex.ToString());
                }
            }
        }
        public double[] GetValuesAsDouble(DataTick.DataValueEnum valueEnum, int startingIndex, int indexCount)
        {
            double[] result;
            lock (this)
            {
                int count = indexCount;
                if (count == 0)
                {
                    count = _dataTicks.Count - startingIndex;
                    GeneralHelper.Verify(count >= 0, "Invalid starting index.");
                }

                result = new double[Math.Min(count, _dataTicks.Count)];
                {
                    for (int i = startingIndex; i < startingIndex + count && i < _dataTicks.Count; i++)
                    {
                        result[i - startingIndex] = (double)_dataTicks[i].GetValue(valueEnum);
                    }
                }
            }

            return result;
        }
 public double[] GetValuesAsDouble(DataTick.DataValueEnum valueEnum)
 {
     return GetValuesAsDouble(valueEnum, 0, int.MaxValue);
 }
 public decimal[] GetValues(DataTick.DataValueEnum valueEnum)
 {
     return GetValues(valueEnum, 0, int.MaxValue);
 }
        /// <summary>
        /// Managed thread entrance only.
        /// </summary>
        void Managed_tdSink_ITradeDeskEvents_Event_OnRowChanged(object tableDisp, string rowID)
        {
            if (LoggedIn)
            {
                TradeDeskAut desk = _desk;
                if (desk == null)
                {
                    return;
                }

                try
                {
                    FXCore.ITableAut t = (FXCore.ITableAut)tableDisp;
                    if ("offers".Equals(t.Type))
                    {
                        TableAut offersTable = (TableAut)desk.FindMainTable("offers");
                        RowAut instrumentRow = (RowAut)offersTable.FindRow("OfferID", rowID, 0);

                        DataTick dataTick = new DataTick();
                        dataTick.Ask = (decimal)((double)instrumentRow.CellValue("Ask"));
                        dataTick.Bid = (decimal)((double)instrumentRow.CellValue("Bid"));
                        dataTick.DateTime = (DateTime)instrumentRow.CellValue("Time");

                        QuoteUpdateDelegate delegateInstance = QuoteUpdatedEvent;
                        if (delegateInstance != null)
                        {
                            GeneralHelper.FireAndForget(delegateInstance, this, (string)instrumentRow.CellValue("Instrument"), dataTick);
                        }
                    }
                    else if ("orders".Equals(t.Type))
                    {
                        // Orders table empty?
                        //TableAut offersTable = (TableAut)desk.FindMainTable("orders");
                        //RowAut instrumentRow = (RowAut)offersTable.FindRow("OrderID", rowID, 0);

                        //string accountId;
                        //OrderInfo? info = Managed_ExtractOrderInfo(instrumentRow, out accountId);

                        //OrderUpdateDelegate delegateInstance = OrderUpdatedEvent;
                        //if (info.HasValue && delegateInstance != null)
                        //{
                        //    GeneralHelper.FireAndForget(delegateInstance, this, accountId, info.Value);
                        //}
                    }
                    else if ("accounts".Equals(t.Type))
                    {
                        ItemUpdateDelegate delegateInstance = AccountUpdatedEvent;
                        if (delegateInstance != null)
                        {
                            GeneralHelper.FireAndForget(delegateInstance, this, rowID);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    SystemMonitor.Error("Failed to handle OnRow event", ex);
                }
            }
        }