Beispiel #1
0
        public DepthMessage GetParsedDepthMessage(dynamic messageData)
        {
            var result = new DepthMessage
            {
                EventType = messageData.e,
                EventTime = messageData.E,
                Symbol    = messageData.s,
                UpdateId  = messageData.u
            };

            var bids = new List <OrderBookOffer>();
            var asks = new List <OrderBookOffer>();

            foreach (JToken item in ((JArray)messageData.b).ToArray())
            {
                bids.Add(new OrderBookOffer()
                {
                    Price = decimal.Parse(item[0].ToString()), Quantity = decimal.Parse(item[1].ToString())
                });
            }

            foreach (JToken item in ((JArray)messageData.a).ToArray())
            {
                asks.Add(new OrderBookOffer()
                {
                    Price = decimal.Parse(item[0].ToString()), Quantity = decimal.Parse(item[1].ToString())
                });
            }

            result.Bids = bids;
            result.Asks = asks;

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the parsed depth message.
        /// </summary>
        /// <param name="messageData">The message data.</param>
        /// <returns>A DepthMessage.</returns>
        public DepthMessage GetParsedDepthMessage(dynamic messageData)
        {
            DepthMessage result = new DepthMessage
            {
                EventType = messageData.e,
                EventTime = messageData.E,
                Symbol    = messageData.s,
                UpdateId  = messageData.u
            };

            List <OrderBookOffer> bids = ((JArray)messageData.b).ToArray().Select(item => new OrderBookOffer()
            {
                Price = decimal.Parse(item[0].ToString()), Quantity = decimal.Parse(item[1].ToString())
            }).ToList();

            List <OrderBookOffer> asks = ((JArray)messageData.a).ToArray().Select(item => new OrderBookOffer()
            {
                Price = decimal.Parse(item[0].ToString()), Quantity = decimal.Parse(item[1].ToString())
            }).ToList();

            result.Bids = bids;
            result.Asks = asks;

            return(result);
        }
        public DepthMessage GetParsedDepthMessage(dynamic messageData)
        {
            try
            {
                var result = new DepthMessage
                {
                    EventType = messageData.e,
                    EventTime = messageData.E,
                    Symbol    = messageData.s,
                    UpdateId  = messageData.u
                };

                var bids = new List <OrderBookOffer>();
                var asks = new List <OrderBookOffer>();

                foreach (JToken item in ((JArray)messageData.b).ToArray())
                {
                    bids.Add(Convert(item));
                }

                foreach (JToken item in ((JArray)messageData.a).ToArray())
                {
                    asks.Add(Convert(item));
                }

                result.Bids = bids;
                result.Asks = asks;

                return(result);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Beispiel #4
0
        public DepthMessage GetParsedDepthMessage(dynamic messageData)
        {
            DepthMessage result = new DepthMessage();

            result.UpdateId = messageData.lastUpdateId;

            /*DepthMessage result = new DepthMessage
             * {
             *  //EventType = messageData.e,
             *  //EventTime = messageData.E,
             *  //Symbol = messageData.s,
             *  UpdateId = messageData.lastUpdateId //messageData.u
             * };*/

            List <OrderBookOffer> bids = new List <OrderBookOffer>();
            List <OrderBookOffer> asks = new List <OrderBookOffer>();

            JToken[] barray = ((JArray)messageData.bids).ToArray();
            foreach (JToken item in barray)
            {
                bids.Add(new OrderBookOffer()
                {
                    Price    = Convert.ToDecimal(item[0].ToString().Replace(',', '.'), CultureInfo.InvariantCulture),
                    Quantity = Convert.ToDecimal(item[1].ToString().Replace(',', '.'), CultureInfo.InvariantCulture)
                });
            }
            JToken[] aarray = ((JArray)messageData.asks).ToArray();
            foreach (JToken item in aarray)
            {
                asks.Add(new OrderBookOffer()
                {
                    Price    = Convert.ToDecimal(item[0].ToString().Replace(',', '.'), CultureInfo.InvariantCulture),
                    Quantity = Convert.ToDecimal(item[1].ToString().Replace(',', '.'), CultureInfo.InvariantCulture)
                });
            }

            result.Bids = bids;
            result.Asks = asks;

            return(result);
        }
Beispiel #5
0
            private void depthHandler(DepthMessage dmessage)
            {
                if (InHandler)
                {
                    return;
                }
                InHandler = true;

                var resTicker = new BaseTypes.Ticker()
                {
                    Ask = dmessage.Asks.ElementAt(0).Price,
                    Bid = dmessage.Bids.ElementAt(0).Price
                };

                lock (LocalLockWebSocket)
                {
                    foreach (var thand in CurPriceActions)
                    {
                        thand(resTicker);
                    }
                }
                InHandler = false;
            }
Beispiel #6
0
 private void DepthHandler(DepthMessage messageData)
 {
     var depthData = messageData;
 }