Exemplo n.º 1
0
        /// <summary>
        /// Create time event subscription.
        /// </summary>
        /// <param name="connection">Native connection pointer.</param>
        /// <param name="eventType">Type of event to create.</param>
        /// <param name="time">Unix time stamp (the number of milliseconds from 1.1.1970)</param>
        /// <param name="eventSubscriptionFlags">event subscription flags</param>
        /// <param name="listener">Event listener.</param>
        /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception>
        /// <exception cref="DxException"></exception>
        public NativeSubscription(NativeConnection connection, EventType eventType, long time, EventSubscriptionFlag eventSubscriptionFlags, IDxEventListener listener)
        {
            if (listener == null)
            {
                throw new ArgumentNullException(nameof(listener));
            }

            connectionPtr  = connection.Handler;
            this.eventType = eventType;
            eventListener  = listener;

            if (eventSubscriptionFlags == EventSubscriptionFlag.Default)
            {
                C.CheckOk(C.Instance.dxf_create_subscription_timed(connectionPtr, eventType, time,
                                                                   out subscriptionPtr));
            }
            else
            {
                C.CheckOk(C.Instance.dxf_create_subscription_timed_with_flags(connectionPtr, eventType, time,
                                                                              eventSubscriptionFlags,
                                                                              out subscriptionPtr));
            }

            try
            {
                C.CheckOk(C.Instance.dxf_attach_event_listener_v2(subscriptionPtr, callback = OnEvent, IntPtr.Zero));
            }
            catch (DxException)
            {
                C.Instance.dxf_close_subscription(subscriptionPtr);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Candle event subscription.
        /// For rest events use another constructor.
        /// </summary>
        /// <param name="connection">Native connection pointer.</param>
        /// <param name="time">Date time in the past.</param>
        /// <param name="eventSubscriptionFlags">event subscription flags</param>
        /// <param name="listener">Candle event listener.</param>
        /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception>
        /// <exception cref="DxException"></exception>
        public NativeSubscription(NativeConnection connection, DateTime?time, EventSubscriptionFlag eventSubscriptionFlags, IDxCandleListener listener)
        {
            if (listener == null)
            {
                throw new ArgumentNullException(nameof(listener));
            }

            connectionPtr = connection.Handler;
            eventType     = EventType.Candle;
            eventListener = listener;

            var unixTimestamp = time == null ? 0 : Tools.DateToUnixTime((DateTime)time);

            C.CheckOk(eventSubscriptionFlags == EventSubscriptionFlag.Default
                ? C.Instance.dxf_create_subscription_timed(connectionPtr, eventType, unixTimestamp, out subscriptionPtr)
                : C.Instance.dxf_create_subscription_timed_with_flags(connectionPtr, eventType, unixTimestamp,
                                                                      eventSubscriptionFlags, out subscriptionPtr));

            try
            {
                C.CheckOk(C.Instance.dxf_attach_event_listener_v2(subscriptionPtr, callback = OnEvent, IntPtr.Zero));
            }
            catch (DxException)
            {
                C.Instance.dxf_close_subscription(subscriptionPtr);
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the new regional book instance
        /// </summary>
        /// <remarks>
        ///     Don't call this constructor inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="connection">The current connection</param>
        /// <param name="symbol">The book symbol</param>
        /// <param name="bookListener">The book listener implementation</param>
        /// <param name="quoteListener">The quote listener implementation</param>
        /// <exception cref="ArgumentException"></exception>
        public NativeRegionalBook(NativeConnection connection, string symbol, IDxRegionalBookListener bookListener,
                                  IDxQuoteListener quoteListener)
        {
            if (string.IsNullOrWhiteSpace(symbol))
            {
                throw new ArgumentException("Invalid symbol parameter.");
            }

            this.bookListener  = bookListener;
            this.quoteListener = quoteListener;

            if (bookListener == null && quoteListener == null)
            {
                return;
            }

            C.CheckOk(C.Instance.dxf_create_regional_book(connection.Handle, symbol, out bookHandle));
            try
            {
                if (this.bookListener != null)
                {
                    C.CheckOk(C.Instance.dxf_attach_regional_book_listener(bookHandle, nativeBookListener = OnBook, IntPtr.Zero));
                }
                if (this.quoteListener != null)
                {
                    C.CheckOk(C.Instance.dxf_attach_regional_book_listener_v2(bookHandle, nativeQuoteListener = OnQuote, IntPtr.Zero));
                }
            }
            catch (DxException)
            {
                C.Instance.dxf_close_regional_book(bookHandle);
                throw;
            }
        }
        /// <summary>
        /// Creates the new native order subscription on snapshot with incremental updates.
        /// </summary>
        /// <remarks>
        ///     Don't call this constructor inside any listeners and callbacks of NativeSubscription, NativeConnection,
        /// NativeRegionalBook, NativeSnapshotSubscription classes
        /// </remarks>
        /// <param name="connection">Native connection pointer.</param>
        /// <param name="listener">Snapshot or update events listener.</param>
        /// <exception cref="ArgumentNullException">Listener is invalid.</exception>
        public NativeSnapshotSubscription(NativeConnection connection, IDxIncOrderSnapshotListener listener)
        {
            if (listener == null)
            {
                throw new ArgumentNullException(nameof(listener));
            }

            connectionPtr   = connection.Handle;
            this.listener   = listener;
            this.time       = 0;
            this.connection = connection;
        }
        /// <summary>
        /// Creates new native order or candle subscription on snapshot.
        /// </summary>
        /// <param name="connection">Native connection pointer.</param>
        /// <param name="time">Milliseconds time in the past.</param>
        /// <param name="listener">Snapshot events listener.</param>
        /// <exception cref="ArgumentNullException">Listener is invalid.</exception>
        public NativeSnapshotSubscription(NativeConnection connection, long time,
                                          IDxSnapshotListener listener)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }

            connectionPtr   = connection.Handler;
            this.listener   = listener;
            this.time       = time;
            this.connection = connection;
        }
Exemplo n.º 6
0
        public void Dispose()
        {
            if (connection != null)
            {
                connection.RemoveSubscription(this);
                connection = null;
            }

            if (subscriptionPtr == IntPtr.Zero)
            {
                return;
            }

            C.CheckOk(C.Instance.dxf_close_subscription(subscriptionPtr));
            subscriptionPtr = IntPtr.Zero;
        }
        /// <summary>
        /// Creates new native snapshot subscription with specified event type.
        /// </summary>
        /// <param name="connection">Native connection pointer.</param>
        /// <param name="eventType">Single event type.</param>
        /// <param name="time">Milliseconds time in the past.</param>
        /// <param name="listener">Snapshot events listener.</param>
        /// <exception cref="ArgumentNullException">Listener is invalid.</exception>
        public NativeSnapshotSubscription(NativeConnection connection, EventType eventType,
                                          long time, IDxSnapshotListener listener)
        {
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }
            if ((eventType & (eventType - 1)) > 0)
            {
                throw new ArgumentException("Only one event type is allowed for snapshot.");
            }

            connectionPtr  = connection.Handler;
            this.eventType = eventType;
            this.listener  = listener;
            this.time      = time;
        }
        /// <summary>
        /// Dispose native snapshot subscription
        /// </summary>
        /// <exception cref="NativeDxSubscription"></exception>
        public void Dispose()
        {
            if (connection != null)
            {
                connection.RemoveSubscription(this);
                connection = null;
            }
            if (snapshotPtr == InvalidSnapshot)
            {
                return;
            }

            C.CheckOk(C.Instance.dxf_close_snapshot(snapshotPtr));
            snapshotPtr = InvalidSnapshot;

            eventType = EventType.None;
        }
Exemplo n.º 9
0
        private bool disposedValue = false; // To detect redundant calls

        /// <summary>
        ///   This code added to correctly implement the disposable pattern.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (connection != null)
            {
                connection.RemoveSubscription(this);
                connection = null;
            }

            if (disposedValue)
            {
                return;
            }

            if (disposing)
            {
                if (subscription != null)
                {
                    subscription.Dispose();
                    subscription = null;
                }
            }

            disposedValue = true;
        }
Exemplo n.º 10
0
 /// <summary>
 ///   Constructor
 /// </summary>
 /// <param name="connection">IDxConnection connection</param>
 /// <param name="listener">OrderView listener</param>
 public OrderViewSubscription(NativeConnection connection, IDxOrderViewListener listener)
 {
     this.connection = connection;
     this.listener   = listener;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Create event subscription.
 /// </summary>
 /// <param name="connection">native connection pointer</param>
 /// <param name="eventType">type of event to create</param>
 /// <param name="listener">event listener</param>
 /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception>
 /// <exception cref="DxException"></exception>
 public NativeSubscription(NativeConnection connection, EventType eventType, IDxEventListener listener) :
     this(connection, eventType, EventSubscriptionFlag.Default, listener)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Create Candle event subscription.
 /// For rest events use another constructor.
 /// </summary>
 /// <param name="connection">Native connection pointer.</param>
 /// <param name="time">Date time in the past.</param>
 /// <param name="listener">Candle event listener.</param>
 /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception>
 /// <exception cref="DxException"></exception>
 public NativeSubscription(NativeConnection connection, DateTime?time, IDxCandleListener listener) :
     this(connection, time, EventSubscriptionFlag.Default, listener)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Create time event subscription.
 /// </summary>
 /// <param name="connection">Native connection pointer.</param>
 /// <param name="eventType">Type of event to create.</param>
 /// <param name="time">Time to getting events from.</param>
 /// <param name="listener">Event listener.</param>
 /// <exception cref="ArgumentException">One of passed parameters is not valid.</exception>
 /// <exception cref="DxException"></exception>
 public NativeSubscription(NativeConnection connection, EventType eventType, DateTime time, IDxEventListener listener) :
     this(connection, eventType, Tools.DateToUnixTime(time), listener)
 {
 }