void ReadSnapshot(string requestId, O2GResponse response)
        {
            TransportHistoryRequest request = null;

            mHistoryRequests.TryGetValue(requestId, out request);
            if (request != null)
            {
                O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();
                if (factory != null)
                {
                    O2GMarketDataSnapshotResponseReader reader   = factory.createMarketDataSnapshotReader(response);
                    ITransportHistoryReader             consumer = request.Reader;
                    for (int i = 0; i < reader.Count; i++)
                    {
                        //mTimeConverter.convert(reader.getDate(i), O2GTimeConverterTimeZone.UTC, mTimezone)
                        DateTime dt = reader.getDate(i);
                        consumer.onHistoryRow(requestId, dt,
                                              reader.getBidOpen(i), reader.getBidHigh(i), reader.getBidLow(i), reader.getBidClose(i),
                                              reader.getAskOpen(i), reader.getAskHigh(i), reader.getAskLow(i), reader.getAskClose(i),
                                              reader.getVolume(i), i);
                    }
                    //mTimeConverter.convert(reader.getLastBarTime(), O2GTimeConverterTimeZone.UTC, mTimezone)
                    DateTime dt1 = reader.getLastBarTime();
                    consumer.setLastBar(dt1, reader.getLastBarVolume());
                    mHistoryRequests.Remove(requestId);
                }
            }
        }
        /// <summary>
        /// Sends a request for the history
        /// </summary>
        public string RequestHistory(TransportHistoryRequest request)
        {
            O2GRequestFactory      factory    = mSession.getRequestFactory();
            O2GTimeframeCollection timeframes = factory.Timeframes;
            O2GTimeframe           timeframe  = timeframes[request.Timeframe];
            int        count = request.Count > 300 ? 300 : request.Count;
            O2GRequest rq    = factory.createMarketDataSnapshotRequestInstrument(request.Instrument, timeframe, count);

            if (request.From != factory.ZERODATE || request.To != factory.ZERODATE)
            {
                DateTime from, to;
                from = request.From;
                to   = request.To;

                /*
                 * if (request.From != factory.ZERODATE)
                 *  from = mTimeConverter.convert(request.From, O2GTimeConverterTimeZone.EST, O2GTimeConverterTimeZone.UTC);
                 * else
                 *  from = factory.ZERODATE;
                 *
                 * if (request.To != factory.ZERODATE)
                 *  to = mTimeConverter.convert(request.To, O2GTimeConverterTimeZone.EST, O2GTimeConverterTimeZone.UTC);
                 * else
                 *  to = factory.ZERODATE;
                 */

                factory.fillMarketDataSnapshotRequestTime(rq, from, to, false);
            }
            mHistoryRequests[rq.RequestID] = request;
            mSession.sendRequest(rq);
            return(rq.RequestID);
        }
        void IO2GResponseListener.onRequestFailed(string requestId, string error)
        {
            TransportHistoryRequest request = null;

            mHistoryRequests.TryGetValue(requestId, out request);
            if (request != null)
            {
                request.Reader.onHistoryFailed(requestId, error);
            }
        }
Ejemplo n.º 4
0
 internal CandleManagerHistory(TransportHistoryRequest request, bool subscribe, TimeFrameCalculator calculator, int precision)
 {
     mPrecision = precision;
     mTimeframe = Timeframe.Parse(request.Timeframe);
     mHistory   = new CandleHistory(request.Instrument, mTimeframe, calculator, mPrecision);
     if (subscribe)
     {
         mTicks = new LinkedList <Tick>();
     }
     mWaitForData = true;
     mSubscribe   = subscribe;
     mFailed      = false;
     mCount       = request.Count;
     mLastMinute  = DateTime.MinValue;
 }
 private CandleHistory GetHistory(string instrument, string timeframe, DateTime from, DateTime to, int count, bool subscribe)
 {
     lock (mMutex)
     {
         if (mTransport.IsReady())
         {
             TransportHistoryRequest rq = new TransportHistoryRequest(instrument, timeframe, from, to, count);
             CandleManagerHistory    hist;
             string key = rq.ID;
             if (!mHistories.TryGetValue(key, out hist))
             {
                 hist = new CandleManagerHistory(rq, subscribe, mCalculator, mTransport.GetInstrumentPrecision(instrument));
                 mHistories.Add(key, hist);
             }
             rq.Reader = hist;
             mTransport.RequestHistory(rq);
             return(hist.History);
         }
         else
         {
             throw new InvalidOperationException("Transport is not in the proper state");
         }
     }
 }