示例#1
0
        internal unsafe PlayedOrder(string symbol, EventFlag event_flags, long index,
                                    long time, int time_nanos, int sequence,
                                    double price, int size, int count,
                                    Scope scope, Side side, char exchange_code,
                                    IndexedEventSource source, string mm)
        {
            this.EventSymbol  = symbol;
            this.EventFlags   = event_flags;
            this.Index        = index;
            this.Time         = Tools.UnixTimeToDate(time);
            this.TimeNanoPart = time_nanos;
            this.Sequence     = sequence;
            this.Price        = price;
            this.Size         = size;
            this.Count        = count;
            this.Scope        = scope;
            this.Side         = side;
            this.ExchangeCode = exchange_code;
            this.Source       = source;
            fixed(char *pMarketMaker = mm.ToCharArray())
            {
                this.MarketMaker = new string(pMarketMaker);
            }

            marketMakerCharArray = mm.ToCharArray();
            IntPtr marketMakerCharsPtr = Marshal.UnsafeAddrOfPinnedArrayElement(marketMakerCharArray, 0);

            Params = new EventParams(EventFlags, (ulong)Index, 0);
            Data   = new DxTestOrder(event_flags, index, time, time_nanos, sequence, price, size, count, scope, side, exchange_code, source, marketMakerCharsPtr);
        }
        public void OnSnapshot <TB, TE>(TB buf)
            where TB : IDxEventBuf <TE>
            where TE : IDxOrder
        {
            var s     = new Dictionary <long, SimpleOrder>();
            var count = 0;
            IndexedEventSource src = null;
            var sym = "";

            foreach (var o in buf)
            {
                if (src == null)
                {
                    src = o.Source;
                    sym = $"{buf.Symbol}#{src.Name}";
                }
                else if (!Equals(src, o.Source))
                {
                    Console.WriteLine("ERROR: Mixed!");
                }

                s.Add(o.Index, new SimpleOrder(o));
                Console.WriteLine($"\"{sym}\" add {s[o.Index]}");
                count++;
            }

            /* Override old, if have one */
            state[sym] = s;
            Console.WriteLine($"New snapshot for \"{sym}\" with {count} orders");
            CheckBidAsk(sym, s);
        }
示例#3
0
        internal IntPtr    mm_or_ss; // String

        internal DxTestOrder(EventFlag event_flags, long index,
                             long time, int time_nanos, int sequence,
                             double price, int size, int count,
                             Scope scope, Side side, char exchange_code,
                             IndexedEventSource source, IntPtr mm_or_ss)
        {
            this.event_flags   = event_flags;
            this.index         = index;
            this.time          = time;
            this.time_nanos    = time_nanos;
            this.sequence      = sequence;
            this.price         = price;
            this.size          = size;
            this.count         = count;
            this.scope         = scope;
            this.side          = side;
            this.exchange_code = exchange_code;
            fixed(char *pSource = this.source)
            {
                var length = Math.Min(4, source.Name.Length);

                Marshal.Copy(source.Name.ToCharArray(), 0, (IntPtr)pSource, length);
                pSource[length] = (char)0;
            }

            this.mm_or_ss = mm_or_ss;
        }
示例#4
0
        /// <summary>
        ///     Creates new snapshot subscription for a single event type that is attached to this feed.
        ///     This method creates new <see cref="IDXFeedSubscription{E}"/>.
        /// </summary>
        /// <typeparam name="E">The type of events.</typeparam>
        /// <param name="time">Unix time in the past - number of milliseconds from 1.1.1970.</param>
        /// <param name="source">The source of the event.</param>
        /// <returns>New DXFeedSubscription for a single event type.</returns>
        internal IDXFeedSubscription <E> CreateSnapshotSubscription <E>(long time, IndexedEventSource source)
            where E : IDxIndexedEvent
        {
            IDXFeedSubscription <E> subscription = new DXFeedSubscription <E>(endpoint, time, source) as IDXFeedSubscription <E>;

            subscription.Attach(this);
            return(subscription);
        }
示例#5
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));
 }
示例#6
0
        /// <summary>
        ///     Creates detached snapshot subscription for a single event type.
        /// </summary>
        /// <param name="endpoint">The <see cref="DXEndpoint"/> instance.</param>
        /// <param name="time">Unix time in the past - number of milliseconds from 1.1.1970.</param>
        /// <param name="source">The source of the event.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="endpoint"/> is null.</exception>
        /// <exception cref="ArgumentException">If type E is not event class.</exception>
        /// <exception cref="DxException">Internal error.</exception>
        internal DXFeedSubscription(DXEndpoint endpoint, long time, IndexedEventSource source) : this()
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            endpoint.OnClosing += Endpoint_OnClosing;

            subscriptionInstance = endpoint.Connection.CreateSnapshotSubscription(
                EventTypeUtil.GetEventsType(typeof(E)),
                time,
                new DXFeedEventHandler <E>(eventListeners, eventListenerLocker));
            if (source != IndexedEventSource.DEFAULT)
            {
                subscriptionInstance.SetSource(source.Name);
            }
        }
示例#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));
        }
示例#8
0
 private static string CreateCompoundKey(ulong snapshotKey, string symbol, IndexedEventSource source)
 {
     return($"{snapshotKey}{symbol}{source}");
 }