コード例 #1
0
        private IEnumerable <BaseRow> GetGenericResponse(O2GTablesUpdatesReader reader)
        {
            var rows = new List <BaseRow>();

            for (var i = 0; i < reader.Count; i++)
            {
                var type = reader.getUpdateTable(i);

                BaseRow row = null;

                switch (type)
                {
                case O2GTableType.Accounts:
                {
                    // AccountRowEx - so we can get hold of O2GAccountRow internally when needed.
                    row = this.GetRow <AccountRowEx, O2GAccountRow>(reader.getAccountRow(i));
                    break;
                }

                case O2GTableType.ClosedTrades:
                {
                    row = this.GetRow <ClosedTradeRow, O2GClosedTradeRow>(reader.getClosedTradeRow(i));
                    break;
                }

                case O2GTableType.Messages:
                {
                    row = this.GetRow <MessageRow, O2GMessageRow>(reader.getMessageRow(i));
                    break;
                }

                case O2GTableType.Offers:
                {
                    row = this.GetRow <OfferRow, O2GOfferRow>(reader.getOfferRow(i));
                    break;
                }

                case O2GTableType.Orders:
                {
                    row = this.GetRow <OrderRow, O2GOrderRow>(reader.getOrderRow(i));
                    break;
                }

                case O2GTableType.Trades:
                {
                    row = this.GetRow <TradeRow, O2GTradeRow>(reader.getTradeRow(i));
                    break;
                }
                }

                if (row != null)
                {
                    row.UpdateType = ConvertersInternal.GetUpdateType(reader.getUpdateType(i));
                    rows.Add(row);
                }
            }

            return(rows);
        }
コード例 #2
0
        /// <summary>
        /// Listener: Forex Connect received update for trading tables.
        /// </summary>
        /// <param name="data"></param>
        public void onTablesUpdates(O2GResponse data)
        {
            if (data.Type == O2GResponseType.TablesUpdates)
            {
                if (mOffer == null)
                {
                    return;
                }

                O2GTablesUpdatesReader reader = mSession.getResponseReaderFactory().createTablesUpdatesReader(data);
                for (int i = 0; i < reader.Count; i++)
                {
                    // We are looking only for updates and only for offers

                    // NOTE: in order to support offer subscribtion, the real application also will need
                    // to read add/remove events and change the offer collection correspondingly
                    if (reader.getUpdateType(i) == O2GTableUpdateType.Update &&
                        reader.getUpdateTable(i) == O2GTableType.Offers)
                    {
                        // read the offer update
                        O2GOfferRow row = reader.getOfferRow(i);

                        if (!row.isInstrumentValid)
                        {
                            continue;
                        }

                        if (!mInstrument.Equals(row.Instrument))
                        {
                            continue;
                        }

                        // update latest offer
                        if (row.isTimeValid)
                        {
                            mOffer.LastUpdate = row.Time;
                        }
                        if (row.isBidValid)
                        {
                            mOffer.Bid = row.Bid;
                        }
                        if (row.isAskValid)
                        {
                            mOffer.Ask = row.Ask;
                        }
                        if (row.isVolumeValid)
                        {
                            mOffer.MinuteVolume = row.Volume;
                        }

                        // please note that we send a clone of the offer,
                        // we need it in order to make sure that no ticks
                        // will be lost, if, for example, subscriber doesn't handle the
                        // offer immideatelly
                        if (OnPriceUpdate != null)
                        {
                            OnPriceUpdate(mOffer.Clone());
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Listener: Forex Connect received update for trading tables
        /// </summary>
        /// <param name="data"></param>
        public void onTablesUpdates(O2GResponse data)
        {
            if (data.Type == O2GResponseType.TablesUpdates)
            {
                O2GTablesUpdatesReader reader = mTradingSession.getResponseReaderFactory().createTablesUpdatesReader(data);
                for (int i = 0; i < reader.Count; i++)
                {
                    // We are looking only for updates and only for offers

                    // NOTE: in order to support offer subscribtion, the real application also will need
                    // to read add/remove events and change the offer collection correspondingly
                    if (reader.getUpdateType(i) == O2GTableUpdateType.Update &&
                        reader.getUpdateTable(i) == O2GTableType.Offers)
                    {
                        // read the offer update
                        O2GOfferRow row = reader.getOfferRow(i);
                        Offer       offer;
                        // find the offer in our list either by the instrument name or
                        // by the offer id
                        string id = null;
                        if (row.isInstrumentValid)
                        {
                            id = row.Instrument;
                        }
                        else if (row.isOfferIDValid)
                        {
                            id = row.OfferID;
                        }

                        if (id == null)
                        {
                            continue;
                        }

                        offer = mOffers[id];
                        if (offer == null)
                        {
                            continue;
                        }

                        // if we have that offer - update it
                        if (row.isTimeValid)
                        {
                            offer.LastUpdate = row.Time;
                        }
                        if (row.isBidValid)
                        {
                            offer.Bid = row.Bid;
                        }
                        if (row.isAskValid)
                        {
                            offer.Ask = row.Ask;
                        }
                        if (row.isVolumeValid)
                        {
                            offer.MinuteVolume = row.Volume;
                        }

                        // please note that we send a clone of the offer,
                        // we need it in order to make sure that no ticks
                        // will be lost, if, for example, subscriber doesn't handle the
                        // offer immideatelly
                        if (OnPriceUpdate != null)
                        {
                            OnPriceUpdate(offer.Clone());
                        }
                    }
                }
            }
        }