public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var response = new PricingStreamResponse();

            var jsonToken = JToken.Load(reader);

            if (jsonToken.Type == JTokenType.Object)
            {
                bool isHeartbeat = jsonToken["type"].Value <string>() == "HEARTBEAT";

                if (isHeartbeat)
                {
                    var heartbeat = new PricingHeartbeat();
                    serializer.Populate(jsonToken.CreateReader(), heartbeat);
                    response.heartbeat = heartbeat;
                }
                else
                {
                    Price price = new Price();
                    serializer.Populate(jsonToken.CreateReader(), price);
                    response.price = price;
                }

                return(response);
            }
            else
            {
                throw new ArgumentException(string.Format("Unexpected JTokenType ({0}) in reader.", jsonToken.Type.ToString()));
            }
        }
        public void Start()
        {
            var con = new WebClient();

            con.Headers.Add("Authorization", "Bearer " + OAndaCandleReader.BEARER);

            System.Action connect = () =>
            {
                con.OpenReadAsync(new System.Uri("https://stream-fxpractice.oanda.com/v3/accounts/" + OAndaCandleReader.ACCOUNT + "/pricing/stream?instruments=" + OAndaCandleReader.INSTRUMENTS));
            };

            con.OpenReadCompleted += (object sender, OpenReadCompletedEventArgs e) =>
            {
                try
                {
                    using (var streamReader = new System.IO.StreamReader(e.Result))
                    {
                        while (true)
                        {
                            var conteudo = streamReader.ReadLine();

                            ClientPrice      price     = null;
                            PricingHeartbeat heartbeat = null;

                            if (conteudo.Contains("\"type\":\"PRICE\""))
                            {
                                price = Newtonsoft.Json.JsonConvert.DeserializeObject <ClientPrice>(conteudo);
                            }
                            else
                            {
                                heartbeat = Newtonsoft.Json.JsonConvert.DeserializeObject <PricingHeartbeat>(conteudo);
                            }

                            var responsePrice = new InlineResponse20028();

                            responsePrice.Price     = price;
                            responsePrice.Heartbeat = heartbeat;

                            if (price != null)
                            {
                                this.OnPriceChanged(new PriceChangedEventArgs()
                                {
                                    PrecoVenda  = price.CloseoutAsk,
                                    PrecoCompra = price.CloseoutBid,
                                    Time        = price.Time
                                });
                            }
                        }
                    }
                }
                catch (System.Exception)
                {
                    connect();
                }
            };

            connect();
        }