Example #1
0
        /// <summary>
        ///     Creates an event subscription.
        /// </summary>
        /// <remarks>
        ///     Don't call this method inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="type">Event type.</param>
        /// <param name="listener">Event listener callback.</param>
        /// <returns>Subscription object.</returns>
        /// <exception cref="ArgumentNullException">Listener is null.</exception>
        /// <exception cref="DxException"></exception>
        public IDxSubscription CreateSubscription(EventType type, IDxEventListener listener)
        {
            if (handle == IntPtr.Zero)
            {
                throw new NativeDxException("not connected");
            }
            IDxSubscription result = new NativeSubscription(this, type, listener);

            subscriptions.Add(result);
            return(result);
        }
Example #2
0
        /// <summary>
        ///     Creates a candle event subscription.
        /// </summary>
        /// <remarks>
        ///     Don't call this method inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="time">Date time in the past.</param>
        /// <param name="eventSubscriptionFlags">Event subscription flags</param>
        /// <param name="listener">Candle listener callback.</param>
        /// <returns>Subscription object.</returns>
        /// <exception cref="ArgumentNullException">Listener is null.</exception>
        /// <exception cref="DxException"></exception>
        public IDxSubscription CreateSubscription(DateTime?time, EventSubscriptionFlag eventSubscriptionFlags, IDxCandleListener listener)
        {
            if (handle == IntPtr.Zero)
            {
                throw new NativeDxException("not connected");
            }

            IDxSubscription result = new NativeSubscription(this, time, eventSubscriptionFlags, listener);

            subscriptions.Add(result);
            return(result);
        }
        /// <summary>
        ///     Adds a symbol to the subscription.
        /// </summary>
        /// <remarks>
        ///     Don't call this method inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="symbol">Symbol.</param>
        /// <exception cref="ArgumentException">Invalid <paramref name="symbol"/> parameter.</exception>
        /// <exception cref="InvalidOperationException">You try to add more than one symbol to snapshot subscription.</exception>
        /// <exception cref="DxException">Internal error.</exception>
        public void AddSymbol(string symbol)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("Invalid symbol parameter");
            }
            if (snapshotPtr != InvalidSnapshot)
            {
                throw new InvalidOperationException("It is allowed to add only one symbol to snapshot subscription");
            }

            if ((eventType == EventType.Candle) ||
                (eventType == EventType.None) && NativeSubscription.IsCandleSymbol(symbol))
            {
                AddSymbol(CandleSymbol.ValueOf(symbol));
                return;
            }


            byte[] sourceBytes = null;
            if (source != string.Empty)
            {
                var ascii = Encoding.ASCII;
                sourceBytes = ascii.GetBytes(source);
            }

            if (eventType == EventType.None)
            {
                eventType = EventType.Order;
                C.CheckOk(C.Instance.dxf_create_order_snapshot(connectionPtr, symbol, sourceBytes, time, out snapshotPtr));
            }
            else
            {
                C.CheckOk(C.Instance.dxf_create_snapshot(connectionPtr, EventTypeUtil.GetEventId(eventType), symbol, sourceBytes, time, out snapshotPtr));
            }

            try
            {
                if (listener is IDxIncOrderSnapshotListener)
                {
                    C.CheckOk(C.Instance.dxf_attach_snapshot_inc_listener(snapshotPtr, incCallback = OnIncOrderSnapshot, IntPtr.Zero));
                }
                else
                {
                    C.CheckOk(C.Instance.dxf_attach_snapshot_listener(snapshotPtr, callback = OnEvent, IntPtr.Zero));
                }
            }
            catch (DxException)
            {
                Dispose();
                throw;
            }
        }