private void BinanceWebsocketPublic()
 {
     var successDepth = m_socketClient.SubscribeToDepthStream("bnbbtc", (data) =>
     {
         // handle data
     });
     var successTrades = m_socketClient.SubscribeToTradesStream("bnbbtc", (data) =>
     {
         // handle data
     });
     var successKline = m_socketClient.SubscribeToKlineStream("bnbbtc", KlineInterval.OneMinute, (data) =>
     {
         // handle data
     });
     var successSymbol = m_socketClient.SubscribeToSymbolTicker("bnbbtc", (data) =>
     {
         // handle data
     });
     var successSymbols = m_socketClient.SubscribeToAllSymbolTicker((data) =>
     {
         // handle data
     });
     var successOrderBook = m_socketClient.SubscribeToPartialBookDepthStream("bnbbtc", 10, (data) =>
     {
         // handle data
     });
 }
Ejemplo n.º 2
0
        private object SubscribeCandle(string instrument, string field, int interval)
        {
            var key = instrument + "|" + interval;

            if (SubscribedCandle.ContainsKey(key))
            {
                BinanceStreamKlineData stream;
                if (CandleCache.TryGetValue(key, out stream))
                {
                    return(DecodeCandle(stream, field));
                }
                else
                {
                    return(SubscriptionManager.UninitializedValue);
                }
            }
            else
            {
                KlineInterval klineInterval = (KlineInterval)interval;

                SubscribedCandle.Add(key, true);
                Task.Run(() => socketClient.SubscribeToKlineStream(instrument, klineInterval, (stream) =>
                {
                    CandleCache[key] = stream;
                    CacheCandle(stream, interval);
                }));
                return(SubscriptionManager.UninitializedValue);
            }
        }
Ejemplo n.º 3
0
        private void ProcessBuy(BinanceClient client, BinanceSocketClient socketClient, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            var subscribeSymbolTicker = socketClient.SubscribeToSymbolTicker("ETHSTORM", data => {
                var s = data;
            });

            if (subscribeSymbolTicker.Error != null)
            {
                _logger.LogError(subscribeSymbolTicker.Error.Message);
            }
            else
            {
                binanceHelper.AddToSubscriptionList("ETHSTORM", subscribeSymbolTicker.Data);
            }

            var subscribePair = socketClient.SubscribeToKlineStream("ETHSTORM", KlineInterval.FiveMinutes, data => {
                var s = data;
            });

            if (subscribePair.Error != null)
            {
                _logger.LogError(subscribePair.Error.Message);
            }
            else
            {
                binanceHelper.AddToSubscriptionList("ETHSTORM", subscribePair.Data);
            }
        }
Ejemplo n.º 4
0
        private async Task GetAllSymbols()
        {
            using (var client = new BinanceClient())
            {
                var result = await client.GetAllPricesAsync();

                if (result.Success)
                {
                    AllPrices = new ObservableCollection <BinanceSymbolViewModel>(result.Data.Select(r => new BinanceSymbolViewModel(r.Symbol, r.Price)).ToList());
                }
                else
                {
                    messageBoxService.ShowMessage($"Error requesting data: {result.Error.Message}", "error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            socketClient = new BinanceSocketClient();
            List <Task> tasks = new List <Task>();

            foreach (var symbol in AllPrices)
            {
                var task = new Task(() => socketClient.SubscribeToKlineStream(symbol.Symbol.ToLower(), KlineInterval.OneMinute, (data) =>
                {
                    symbol.Price = data.Data.Close;
                }));
                tasks.Add(task);
                task.Start();
            }
            Task.WaitAll(tasks.ToArray());
        }
Ejemplo n.º 5
0
        public void SubscribingToKlineStream_Should_TriggerWhenKlineStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect()).Returns(Task.FromResult(true));
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <Log>(), It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamKlineData result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToKlineStream("test", KlineInterval.OneMinute, (test) => result = test);

            var data = new BinanceCombinedStream <BinanceStreamKlineData>()
            {
                Stream = "test",
                Data   = new BinanceStreamKlineData()
                {
                    Event     = "TestKlineStream",
                    EventTime = new DateTime(2017, 1, 1),
                    Symbol    = "test",
                    Data      = new BinanceStreamKline()
                    {
                        TakerBuyBaseAssetVolume = 0.1m,
                        Close      = 0.2m,
                        CloseTime  = new DateTime(2017, 1, 2),
                        Final      = true,
                        FirstTrade = 10000000000,
                        High       = 0.3m,
                        Interval   = KlineInterval.OneMinute,
                        LastTrade  = 2000000000000,
                        Low        = 0.4m,
                        Open       = 0.5m,
                        TakerBuyQuoteAssetVolume = 0.6m,
                        QuoteAssetVolume         = 0.7m,
                        OpenTime   = new DateTime(2017, 1, 1),
                        Symbol     = "test",
                        TradeCount = 10,
                        Volume     = 0.8m
                    }
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, JsonConvert.SerializeObject(data));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(TestHelpers.PublicInstancePropertiesEqual(data.Data, result, "Data"));
            Assert.IsTrue(TestHelpers.PublicInstancePropertiesEqual(data.Data.Data, result.Data));
        }
Ejemplo n.º 6
0
        public void SubscribingToKlineStream_Should_TriggerWhenKlineStreamMessageIsReceived()
        {
            // arrange
            var socket = new Mock <IWebsocket>();

            socket.Setup(s => s.Close());
            socket.Setup(s => s.Connect());
            socket.Setup(s => s.Url).Returns("test");
            socket.Setup(s => s.SetEnabledSslProtocols(It.IsAny <System.Security.Authentication.SslProtocols>()));

            var factory = new Mock <IWebsocketFactory>();

            factory.Setup(s => s.CreateWebsocket(It.IsAny <string>())).Returns(socket.Object);

            BinanceStreamKline result = null;
            var client = new BinanceSocketClient {
                SocketFactory = factory.Object
            };

            client.SubscribeToKlineStream("test", KlineInterval.OneMinute, (test) => result = test);

            var data = new BinanceStreamKline()
            {
                Event     = "TestKlineStream",
                EventTime = new DateTime(2017, 1, 1),
                Symbol    = "test",
                Data      = new BinanceStreamKlineInner()
                {
                    ActiveBuyVolume      = 0.1,
                    Close                = 0.2,
                    EndTime              = new DateTime(2017, 1, 2),
                    Final                = true,
                    FirstTrade           = 10000000000,
                    High                 = 0.3,
                    Interval             = KlineInterval.OneMinute,
                    LastTrade            = 2000000000000,
                    Low                  = 0.4,
                    Open                 = 0.5,
                    QuoteActiveBuyVolume = 0.6,
                    QuoteVolume          = 0.7,
                    StartTime            = new DateTime(2017, 1, 1),
                    Symbol               = "test",
                    TradeCount           = 10,
                    Volume               = 0.8
                }
            };

            // act
            socket.Raise(r => r.OnMessage += null, new MessagedEventArgs(JsonConvert.SerializeObject(data), false, false, true, new byte[2]));

            // assert
            Assert.IsNotNull(result);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data, result, "Data"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(data.Data, result.Data));
        }
Ejemplo n.º 7
0
        public TradeResult TrailingTakeProfit(Trade trade)
        {
            TradeResult result       = new TradeResult();
            bool        active       = true;
            bool        canceled     = false;
            int         priceDecimal = BitConverter.GetBytes(decimal.GetBits(trade.TakeProfitPrice)[3])[2];

            using (var client = new BinanceSocketClient())
            {
                var successKline = client.SubscribeToKlineStream(build.Market, KlineInterval.OneMinute, (data) =>
                {
                    if (data.Data.High >= build.TakeProfitPrice)
                    {
                        active = false;
                    }
                });

                while (active)
                {
                    using (var clientRest = new BinanceClient())
                    {
                        var orderStatus = clientRest.QueryOrder(build.Market, trade.OrderId);
                        if (orderStatus.Success)
                        {
                            if (orderStatus.Data.Status == OrderStatus.Canceled)
                            {
                                canceled     = true;
                                active       = false;
                                trade.Status = false;
                                TradeDB tradeDB = new TradeDB();
                                tradeDB.Update(trade);
                            }
                        }
                    }
                }
            }
            if (!canceled)
            {
                decimal trailingTakePerc = build.TrailingTakePercent < 0 ? build.TrailingTakePercent * -1m : build.TrailingTakePercent;
                trade.StopLossPrice  = decimal.Round(build.TakeProfitPrice - (build.TakeProfitPrice * (trailingTakePerc / 100)), priceDecimal);
                trade.IsTrailingTake = true;
                trade.DisplayType    = "TSLVC";
                TradeDB tradeDB = new TradeDB();
                tradeDB.Update(trade);
                return(TrailingStopLoss(trade));
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            BinanceDefaults.SetDefaultApiCredentials("APIKEY", "APISECRET");
            BinanceDefaults.SetDefaultLogVerbosity(LogVerbosity.Debug);
            BinanceDefaults.SetDefaultLogOutput(Console.Out);

            using (var client = new BinanceClient())
                using (var socketClient = new BinanceSocketClient())
                {
                    // Public
                    var ping          = client.Ping();
                    var serverTime    = client.GetServerTime();
                    var orderBook     = client.GetOrderBook("BNBBTC", 10);
                    var aggTrades     = client.GetAggregatedTrades("BNBBTC", startTime: DateTime.UtcNow.AddMinutes(-2), endTime: DateTime.UtcNow, limit: 10);
                    var klines        = client.GetKlines("BNBBTC", KlineInterval.OneHour, startTime: DateTime.UtcNow.AddHours(-10), endTime: DateTime.UtcNow, limit: 10);
                    var prices24h     = client.Get24HPrices("BNBBTC");
                    var allPrices     = client.GetAllPrices();
                    var allBookPrices = client.GetAllBookPrices();

                    // Private
                    var openOrders      = client.GetOpenOrders("BNBBTC");
                    var allOrders       = client.GetAllOrders("BNBBTC");
                    var testOrderResult = client.PlaceTestOrder("BNBBTC", OrderSide.Buy, OrderType.Limit, TimeInForce.GoodTillCancel, 1, 1);
                    var queryOrder      = client.QueryOrder("BNBBTC", allOrders.Data[0].OrderId);
                    var orderResult     = client.PlaceOrder("BNBBTC", OrderSide.Sell, OrderType.Limit, TimeInForce.GoodTillCancel, 10, 0.0002);
                    var cancelResult    = client.CancelOrder("BNBBTC", orderResult.Data.OrderId);
                    var accountInfo     = client.GetAccountInfo();
                    var myTrades        = client.GetMyTrades("BNBBTC");


                    // Withdrawal/deposit
                    var withdrawalHistory = client.GetWithdrawHistory();
                    var depositHistory    = client.GetDepositHistory();
                    var withdraw          = client.Withdraw("ASSET", "ADDRESS", 0);


                    // Streams
                    var successDepth = socketClient.SubscribeToDepthStream("bnbbtc", (data) =>
                    {
                        // handle data
                    });
                    var successTrades = socketClient.SubscribeToTradesStream("bnbbtc", (data) =>
                    {
                        // handle data
                    });
                    var successKline = socketClient.SubscribeToKlineStream("bnbbtc", KlineInterval.OneMinute, (data) =>
                    {
                        // handle data
                    });

                    var successStart   = client.StartUserStream();
                    var successAccount = socketClient.SubscribeToAccountUpdateStream(successStart.Data.ListenKey, (data) =>
                    {
                        // handle data
                    });
                    var successOrder = socketClient.SubscribeToOrderUpdateStream(successStart.Data.ListenKey, (data) =>
                    {
                        // handle data
                    });

                    socketClient.UnsubscribeFromStream(successDepth.Data);
                    socketClient.UnsubscribeFromAccountUpdateStream();
                    socketClient.UnsubscribeAllStreams();
                }

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        public TradeResult MiddleOrderFlip(Trade trade)
        {
            // Take Profit Stop Loss Trailing Stop Loss
            decimal     middle            = build.TakeProfitPrice - ((build.TakeProfitPrice - build.StopLossPrice) / 2);
            bool        active            = true;
            bool        canceledSwap      = false;
            bool        take              = true;
            bool        initial           = true;
            bool        trailingTake      = false;
            int         iterationCanceled = 0;
            int         priceDecimal      = BitConverter.GetBytes(decimal.GetBits(trade.StopLossPrice)[3])[2];
            decimal     prevStopLossPrice = build.StopLossPrice;
            decimal     percentStop       = decimal.Round((build.StopLossPrice - build.Price) / build.Price * -1m, 2);
            TradeResult result            = new TradeResult();

            using (var client = new BinanceSocketClient())
            {
                var successKline = client.SubscribeToKlineStream(build.Market, KlineInterval.OneMinute, (data) =>
                {
                    if (trade.Status && iterationCanceled == 0)
                    {
                        if (build.TrailingStopLoss)
                        {
                            if (((trade.StopLossPrice - data.Data.High) / data.Data.High * -1) > percentStop)
                            {
                                prevStopLossPrice   = trade.StopLossPrice;
                                trade.StopLossPrice = decimal.Round(data.Data.High - (data.Data.High * percentStop), priceDecimal);
                                middle = trade.TakeProfitPrice - ((trade.TakeProfitPrice - trade.StopLossPrice) / 2);
                            }
                        }
                        if (data.Data.Low > middle && !take)
                        {
                            if (!build.TrailingTakeProfit)
                            {
                                Cancel cancel = new Cancel();
                                if (cancel.Trade(trade))
                                {
                                    canceledSwap = true;
                                    Sell sell    = new Sell(build, api);
                                    trade        = sell.Limit(trade, trade.TakeProfitPrice);
                                    if (trade.Success)
                                    {
                                        canceledSwap    = false;
                                        TradeDB tradeDB = new TradeDB();
                                        tradeDB.Update(trade);
                                        take = true;
                                    }
                                }
                            }
                            else if (data.Data.High > trade.TakeProfitPrice)
                            {
                                trailingTake = true;
                            }
                        }
                        else if (data.Data.Low <= middle && take || data.Data.Low <= middle && initial || trade.StopLossPrice > prevStopLossPrice && data.Data.Low <= middle)
                        {
                            Cancel cancel = new Cancel();
                            if (cancel.Trade(trade) || initial)
                            {
                                canceledSwap = true;
                                Sell sell    = new Sell(build, api);
                                trade        = sell.LimitStop(trade, trade.StopLossPrice);
                                if (trade.Success)
                                {
                                    canceledSwap    = false;
                                    TradeDB tradeDB = new TradeDB();
                                    tradeDB.Update(trade);
                                    take = false;
                                }
                            }
                        }
                        initial = false;
                    }
                });

                while (active && !trailingTake)
                {
                    using (var db = new ApplicationDbContext())
                    {
                        Trade tradeGrab = db.Trades.Where(t => t.Id == trade.Id).Single();
                        if (!tradeGrab.Status)
                        {
                            trade.Status = false;
                        }
                    }
                    using (var clientRest = new BinanceClient())
                    {
                        var orderStatus = clientRest.QueryOrder(build.Market, trade.OrderId);
                        if (orderStatus.Success)
                        {
                            if (orderStatus.Data.Status == OrderStatus.Filled)
                            {
                                result.SellPrice   = orderStatus.Data.Price;
                                result.SellOrderId = trade.OrderId;
                                result.TradeId     = trade.Id;
                                result.EndTime     = DateTime.Now;
                                CalculateResult calculate = new CalculateResult();
                                result         = calculate.PercentDifference(result, trade);
                                result.Success = true;
                                active         = false;
                            }
                            if (orderStatus.Data.Status == OrderStatus.Canceled && !canceledSwap)
                            {
                                iterationCanceled++;
                                if (iterationCanceled > 4)
                                {
                                    active       = false;
                                    trade.Status = false;
                                    TradeDB tradeDB = new TradeDB();
                                    tradeDB.Update(trade);
                                }
                                System.Threading.Thread.Sleep(5000);
                            }
                            else if (orderStatus.Data.Status != OrderStatus.Canceled)
                            {
                                iterationCanceled = 0;
                            }
                        }
                    }
                }
            }
            if (trailingTake == true)
            {
                decimal trailingTakePerc = build.TrailingTakePercent < 0 ? build.TrailingTakePercent * -1m : build.TrailingTakePercent;
                trade.StopLossPrice  = decimal.Round(build.TakeProfitPrice - (build.TakeProfitPrice * (trailingTakePerc / 100)), priceDecimal);
                trade.IsTrailingTake = true;
                trade.DisplayType    = "TSLVC";
                TradeDB tradeDB = new TradeDB();
                tradeDB.Update(trade);
                return(TrailingStopLoss(trade));
            }
            else
            {
                return(result);
            }
        }
Ejemplo n.º 10
0
        public TradeResult TrailingStopLoss(Trade trade)
        {
            bool        canceledSwap      = false;
            int         iterationCanceled = 0;
            bool        active            = true;
            int         priceDecimal      = BitConverter.GetBytes(decimal.GetBits(trade.StopLossPrice)[3])[2];
            decimal     prevStopLossPrice = build.StopLossPrice;
            decimal     percentStop       = decimal.Round((build.StopLossPrice - build.Price) / build.Price * -1, 3);
            TradeResult result            = new TradeResult();

            using (var client = new BinanceSocketClient())
            {
                var successKline = client.SubscribeToKlineStream(build.Market, KlineInterval.OneMinute, (data) =>
                {
                    if (trade.Status && iterationCanceled == 0)
                    {
                        decimal newPercentDiff = decimal.Round((trade.StopLossPrice - data.Data.High) / data.Data.High, 3);
                        newPercentDiff         = newPercentDiff < 0 ? newPercentDiff * -1m : newPercentDiff;
                        if (newPercentDiff > percentStop)
                        {
                            trade.StopLossPrice = decimal.Round(data.Data.High - (data.Data.High * percentStop), priceDecimal);
                            Cancel cancel       = new Cancel();
                            if (cancel.Trade(trade))
                            {
                                canceledSwap = true;
                                Sell sell    = new Sell(build, api);
                                trade        = sell.LimitStop(trade, trade.StopLossPrice);
                                if (trade.Success)
                                {
                                    canceledSwap    = false;
                                    TradeDB tradeDB = new TradeDB();
                                    tradeDB.Update(trade);
                                }
                            }
                        }
                    }
                });

                while (active)
                {
                    using (var db = new ApplicationDbContext())
                    {
                        Trade tradeGrab = db.Trades.Where(t => t.Id == trade.Id).Single();
                        if (!tradeGrab.Status)
                        {
                            trade.Status = false;
                        }
                    }
                    using (var clientRest = new BinanceClient())
                    {
                        var orderStatus = clientRest.QueryOrder(build.Market, trade.OrderId);
                        if (orderStatus.Success)
                        {
                            if (orderStatus.Data.Status == OrderStatus.Filled)
                            {
                                result.SellPrice   = orderStatus.Data.Price;
                                result.SellOrderId = trade.OrderId;
                                result.TradeId     = trade.Id;
                                result.EndTime     = DateTime.Now;
                                CalculateResult calculate = new CalculateResult();
                                result         = calculate.PercentDifference(result, trade);
                                result.Success = true;
                                active         = false;
                            }
                            if (orderStatus.Data.Status == OrderStatus.Canceled && !canceledSwap)
                            {
                                iterationCanceled++;
                                if (iterationCanceled > 4)
                                {
                                    active       = false;
                                    trade.Status = false;
                                    TradeDB tradeDB = new TradeDB();
                                    tradeDB.Update(trade);
                                }
                                System.Threading.Thread.Sleep(5000);
                            }
                            else if (orderStatus.Data.Status != OrderStatus.Canceled)
                            {
                                iterationCanceled = 0;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            BinanceClient.SetDefaultOptions(new BinanceClientOptions()
            {
                ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"),
                LogVerbosity   = LogVerbosity.Debug,
                LogWriters     = new List <TextWriter> {
                    Console.Out
                }
            });
            BinanceSocketClient.SetDefaultOptions(new BinanceSocketClientOptions()
            {
                ApiCredentials = new ApiCredentials("APIKEY", "APISECRET"),
                LogVerbosity   = LogVerbosity.Debug,
                LogWriters     = new List <TextWriter> {
                    Console.Out
                }
            });

            using (var client = new BinanceClient())
            {
                // Public
                var ping             = client.Ping();
                var exchangeInfo     = client.GetExchangeInfo();
                var serverTime       = client.GetServerTime();
                var orderBook        = client.GetOrderBook("BNBBTC", 10);
                var aggTrades        = client.GetAggregatedTrades("BNBBTC", startTime: DateTime.UtcNow.AddMinutes(-2), endTime: DateTime.UtcNow, limit: 10);
                var klines           = client.GetKlines("BNBBTC", KlineInterval.OneHour, startTime: DateTime.UtcNow.AddHours(-10), endTime: DateTime.UtcNow, limit: 10);
                var price            = client.GetPrice("BNBBTC");
                var prices24h        = client.Get24HPrice("BNBBTC");
                var allPrices        = client.GetAllPrices();
                var allBookPrices    = client.GetAllBookPrices();
                var historicalTrades = client.GetHistoricalTrades("BNBBTC");

                // Private
                var openOrders      = client.GetOpenOrders("BNBBTC");
                var allOrders       = client.GetAllOrders("BNBBTC");
                var testOrderResult = client.PlaceTestOrder("BNBBTC", OrderSide.Buy, OrderType.Limit, 1, price: 1, timeInForce: TimeInForce.GoodTillCancel);
                var queryOrder      = client.QueryOrder("BNBBTC", allOrders.Data[0].OrderId);
                var orderResult     = client.PlaceOrder("BNBBTC", OrderSide.Sell, OrderType.Limit, 10, price: 0.0002m, timeInForce: TimeInForce.GoodTillCancel);
                var cancelResult    = client.CancelOrder("BNBBTC", orderResult.Data.OrderId);
                var accountInfo     = client.GetAccountInfo();
                var myTrades        = client.GetMyTrades("BNBBTC");

                // Withdrawal/deposit
                var withdrawalHistory = client.GetWithdrawHistory();
                var depositHistory    = client.GetDepositHistory();
                var withdraw          = client.Withdraw("ASSET", "ADDRESS", 0);
            }

            var socketClient = new BinanceSocketClient();
            // Streams
            var successDepth = socketClient.SubscribeToDepthStream("bnbbtc", (data) =>
            {
                // handle data
            });
            var successTrades = socketClient.SubscribeToTradesStream("bnbbtc", (data) =>
            {
                // handle data
            });
            var successKline = socketClient.SubscribeToKlineStream("bnbbtc", KlineInterval.OneMinute, (data) =>
            {
                // handle data
            });
            var successTicker = socketClient.SubscribeToAllSymbolTicker((data) =>
            {
                // handle data
            });
            var successSingleTicker = socketClient.SubscribeToSymbolTicker("bnbbtc", (data) =>
            {
                // handle data
            });

            string listenKey;

            using (var client = new BinanceClient())
                listenKey = client.StartUserStream().Data.ListenKey;

            var successAccount = socketClient.SubscribeToUserStream(listenKey, data =>
            {
                // Hanlde account info data
            },
                                                                    data =>
            {
                // Hanlde order update info data
            });

            socketClient.UnsubscribeAllStreams();

            Console.ReadLine();
        }
Ejemplo n.º 12
0
        private async Task GetAllSymbols()
        {
            using (var client = new BinanceClient())
            {
                var result = await client.GetAllPricesAsync();

                if (result.Success)
                {
                    AllPrices = new ObservableCollection <BinanceSymbolViewModel>(result.Data.Select(r => new BinanceSymbolViewModel(r.Symbol, r.Price)).OrderBy(s => s.SymbolCurrency).ThenBy(s => s.SymbolAsset).ToList());

                    foreach (var price in AllPrices)
                    {
                        if (CurrencyDictionary.ContainsKey(price.SymbolCurrency))
                        {
                            if (!CurrencyDictionary[price.SymbolCurrency].Contains(price.SymbolAsset))
                            {
                                CurrencyDictionary[price.SymbolCurrency].Add(price.SymbolAsset);
                            }
                        }
                        else
                        {
                            CurrencyDictionary.Add(price.SymbolCurrency, new ObservableCollection <string> {
                                price.SymbolAsset
                            });
                        }

                        if (AssetDictionary.ContainsKey(price.SymbolAsset))
                        {
                            if (!AssetDictionary[price.SymbolAsset].Contains(price.SymbolCurrency))
                            {
                                AssetDictionary[price.SymbolAsset].Add(price.SymbolCurrency);
                            }
                        }
                        else
                        {
                            AssetDictionary.Add(price.SymbolAsset, new ObservableCollection <string> {
                                price.SymbolCurrency
                            });
                        }
                    }

                    var cdKeys = CurrencyDictionary.Keys.ToList();
                    var adKeys = AssetDictionary.Keys.ToList();
                    for (int k = 0; k < cdKeys.Count; k++)
                    {
                        CurrencyDictionary[cdKeys[k]] = new ObservableCollection <string>(CurrencyDictionary[cdKeys[k]].OrderBy(v => v));
                    }
                    for (int k = 0; k < adKeys.Count; k++)
                    {
                        AssetDictionary[adKeys[k]] = new ObservableCollection <string>(AssetDictionary[adKeys[k]].OrderBy(v => v));
                    }
                }
                else
                {
                    messageBoxService.ShowMessage($"Error getting all symbols data.\n{result.Error.Message}", $"Error Code: {result.Error.Code}", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            List <Task> tasks = new List <Task>();

            foreach (var symbol in AllPrices)
            {
                var task = new Task(() => binanceSocketClient.SubscribeToKlineStream(symbol.Symbol.ToLower(), KlineInterval.OneMinute, (data) =>
                {
                    symbol.Price = data.Data.Close;
                }));
                tasks.Add(task);
                task.Start();
            }
            Task.WaitAll(tasks.ToArray());
        }