Exemplo n.º 1
0
        public void ProcessSubscriptionEvent(string resp)
        {
            WebSocketSubscriptionResponse requestRespSubscr = JsonConvert.DeserializeObject <WebSocketSubscriptionResponse>(resp);

            if (requestRespSubscr.IsAuthentication())
            {
                if (requestRespSubscr.success)
                {
                    AuthSubscriptionResult.Authenticated = true;
                    //Good idea to calculate here the expiration of the token
                    AuthSubscriptionResult.ExpiresIn = Convert.ToInt32(requestRespSubscr.request.args[1]);
                }
                else
                {
                    AuthSubscriptionResult.Authenticated = false;

                    AuthSubscriptionResult.ErrorMessage = requestRespSubscr.error;

                    //abort = true;//we cannot continue requesting info if there was an authentication problem
                    //even for public serivces. Unless with this architecture
                }
            }
            else
            {
                DoRunLoopSubscriptions(resp);
            }
        }
Exemplo n.º 2
0
        public void OnEvent(string resp)
        {
            WebSocketResponseMessage wsResp = wsResp = JsonConvert.DeserializeObject <WebSocketResponseMessage>(resp);

            lock (tSubscrLock)
            {
                if (wsResp.IsResponse())//We have the response to a subscription
                {
                    WebSocketSubscriptionResponse requestRespSubscr = JsonConvert.DeserializeObject <WebSocketSubscriptionResponse>(resp);

                    if (ResponseRequestSubscriptions.ContainsKey(requestRespSubscr.GetSubscriptionEvent()))
                    {
                        WebSocketSubscriptionResponse requestRespEvent = ResponseRequestSubscriptions[requestRespSubscr.GetSubscriptionEvent()];

                        requestRespEvent.RunSubscritionEvent(requestRespSubscr);
                    }
                }
                else if (resp.Contains("error"))
                {
                    WebSocketErrorMessage wsError = JsonConvert.DeserializeObject <WebSocketErrorMessage>(resp);

                    if (wsError.request != null)
                    {
                        foreach (string ev in wsError.request.args)
                        {
                            string[] fields = ev.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                            string key    = fields[0];
                            string symbol = fields.Length > 1 ? fields[1] : null;

                            WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[key];

                            if (subscrEvent != null)
                            {
                                wsError.Symbol = symbol;
                                subscrEvent.RunEvent(wsError);
                            }
                        }
                    }
                    else
                    {
                        ProcessSubscriptionEvent(resp);
                    }
                }
                else //We have an event from a subscription
                {
                    ProcessSubscriptionEvent(resp);
                }
            }
        }
Exemplo n.º 3
0
        private void HandleGenericSubscription(WebSocketResponseMessage WebSocketResponseMessage)
        {
            WebSocketSubscriptionResponse resp = (WebSocketSubscriptionResponse)WebSocketResponseMessage;

            if (resp.success)
            {
                DoLog(string.Format("Successfully subscribed to {0} event on symbol {1}",
                                    resp.GetSubscriptionEvent(), resp.GetSubscriptionAsset()), Main.Common.Util.Constants.MessageType.Information);
            }
            else
            {
                Console.WriteLine(string.Format("Error on subscription to {0} event on symbol {1}:{2}",
                                                resp.GetSubscriptionEvent(), resp.GetSubscriptionAsset(), resp.error), Main.Common.Util.Constants.MessageType.Error);
            }
        }
Exemplo n.º 4
0
        protected void HandleGenericSubscription(WebSocketResponseMessage WebSocketResponseMessage)
        {
            WebSocketSubscriptionResponse resp = (WebSocketSubscriptionResponse)WebSocketResponseMessage;

            if (resp.success)
            {
                DoLog(string.Format("Successfully subscribed to {0} event ",
                                    resp.GetSubscriptionEvent()), Main.Common.Util.Constants.MessageType.Information);
            }
            else
            {
                DoLog(string.Format("Error on subscription to {0} event:{!}",
                                    resp.GetSubscriptionEvent(), resp.error), Main.Common.Util.Constants.MessageType.Error);
            }
        }
Exemplo n.º 5
0
        public void SubscribeResponseRequest(string topic, OnSubscritionEvent pOnSubscriptionEvent,
                                             object[] parameters = null)
        {
            WebSocketSubscriptionResponse msg = new WebSocketSubscriptionResponse()
            {
                topic      = topic,
                parameters = parameters,
            };

            msg.SetSubscritionEvent(pOnSubscriptionEvent);

            if (ResponseRequestSubscriptions == null)
            {
                throw new Exception(string.Format("Response Request Subscriptions Dictionary has not been initialized"));
            }
            ResponseRequestSubscriptions.Add(topic, msg);
        }