/// <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="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, IDxCandleListener listener) { if (handle == IntPtr.Zero) { throw new NativeDxException("not connected"); } IDxSubscription result = new NativeSubscription(this, time, listener); subscriptions.Add(result); return(result); }
/// <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) { }
/// <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; } }