Пример #1
0
        /// <summary>
        /// Request historical prices for the specified timeframe of the specified period.
        /// </summary>
        /// <param name="communicator">The price history communicator.</param>
        /// <param name="instrument">The instrument.</param>
        /// <param name="timeframe">The timeframe.</param>
        /// <param name="from">From-date.</param>
        /// <param name="to">To-date</param>
        /// <param name="quotesCount">The quotes count.</param>
        /// <param name="responseListener">The response listener.</param>
        public static void GetHistoryPrices(IPriceHistoryCommunicator communicator, string instrument, string timeframe,
                                            DateTime from, DateTime to, int quotesCount, ResponseListener responseListener)
        {
            if (!communicator.isReady())
            {
                Console.WriteLine("History communicator is not ready.");
                return;
            }

            // create timeframe entity
            ITimeframeFactory timeframeFactory = communicator.TimeframeFactory;
            O2GTimeframe      timeframeObj     = timeframeFactory.create(timeframe);

            // create and send a history request
            IPriceHistoryCommunicatorRequest request = communicator.createRequest(instrument, timeframeObj, from, to, quotesCount);

            responseListener.SetRequest(request);
            communicator.sendRequest(request);

            // wait results
            responseListener.Wait();

            // print results if any
            IPriceHistoryCommunicatorResponse response = responseListener.GetResponse();

            if (response != null)
            {
                PrintPrices(communicator, response);
            }
        }
Пример #2
0
        /// <summary>
        /// Request historical prices for the specified timeframe of the specified period
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sInstrument"></param>
        /// <param name="sTimeframe"></param>
        /// <param name="dtFrom"></param>
        /// <param name="dtTo"></param>
        /// <param name="responseListener"></param>
        public static void GetHistoryPrices(O2GSession session, string sInstrument, string sTimeframe, DateTime dtFrom, DateTime dtTo, ResponseListener responseListener)
        {
            O2GRequestFactory factory   = session.getRequestFactory();
            O2GTimeframe      timeframe = factory.Timeframes[sTimeframe];

            if (timeframe == null)
            {
                throw new Exception(string.Format("Timeframe '{0}' is incorrect!", sTimeframe));
            }
            O2GRequest request = factory.createMarketDataSnapshotRequestInstrument(sInstrument, timeframe, 300);
            DateTime   dtFirst = dtTo;

            do // cause there is limit for returned candles amount
            {
                factory.fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
                responseListener.SetRequestID(request.RequestID);
                session.sendRequest(request);
                if (!responseListener.WaitEvents())
                {
                    throw new Exception("Response waiting timeout expired");
                }
                // shift "to" bound to oldest datetime of returned data
                O2GResponse response = responseListener.GetResponse();
                if (response != null && response.Type == O2GResponseType.MarketDataSnapshot)
                {
                    O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
                    if (readerFactory != null)
                    {
                        O2GMarketDataSnapshotResponseReader reader = readerFactory.createMarketDataSnapshotReader(response);
                        if (reader.Count > 0)
                        {
                            if (DateTime.Compare(dtFirst, reader.getDate(0)) != 0)
                            {
                                dtFirst = reader.getDate(0); // earliest datetime of returned data
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("0 rows received");
                            break;
                        }
                    }
                    PrintPrices(session, response);
                }
                else
                {
                    break;
                }
            } while (dtFirst > dtFrom);
        }
Пример #3
0
 /// <summary>
 /// Request historical prices for the specified timeframe of the specified period
 /// </summary>
 /// <param name="session"></param>
 /// <param name="sInstrument"></param>
 /// <param name="sTimeframe"></param>
 /// <param name="dtFrom"></param>
 /// <param name="dtTo"></param>
 /// <param name="responseListener"></param>
 public static void GetHistoryPrices(O2GSession session, string sInstrument, string sTimeframe, DateTime dtFrom, DateTime dtTo, ResponseListener responseListener)
 {
     O2GRequestFactory factory = session.getRequestFactory();
     O2GTimeframe timeframe = factory.Timeframes[sTimeframe];
     if (timeframe == null)
     {
         throw new Exception(string.Format("Timeframe '{0}' is incorrect!", sTimeframe));
     }
     O2GRequest request = factory.createMarketDataSnapshotRequestInstrument(sInstrument, timeframe, 300);
     DateTime dtFirst = dtTo;
     do // cause there is limit for returned candles amount
     {
         factory.fillMarketDataSnapshotRequestTime(request, dtFrom, dtFirst, false);
         responseListener.SetRequestID(request.RequestID);
         session.sendRequest(request);
         if (!responseListener.WaitEvents())
         {
             throw new Exception("Response waiting timeout expired");
         }
         // shift "to" bound to oldest datetime of returned data
         O2GResponse response = responseListener.GetResponse();
         if (response != null && response.Type == O2GResponseType.MarketDataSnapshot)
         {
             O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
             if (readerFactory != null)
             {
                 O2GMarketDataSnapshotResponseReader reader = readerFactory.createMarketDataSnapshotReader(response);
                 if (reader.Count > 0)
                 {
                     if (DateTime.Compare(dtFirst, reader.getDate(0)) != 0)
                     {
                         dtFirst = reader.getDate(0); // earliest datetime of returned data
                     }
                     else
                     {
                         break;
                     }
                 }
                 else
                 {
                     Console.WriteLine("0 rows received");
                     break;
                 }
             }
             PrintPrices(session, response);
         }
         else
         {
             break;
         }
     } while (dtFirst > dtFrom);
 }