Beispiel #1
0
        /// <summary>
        /// Returns candle symbol string with the normalized representation of the candle price level attribute.
        /// </summary>
        /// <param name="symbol">The candle symbol string.</param>
        /// <returns>The candle symbol string with the normalized representation of the the candle price level attribute.</returns>
        public static string NormalizeAttributeForSymbol(string symbol)
        {
            var a = MarketEventSymbols.GetAttributeStringByKey(symbol, ATTRIBUTE_KEY);

            if (a == null)
            {
                return(symbol);
            }
            try
            {
                var other = Parse(a);

                if (other.Equals(DEFAULT))
                {
                    MarketEventSymbols.RemoveAttributeStringByKey(symbol, ATTRIBUTE_KEY);
                }

                return(!a.Equals(other.ToString())
                    ? MarketEventSymbols.ChangeAttributeStringByKey(symbol, ATTRIBUTE_KEY, other.ToString())
                    : symbol);
            } catch (ArgumentNullException)
            {
                return(symbol);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns candle symbol string with the normalized representation of the candle session attribute.
        /// </summary>
        /// <param name="symbol">candle symbol string.</param>
        /// <returns>candle symbol string with the normalized representation of the the candle session attribute.</returns>
        public static string NormalizeAttributeForSymbol(string symbol)
        {
            string a = MarketEventSymbols.GetAttributeStringByKey(symbol, ATTRIBUTE_KEY);

            if (a == null)
            {
                return(symbol);
            }
            try
            {
                bool b = bool.Parse(a);
                if (!b)
                {
                    MarketEventSymbols.RemoveAttributeStringByKey(symbol, ATTRIBUTE_KEY);
                }
                if (b && !a.Equals(REGULAR.ToString()))
                {
                    return(MarketEventSymbols.ChangeAttributeStringByKey(symbol, ATTRIBUTE_KEY, REGULAR.ToString()));
                }
                return(symbol);
            }
            catch (ArgumentNullException)
            {
                return(symbol);
            }
        }
Beispiel #3
0
 private void InitTransientFields()
 {
     baseSymbol = MarketEventSymbols.GetBaseSymbol(symbol);
     if (exchange == null)
     {
         exchange = CandleExchange.GetAttributeForSymbol(symbol);
     }
     if (price == null)
     {
         price = CandlePrice.GetAttributeForSymbol(symbol);
     }
     if (session == null)
     {
         session = CandleSession.GetAttributeForSymbol(symbol);
     }
     if (period == null)
     {
         period = CandlePeriod.GetAttributeForSymbol(symbol);
     }
     if (alignment == null)
     {
         alignment = CandleAlignment.GetAttributeForSymbol(symbol);
     }
     if (priceLevel == null)
     {
         priceLevel = CandlePriceLevel.GetAttributeForSymbol(symbol);
     }
 }
Beispiel #4
0
        /// <summary>
        ///     Requests the last event for the specified event type and symbol.
        ///     This method works only for event types that implement <see cref="IDxLastingEvent"/>
        ///     marker interface.
        ///     This method requests the data from the the uplink data provider, creates new event
        ///     of the specified event type <c>E</c>, and completes the resulting promise with
        ///     this event.
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         This method is designed for retrieval of a snapshot only.
        ///         Use <see cref="DXFeedSubscription{E}"/> if you need event updates in real time.
        ///     </para>
        ///     <para>
        ///         The promise is <see cref="TaskStatus.Canceled"/> when the the underlying
        ///         <see cref="DXEndpoint"/> is <see cref="DXEndpoint.Close()"/>.
        ///         If the event is not available for any transient reason (no subscription, no
        ///         connection to uplink, etc), then the resulting promise completes when the issue
        ///         is resolved, which may involve an arbitrarily long wait.
        ///         Use <see cref="CancellationTokenSource"/> class constructors and methods to
        ///         specify timeout while waiting for promise to complete.
        ///         If the event is permanently not available (not supported), then the promise
        ///         completes exceptionally with <see cref="AggregateException"/>.
        ///     </para>
        ///     <para>
        ///         There is a bulk version of this method that works much faster for a single event
        ///         type and multiple symbols.
        ///         See <see cref="GetLastEventsPromises{E}(ICollection{object}, CancellationToken)"/>.
        ///     </para>
        ///     <para>
        ///         Note, that this method does not work when <see cref="DXEndpoint"/> was created
        ///         with DXEndpoint.Role#STREAM_FEED role (promise completes
        ///         exceptionally).
        ///     </para>
        ///     <para>Threads</para>
        ///     <para>
        ///         Use <see cref="Task.ContinueWith(Action{Task})"/> method on the resulting
        ///         promise to receive notification when the promise becomes done.
        ///     </para>
        /// </remarks>
        /// <example>
        ///     Use the following pattern of code to acquire multiple events (either for multiple
        ///     symbols and/or multiple events) and wait with a single timeout for all of them:
        ///     <code>
        ///         List&lt;Task&lt;LastingEvent&gt;&gt; promises = new List&lt;Task&lt;LastingEvent&gt;&gt;();
        ///         // iterate the following line for all events and/or symbols that are needed
        ///         promises.Add(feed.GetLastEventPromise&lt;eventType&gt;(symbol, new CancellationTokenSource(taskTimeout).Token));
        ///         // combine the list of promises into one with Task utility method and wait
        ///         try
        ///         {
        ///             Task.WaitAll(tasks.ToArray());
        ///         }
        ///         catch (AggregateException) {}
        ///         // now iterate the promises to retrieve results
        ///         foreach (Task&lt;LastingEvent&gt; promise in promises)
        ///             // result received exceptionally if this event was not found
        ///             // so first check that task completes successfully
        ///             if (promise.Status == TaskStatus.RanToCompletion)
        ///                 doSomethingWith(promise.Result);
        ///     </code>
        /// </example>
        /// <typeparam name="E">The event type.</typeparam>
        /// <param name="symbol">The symbol.</param>
        /// <param name="cancellationToken">The task cancellation token.</param>
        /// <returns>The promise for the result of the request.</returns>
        /// <exception cref="ArgumentException">
        ///     The <paramref name="symbol"/> symbol is not one of string or <see cref= "CandleSymbol"/>.
        /// </exception >
        /// <exception cref="ArgumentNullException">The <paramref name="symbol"/> is null.</exception>
        public async Task <IDxLastingEvent> GetLastEventPromise <E>(object symbol,
                                                                    CancellationToken cancellationToken)
            where E : class, IDxLastingEvent
        {
            MarketEventSymbols.ValidateSymbol(symbol);

            return(await Task.Run(() =>
            {
                if (endpoint.State == DXEndpointState.Closed)
                {
                    throw new OperationCanceledException("Endpoint was been closed.");
                }
                LastingEventsCollector <E> collector = new LastingEventsCollector <E>();
                IDXFeedSubscription <E> s = CreateSubscription <E>();
                s.AddSymbols(symbol);
                s.AddEventListener(collector);
                while (!collector.HasEvent <E>(symbol))
                {
                    if (endpoint.State == DXEndpointState.Closed)
                    {
                        throw new OperationCanceledException("Endpoint was been closed.");
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                }
                return collector.GetEvent <E>(symbol);
            }, cancellationToken));
        }
Beispiel #5
0
 /// <summary>
 ///     Requests time series of events for the specified event type, symbol, and a range
 ///     of time.
 ///     This method works only for event types that implement <see cref="IDxTimeSeriesEvent"/>
 ///     interface.
 ///     This method requests the data from the the uplink data provider, creates a list of
 ///     events of the specified event type <c>E</c>, and completes the resulting promise
 ///     with this list.
 ///     The events are ordered by <see cref="IDxTimeSeriesEvent.Time"/> in the list.
 /// </summary>
 /// <remarks>
 ///     <para>
 ///         This method is designed for retrieval of a snapshot only.
 ///         Use <see cref="IDxConnection.CreateSnapshotSubscription(EventType, long, IDxSnapshotListener)"/>
 ///         if you need a list of time-series events that updates in real time.
 ///     </para>
 ///     <para>
 ///         The range and depth of events that are available with this service is typically
 ///         constrained by upstream data provider.
 ///     </para>
 ///     <para>
 ///         The promise is <see cref="TaskStatus.Canceled"/> when the the underlying
 ///         <see cref="DXEndpoint"/> is <see cref="DXEndpoint.Close()"/>.
 ///         If the event is not available for any transient reason (no subscription, no
 ///         connection to uplink, etc), then the resulting promise completes when the
 ///         issue is resolved, which may involve an arbitrarily long wait.
 ///         Use <see cref="CancellationTokenSource"/> class constructors and methods to
 ///         specify timeout while waiting for promise to complete.
 ///         If the event is permanently not available (not supported), then the promise
 ///         completes exceptionally with <see cref="AggregateException"/>.
 ///     </para>
 ///     <para>
 ///         Note, that this method does not work when <see cref="DXEndpoint"/>  was created
 ///         with DXEndpoint.Role#STREAM_FEED role (promise completes
 ///         exceptionally).
 ///     </para>
 ///     <para>
 ///         Event flags
 ///     </para>
 ///     <para>
 ///         This method completes promise only when a consistent snapshot of time series
 ///         has been received from the data feed. The <see cref="IDxIndexedEvent.EventFlags"/>
 ///         property of the events in the resulting list is always zero.
 ///     </para>
 ///     <para>
 ///         Threads
 ///     </para>
 ///     <para>
 ///         Use <see cref="Task.ContinueWith(Action{Task})"/> method on the resulting
 ///         promise to receive notification when the promise becomes done.
 ///     </para>
 /// </remarks>
 /// <typeparam name="E">The event type.</typeparam>
 /// <param name="symbol">The symbol.</param>
 /// <param name="fromTime">
 ///     The time, inclusive, to request events from <see cref="IDxTimeSeriesEvent.Time"/>.
 /// </param>
 /// <param name="toTime">
 ///     The time, inclusive, to request events to <see cref="IDxTimeSeriesEvent.Time"/>.
 ///     Use <see cref="long.MaxValue"/> to retrieve events without an upper limit on time.
 /// </param>
 /// <param name="cancellationToken">The task cancellation token.</param>
 /// <returns>The promise for the result of the request.</returns>
 /// <exception cref="ArgumentException">
 ///     The <paramref name="symbol"/> symbol is not one of string or <see cref= "CandleSymbol"/>.
 /// </exception >
 /// <exception cref="ArgumentNullException">The <paramref name="symbol"/> is null.</exception>
 public async Task <List <E> > GetTimeSeriesPromise <E>(object symbol, long fromTime,
                                                        long toTime, CancellationToken cancellationToken)
     where E : IDxTimeSeriesEvent
 {
     MarketEventSymbols.ValidateSymbol(symbol);
     return(await FetchOrSubscribeFromHistory <E>(symbol, fromTime, toTime,
                                                  IndexedEventSource.DEFAULT, cancellationToken));
 }
Beispiel #6
0
 /// <summary>
 ///     Requests a list of indexed events for the specified event type, symbol, and source.
 ///     This method works only for event types that implement <see cref="IDxIndexedEvent"/>
 ///     interface.
 ///     This method requests the data from the the uplink data provider, creates a list of
 ///     events of the specified event type <c>E</c>, and completes the resulting promise
 ///     with this list.
 ///     The events are ordered by <see cref="IDxIndexedEvent.Index"/> in the list.
 /// </summary>
 /// <remarks>
 ///     <para>
 ///         This method is designed for retrieval of a snapshot only.
 ///         Use <see cref="IDxConnection.CreateSnapshotSubscription(EventType, long, IDxSnapshotListener)"/>
 ///         if you need a list of time-series events that updates in real time.
 ///     </para>
 ///     <para>
 ///         The promise is <see cref="TaskStatus.Canceled"/> when the the underlying
 ///         <see cref="DXEndpoint"/> is <see cref="DXEndpoint.Close()"/>.
 ///         If the event is not available for any transient reason (no subscription, no
 ///         connection to uplink, etc), then the resulting promise completes when the
 ///         issue is resolved, which may involve an arbitrarily long wait.
 ///         Use <see cref="CancellationTokenSource"/> class constructors and methods to
 ///         specify timeout while waiting for promise to complete.
 ///         If the event is permanently not available (not supported), then the promise
 ///         completes exceptionally with <see cref="AggregateException"/>.
 ///     </para>
 ///     <para>
 ///         Note, that this method does not work when <see cref="DXEndpoint"/>  was created
 ///         with DXEndpoint.Role#STREAM_FEED role (promise completes
 ///         exceptionally).
 ///     </para>
 ///     <para>
 ///         Event source
 ///     </para>
 ///     <para>
 ///         Use the <see cref="IndexedEventSource.DEFAULT"/> value for <c>source</c> with
 ///         events that do not have multiple sources (like <see cref="IDxSeries"/>). For
 ///         events with multiple sources (like <see cref="IDxOrder"/> and <see cref="IDxSpreadOrder"/>),
 ///         use an even-specific source class (for example, <see cref="OrderSource"/>).
 ///         This method does not support synthetic sources of orders (orders that are
 ///         automatically generated from <see cref="IDxQuote"/> events).
 ///     </para>
 ///     <para>
 ///         Event flags and consistent snapshot
 ///     </para>
 ///     <para>
 ///         This method completes promise only when a consistent snapshot of time series has
 ///         been received from the data feed. The <see cref="IDxIndexedEvent.EventFlags"/>
 ///         property of the events in the resulting list is always zero.
 ///     </para>
 ///     <para>
 ///         Threads
 ///     </para>
 ///     <para>
 ///         Use <see cref="Task.ContinueWith(Action{Task})"/> method on the resulting
 ///         promise to receive notification when the promise becomes done.
 ///     </para>
 /// </remarks>
 /// <typeparam name="E">The event type.</typeparam>
 /// <param name="symbol">The collection of symbols.</param>
 /// <param name="source">The source.</param>
 /// <param name="cancellationToken">The task cancellation token.</param>
 /// <returns>The promise for the result of the request.</returns>
 /// <exception cref="ArgumentException">
 ///     The <paramref name="symbol"/> symbol is not one of string or <see cref= "CandleSymbol"/>.
 /// </exception >
 /// <exception cref="ArgumentNullException">
 ///     The <paramref name="symbol"/> or <paramref name="source"/> is null.
 /// </exception>
 public async Task <List <E> > GetIndexedEventsPromise <E>(object symbol,
                                                           IndexedEventSource source, CancellationToken cancellationToken)
     where E : IDxIndexedEvent
 {
     MarketEventSymbols.ValidateSymbol(symbol);
     if (source == null)
     {
         throw new ArgumentNullException("Source is null!");
     }
     return(await FetchOrSubscribeFromHistory <E>(symbol, 0, long.MaxValue, source, cancellationToken));
 }
Beispiel #7
0
        private async Task <List <E> > FetchOrSubscribeFromHistory <E>(object symbol, long fromTime,
                                                                       long toTime, IndexedEventSource source, CancellationToken cancellationToken)
            where E : IDxIndexedEvent
        {
            MarketEventSymbols.ValidateSymbol(symbol);

            return(await Task.Run(() =>
            {
                if (endpoint.State == DXEndpointState.Closed)
                {
                    throw new OperationCanceledException("Endpoint was been closed.");
                }
                HistoryEventsCollector <E> collector = new HistoryEventsCollector <E>(fromTime, toTime);
                IDXFeedSubscription <E> s = CreateSnapshotSubscription <E>(fromTime, source);
                s.AddEventListener(collector);
                s.AddSymbols(symbol);

                try
                {
                    while (!collector.IsDone)
                    {
                        if (endpoint.State == DXEndpointState.Closed)
                        {
                            throw new OperationCanceledException("Endpoint was been closed.");
                        }
                        cancellationToken.ThrowIfCancellationRequested();
                    }
                }
                finally
                {
                    /*Note: it is necessary i.e. new snapshot with similar type and symbol cannot
                     * be created while this is not closed.*/
                    s.Close();
                }
                List <E> eventsList = collector.Events;
                eventsList.Reverse();
                return eventsList;
            }, cancellationToken));
        }
Beispiel #8
0
 /// <summary>
 /// Returns candle event symbol string with this session attribute set.
 /// </summary>
 /// <param name="symbol">original candle event symbol.</param>
 /// <returns>candle event symbol string with this session attribute set.</returns>
 public string ChangeAttributeForSymbol(string symbol)
 {
     return(this == DEFAULT?
            MarketEventSymbols.RemoveAttributeStringByKey(symbol, ATTRIBUTE_KEY) :
                MarketEventSymbols.ChangeAttributeStringByKey(symbol, ATTRIBUTE_KEY, ToString()));
 }
Beispiel #9
0
        /// <summary>
        /// Returns candle session attribute of the given candle symbol string.
        /// The result is {@link #DEFAULT} if the symbol does not have candle session attribute.
        /// </summary>
        /// <param name="symbol">candle symbol string.</param>
        /// <returns>candle session attribute of the given candle symbol string.</returns>
        public static CandleSession GetAttributeForSymbol(string symbol)
        {
            string a = MarketEventSymbols.GetAttributeStringByKey(symbol, ATTRIBUTE_KEY);

            return(a != null && bool.Parse(a) ? REGULAR : DEFAULT);
        }
Beispiel #10
0
 private string SymbolToString(object obj)
 {
     MarketEventSymbols.ValidateSymbol(obj);
     return(obj is CandleSymbol ? (obj as CandleSymbol).ToString() : obj as string);
 }
 private string GetSymbolKey(object symbolObj)
 {
     MarketEventSymbols.ValidateSymbol(symbolObj);
     return((symbolObj is CandleSymbol) ? (symbolObj as CandleSymbol).ToString() : symbolObj as string);
 }
Beispiel #12
0
 public string ChangeAttributeForSymbol(string symbol)
 {
     return(Equals(this, DEFAULT)
         ? MarketEventSymbols.RemoveAttributeStringByKey(symbol, ATTRIBUTE_KEY)
         : MarketEventSymbols.ChangeAttributeStringByKey(symbol, ATTRIBUTE_KEY, stringBuf));
 }
Beispiel #13
0
        /// <summary>
        /// Returns candle price level attribute of the given candle symbol string.
        /// The result is {@link #DEFAULT} if the symbol does not have candle session attribute.
        /// </summary>
        /// <param name="symbol">The candle symbol string.</param>
        /// <returns>The candle price level attribute of the given candle symbol string.</returns>
        public static CandlePriceLevel GetAttributeForSymbol(string symbol)
        {
            var s = MarketEventSymbols.GetAttributeStringByKey(symbol, ATTRIBUTE_KEY);

            return(s == null ? DEFAULT : Parse(s));
        }
 /// <summary>
 /// Returns candle event symbol string with this exchange set.
 /// </summary>
 /// <param name="symbol">original candle event symbol.</param>
 /// <returns>candle event symbol string with this exchange set.</returns>
 public string ChangeAttributeForSymbol(string symbol)
 {
     return(MarketEventSymbols.ChangeExchangeCode(symbol, exchangeCode));
 }
 /// <summary>
 /// Returns exchange attribute object of the given candle symbol string.
 /// The result is {@link #DEFAULT} if the symbol does not have exchange attribute.
 /// </summary>
 /// <param name="symbol">candle symbol string.</param>
 /// <returns>exchange attribute object of the given candle symbol string.</returns>
 public static CandleExchange GetAttributeForSymbol(string symbol)
 {
     return(ValueOf(MarketEventSymbols.GetExchangeCode(symbol)));
 }
Beispiel #16
0
 internal static bool IsCandleSymbol(string symbol)
 {
     return(MarketEventSymbols.HasExchangeCode(symbol) || MarketEventSymbols.HasAttributes(symbol));
 }