private static void Display(SymbolStatistics statsistics)
        {
            lock (_sync)
            {
                _statistics[statsistics.Symbol] = statsistics;

                if (_displayTask.IsCompleted)
                {
                    // Delay to allow multiple data updates between display updates.
                    _displayTask = Task.Delay(100)
                                   .ContinueWith(_ =>
                    {
                        SymbolStatistics[] latestStatistics;
                        lock (_sync)
                        {
                            latestStatistics = _statistics.Values.ToArray();
                        }

                        Console.SetCursorPosition(0, 0);

                        foreach (var stats in latestStatistics)
                        {
                            Console.WriteLine($"  24-hour statistics for {stats.Symbol}:");
                            Console.WriteLine($"    %: {stats.PriceChangePercent:0.00} | O: {stats.OpenPrice:0.00000000} | H: {stats.HighPrice:0.00000000} | L: {stats.LowPrice:0.00000000} | V: {stats.Volume:0.}");
                            Console.WriteLine($"    Bid: {stats.BidPrice:0.00000000} | Last: {stats.LastPrice:0.00000000} | Ask: {stats.AskPrice:0.00000000} | Avg: {stats.WeightedAveragePrice:0.00000000}");
                            Console.WriteLine();
                        }

                        Console.WriteLine(_message);
                    });
                }
            }
        }
        public void Equality()
        {
            var           symbol               = Symbol.BTC_USDT;
            var           period               = TimeSpan.FromHours(24);
            const decimal priceChange          = 50;
            const decimal priceChangePercent   = 1;
            const decimal weightedAveragePrice = 5001;
            const decimal previousClosePrice   = 4900;
            const decimal lastPrice            = 5000;
            const decimal lastQuantity         = 1;
            const decimal bidPrice             = 4995;
            const decimal bidQuantity          = 2;
            const decimal askPrice             = 5005;
            const decimal askQuantity          = 3;
            const decimal openPrice            = 4950;
            const decimal highPrice            = 5025;
            const decimal lowPrice             = 4925;
            const decimal volume               = 100000;
            const decimal quoteVolume          = 200000;
            var           openTime             = DateTimeOffset.FromUnixTimeMilliseconds(DateTime.UtcNow.ToTimestamp()).UtcDateTime;
            var           closeTime            = openTime.AddHours(24);
            const long    firstTradeId         = 123456;
            const long    lastTradeId          = 234567;
            const long    tradeCount           = lastTradeId - firstTradeId + 1;

            var stats = new SymbolStatistics(symbol, period, priceChange, priceChangePercent, weightedAveragePrice, previousClosePrice, lastPrice, lastQuantity, bidPrice, bidQuantity, askPrice, askQuantity, openPrice, highPrice, lowPrice, volume, quoteVolume, openTime, closeTime, firstTradeId, lastTradeId, tradeCount);

            var serializer = new SymbolStatisticsSerializer();

            var json = serializer.Serialize(stats);

            var other = serializer.Deserialize(json);

            Assert.True(stats.Equals(other));
        }
        private void InitializeSymbolStatisticsList()
        {
            symbolStatisticsList = new List <SymbolStatistics>();

            SymbolStatistics symbolA = new SymbolStatistics();

            symbolA.InputFileBitsLength  = 8;
            symbolA.OutputFileBitsLength = 2;
            symbolA.Probability          = 0.2;
            symbolStatisticsList.Add(symbolA);

            SymbolStatistics symbolB = new SymbolStatistics();

            symbolB.InputFileBitsLength  = 8;
            symbolB.OutputFileBitsLength = 2;
            symbolB.Probability          = 0.3;
            symbolStatisticsList.Add(symbolB);

            SymbolStatistics symbolC = new SymbolStatistics();

            symbolC.InputFileBitsLength  = 8;
            symbolC.OutputFileBitsLength = 2;
            symbolC.Probability          = 0.5;
            symbolStatisticsList.Add(symbolC);
        }
Exemplo n.º 4
0
 private Interface.Model.SymbolStats NewSymbolStats(SymbolStatistics s)
 {
     return(new Interface.Model.SymbolStats
     {
         FirstTradeId = s.FirstTradeId,
         CloseTime = s.CloseTime,
         OpenTime = s.OpenTime,
         QuoteVolume = s.QuoteVolume,
         Volume = s.Volume,
         LowPrice = s.LowPrice,
         HighPrice = s.HighPrice,
         OpenPrice = s.OpenPrice,
         AskQuantity = s.AskQuantity,
         AskPrice = s.AskPrice,
         BidQuantity = s.BidQuantity,
         BidPrice = s.BidPrice,
         LastQuantity = s.LastQuantity,
         LastPrice = s.LastPrice,
         PreviousClosePrice = s.PreviousClosePrice,
         WeightedAveragePrice = s.WeightedAveragePrice,
         PriceChangePercent = s.PriceChangePercent,
         PriceChange = s.PriceChange,
         Period = s.Period,
         Symbol = s.Symbol,
         LastTradeId = s.LastTradeId,
         TradeCount = s.TradeCount
     });
 }
Exemplo n.º 5
0
        public virtual string Serialize(SymbolStatistics statistics)
        {
            Throw.IfNull(statistics, nameof(statistics));

            var jObject = new JObject
            {
                new JProperty(KeySymbol, statistics.Symbol),
                new JProperty(KeyPriceChange, statistics.PriceChange.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyPriceChangePercent, statistics.PriceChangePercent.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyWeightedAveragePrice, statistics.WeightedAveragePrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyPreviousClosePrice, statistics.PreviousClosePrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyLastPrice, statistics.LastPrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyLastQuantity, statistics.LastQuantity.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyBidPrice, statistics.BidPrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyBidQuantity, statistics.BidQuantity.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyAskPrice, statistics.AskPrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyAskQuantity, statistics.AskQuantity.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyOpenPrice, statistics.OpenPrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyHighPrice, statistics.HighPrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyLowPrice, statistics.LowPrice.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyVolume, statistics.Volume.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyQuoteVolume, statistics.QuoteVolume.ToString(CultureInfo.InvariantCulture)),
                new JProperty(KeyOpenTime, statistics.OpenTime.ToTimestamp()),
                new JProperty(KeyCloseTime, statistics.CloseTime.ToTimestamp()),
                new JProperty(KeyFirstTradeId, statistics.FirstTradeId),
                new JProperty(KeyLastTradeId, statistics.LastTradeId),
                new JProperty(KeyTradeCount, statistics.TradeCount)
            };

            return(jObject.ToString(Formatting.None));
        }
Exemplo n.º 6
0
        public void Serialization()
        {
            var           symbol               = Symbol.BTC_USDT;
            var           period               = TimeSpan.FromHours(24);
            const decimal priceChange          = 50;
            const decimal priceChangePercent   = 1;
            const decimal weightedAveragePrice = 5001;
            const decimal previousClosePrice   = 4900;
            const decimal lastPrice            = 5000;
            const decimal lastQuantity         = 1;
            const decimal bidPrice             = 4995;
            const decimal bidQuantity          = 2;
            const decimal askPrice             = 5005;
            const decimal askQuantity          = 3;
            const decimal openPrice            = 4950;
            const decimal highPrice            = 5025;
            const decimal lowPrice             = 4925;
            const decimal volume               = 100000;
            const decimal quoteVolume          = 200000;
            var           openTime             = DateTimeOffset.FromUnixTimeMilliseconds(DateTime.UtcNow.ToTimestamp()).UtcDateTime;
            var           closeTime            = openTime.AddHours(24);
            const long    firstTradeId         = 123456;
            const long    lastTradeId          = 234567;
            const long    tradeCount           = lastTradeId - firstTradeId + 1;

            var stats = new SymbolStatistics(symbol, period, priceChange, priceChangePercent, weightedAveragePrice, previousClosePrice, lastPrice, lastQuantity, bidPrice, bidQuantity, askPrice, askQuantity, openPrice, highPrice, lowPrice, volume, quoteVolume, openTime, closeTime, firstTradeId, lastTradeId, tradeCount);

            var settings = new JsonSerializerSettings();

            settings.Converters.Add(new TimestampJsonConverter());

            var json = JsonConvert.SerializeObject(stats, settings);

            stats = JsonConvert.DeserializeObject <SymbolStatistics>(json, settings);

            Assert.Equal(symbol, stats.Symbol);
            Assert.Equal(priceChange, stats.PriceChange);
            Assert.Equal(priceChangePercent, stats.PriceChangePercent);
            Assert.Equal(weightedAveragePrice, stats.WeightedAveragePrice);
            Assert.Equal(previousClosePrice, stats.PreviousClosePrice);
            Assert.Equal(lastPrice, stats.LastPrice);
            Assert.Equal(lastQuantity, stats.LastQuantity);
            Assert.Equal(bidPrice, stats.BidPrice);
            Assert.Equal(bidQuantity, stats.BidQuantity);
            Assert.Equal(askPrice, stats.AskPrice);
            Assert.Equal(askQuantity, stats.AskQuantity);
            Assert.Equal(openPrice, stats.OpenPrice);
            Assert.Equal(highPrice, stats.HighPrice);
            Assert.Equal(lowPrice, stats.LowPrice);
            Assert.Equal(volume, stats.Volume);
            Assert.Equal(quoteVolume, stats.QuoteVolume);
            Assert.Equal(openTime, stats.OpenTime);
            Assert.Equal(closeTime, stats.CloseTime);
            Assert.Equal(firstTradeId, stats.FirstTradeId);
            Assert.Equal(lastTradeId, stats.LastTradeId);
            Assert.Equal(tradeCount, stats.TradeCount);
        }
Exemplo n.º 7
0
 internal static void Display(SymbolStatistics stats)
 {
     lock (ConsoleSync)
     {
         Console.WriteLine($"  24-hour statistics for {stats.Symbol}:");
         Console.WriteLine($"    %: {stats.PriceChangePercent:0.00} | O: {stats.OpenPrice:0.00000000} | H: {stats.HighPrice:0.00000000} | L: {stats.LowPrice:0.00000000} | V: {stats.Volume:0.}");
         Console.WriteLine($"    Bid: {stats.BidPrice:0.00000000} | Last: {stats.LastPrice:0.00000000} | Ask: {stats.AskPrice:0.00000000} | Avg: {stats.WeightedAveragePrice:0.00000000}");
         Console.WriteLine();
     }
 }
Exemplo n.º 8
0
        public static Symbol JoinStatistics(this Symbol sy, SymbolStatistics st)
        {
            if (sy == null)
            {
                throw new ArgumentNullException(nameof(sy));
            }

            sy.SymbolStatistics            = st ?? throw new ArgumentNullException(nameof(st));
            sy.PriceChangePercentDirection = sy.SymbolStatistics.PriceChangePercent > 0 ? 1 : sy.SymbolStatistics.PriceChangePercent < 0 ? -1 : 0;
            return(sy);
        }
        public void Properties()
        {
            var           symbol               = Symbol.BTC_USDT;
            var           period               = TimeSpan.FromHours(24);
            const decimal priceChange          = 50;
            const decimal priceChangePercent   = 1;
            const decimal weightedAveragePrice = 5001;
            const decimal previousClosePrice   = 4900;
            const decimal lastPrice            = 5000;
            const decimal lastQuantity         = 1;
            const decimal bidPrice             = 4995;
            const decimal bidQuantity          = 2;
            const decimal askPrice             = 5005;
            const decimal askQuantity          = 3;
            const decimal openPrice            = 4950;
            const decimal highPrice            = 5025;
            const decimal lowPrice             = 4925;
            const decimal volume               = 100000;
            const decimal quoteVolume          = 200000;
            var           openTime             = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            var           closeTime            = DateTimeOffset.FromUnixTimeMilliseconds(openTime).AddHours(24).ToUnixTimeMilliseconds();
            const long    firstTradeId         = 123456;
            const long    lastTradeId          = 234567;
            const long    tradeCount           = lastTradeId - firstTradeId + 1;

            var stats = new SymbolStatistics(symbol, period, priceChange, priceChangePercent, weightedAveragePrice, previousClosePrice, lastPrice, lastQuantity, bidPrice, bidQuantity, askPrice, askQuantity, openPrice, highPrice, lowPrice, volume, quoteVolume, openTime, closeTime, firstTradeId, lastTradeId, tradeCount);

            Assert.Equal(symbol, stats.Symbol);
            Assert.Equal(priceChange, stats.PriceChange);
            Assert.Equal(priceChangePercent, stats.PriceChangePercent);
            Assert.Equal(weightedAveragePrice, stats.WeightedAveragePrice);
            Assert.Equal(previousClosePrice, stats.PreviousClosePrice);
            Assert.Equal(lastPrice, stats.LastPrice);
            Assert.Equal(lastQuantity, stats.LastQuantity);
            Assert.Equal(bidPrice, stats.BidPrice);
            Assert.Equal(bidQuantity, stats.BidQuantity);
            Assert.Equal(askPrice, stats.AskPrice);
            Assert.Equal(askQuantity, stats.AskQuantity);
            Assert.Equal(openPrice, stats.OpenPrice);
            Assert.Equal(highPrice, stats.HighPrice);
            Assert.Equal(lowPrice, stats.LowPrice);
            Assert.Equal(volume, stats.Volume);
            Assert.Equal(quoteVolume, stats.QuoteVolume);
            Assert.Equal(openTime, stats.OpenTime);
            Assert.Equal(closeTime, stats.CloseTime);
            Assert.Equal(firstTradeId, stats.FirstTradeId);
            Assert.Equal(lastTradeId, stats.LastTradeId);
            Assert.Equal(tradeCount, stats.TradeCount);
        }
Exemplo n.º 10
0
        public List <SymbolStatistics> CreateSymbolStatisticsList(Dictionary <string, OutputValues> symbolsMap, int symbolsCount)
        {
            List <SymbolStatistics> symbolStatisticsList = new List <SymbolStatistics>();

            foreach (KeyValuePair <string, OutputValues> entry in symbolsMap)
            {
                SymbolStatistics symbol = new SymbolStatistics();
                symbol.Probability          = (double)entry.Value.Counts / (double)symbolsCount;
                symbol.OutputFileBitsLength = entry.Value.BitsLength;
                symbol.InputFileBitsLength  = GetBitsLengthFromStringSymbol(entry.Key);

                symbolStatisticsList.Add(symbol);
            }

            return(symbolStatisticsList);
        }
Exemplo n.º 11
0
 public static Symbol JoinStatistics(this Symbol sy, SymbolStatistics st)
 {
     sy.SymbolStatistics            = st;
     sy.PriceChangePercentDirection = sy.SymbolStatistics.PriceChangePercent > 0 ? 1 : sy.SymbolStatistics.PriceChangePercent < 0 ? -1 : 0;
     return(sy);
 }