public IObservable <OrderMarketSnap> SubscribeOrders(string marketId, OrderSubscriptionMessage orderSubscription)
        {
            networkClient.Start();

            if (orderObservables.TryGetValue(marketId, out IObservable <OrderMarketSnap> orderObservable))
            {
                networkClient.OrderSubscription(orderSubscription);
                return(orderObservable);
            }

            var observable = Observable.Create <OrderMarketSnap>(
                (IObserver <OrderMarketSnap> observer) =>
            {
                orderObservers.AddOrUpdate(marketId, observer, (key, existingVal) => existingVal);

                return(Disposable.Create(() =>
                {
                    orderObservables.TryRemove(marketId, out IObservable <OrderMarketSnap> o);
                    orderObservers.TryRemove(marketId, out IObserver <OrderMarketSnap> ob);
                }));
            })
                             .Publish()
                             .RefCount();

            orderObservables.AddOrUpdate(marketId, observable, (key, existingVal) => existingVal);

            // TODO:// race?
            networkClient.OrderSubscription(orderSubscription);
            return(observable);
        }
Exemple #2
0
        private void ConnectAndAuthenticateAndResubscribe()
        {
            try
            {
                //Connect and auth
                ConnectAndAuthenticate();

                //Resub markets
                MarketSubscriptionMessage marketSubscription = _processor.MarketResubscribeMessage;
                if (marketSubscription != null)
                {
                    Trace.TraceInformation("Resubscribe to market subscription.");
                    MarketSubscription(marketSubscription);
                }

                //Resub orders
                OrderSubscriptionMessage orderSubscription = _processor.OrderResubscribeMessage;
                if (orderSubscription != null)
                {
                    Trace.TraceInformation("Resubscribe to order subscription.");
                    OrderSubscription(orderSubscription);
                }

                //Reset counter
                ReconnectCounter = 0;
            } catch (Exception e)
            {
                Trace.TraceError("Reconnect failed", e);
                ReconnectCounter++;
            }
        }
        public Task <StatusMessage> OrderSubscription(OrderSubscriptionMessage message)
        {
            int id = NextId();

            message.Id = id;
            message.Op = REQUEST_ORDER_SUBSCRIPTION;
            var newSub = new SubscriptionHandler <OrderSubscriptionMessage, ChangeMessage <OrderMarketChange>, OrderMarketChange>(id, message, false);

            return(SendMessage(new RequestResponse(id, message,
                                                   success => OrderSubscriptionHandler = newSub)));
        }
        public IObservable <OrderMarketSnap> SubscribeOrders(string marketId)
        {
            OrderSubscriptionMessage orderSubscription = new OrderSubscriptionMessage();

            return(SubscribeOrders(marketId, orderSubscription));
        }
 /// <summary>
 /// Explict order subscription. (starting the client if needed).
 /// </summary>
 /// <param name="subscription"></param>
 public void SubscribeOrders(OrderSubscriptionMessage subscription)
 {
     _client.Start();
     _client.OrderSubscription(subscription);
 }
Exemple #6
0
 /// <summary>
 /// Subscribe the the specified orders (syncronously) with the configured
 /// HeartbeatMS, ConflationMS.
 /// </summary>
 /// <param name="message"></param>
 public void OrderSubscription(OrderSubscriptionMessage message)
 {
     message.ConflateMs  = ConflateMs;
     message.HeartbeatMs = HeartbeatMs;
     WaitFor(_processor.OrderSubscription(message));
 }
        public IObservable<OrderMarketSnap> SubscribeOrders(string marketId, OrderSubscriptionMessage orderSubscription)
        {
            networkClient.Start();

            IObservable<OrderMarketSnap> orderObservable;
            if (orderObservables.TryGetValue(marketId, out orderObservable))
            {
                networkClient.OrderSubscription(orderSubscription);
                return orderObservable;
            }

            var observable = Observable.Create<OrderMarketSnap>(
               (IObserver<OrderMarketSnap> observer) =>
               {
                   orderObservers.AddOrUpdate(marketId, observer, (key, existingVal) => existingVal);

                   return Disposable.Create(() =>
                   {
                       IObserver<OrderMarketSnap> ob;
                       IObservable<OrderMarketSnap> o;
                       orderObservables.TryRemove(marketId, out o);
                       orderObservers.TryRemove(marketId, out ob);
                   });
               })
               .Publish()
               .RefCount();

            orderObservables.AddOrUpdate(marketId, observable, (key, existingVal) => existingVal);

            // TODO:// race?
            networkClient.OrderSubscription(orderSubscription);
            return observable;
        }
 public IObservable<OrderMarketSnap> SubscribeOrders(string marketId)
 {
     OrderSubscriptionMessage orderSubscription = new OrderSubscriptionMessage();
     return SubscribeOrders(marketId, orderSubscription);
 }