コード例 #1
0
        public void AdjustForLatestPrice(string exchange, ExchangePriceInfo exchangePriceInfo)
        {
            Prices[exchange] = exchangePriceInfo;

            decimal volumeWeightedPriceTotal = 0m;
            decimal volumeTotal = 0m;

            foreach (var p in Prices)
            {
                var(price, volume)        = (p.Value.Price, p.Value.Volume);
                volumeWeightedPriceTotal += price * volume;
                volumeTotal += volume;
            }

            VolumeWeightedPrice = Round(volumeWeightedPriceTotal / volumeTotal, 8);
        }
コード例 #2
0
        void OnPriceEvent(
            string currencyPair,
            string exchange,
            decimal price,
            decimal volume,
            decimal bid,
            decimal ask)
        {
            /*var previousPrice = priceInfoLookup.TryGetValue(currencyPair, out var priceInfo) ?
             *  priceInfo.Prices.TryGetValue(exchange, out var tuple) ? tuple.price : -1 : -1;
             *
             * if (price == previousPrice)
             *  return;*/

            priceInfoLookup.TryGetValue(currencyPair, out var priceInfo);

            priceInfo = priceInfo ?? new PriceInfo(currencyPair);
            var exchangePriceInfo = new ExchangePriceInfo(exchange, price, volume, bid, ask);

            priceInfo.AdjustForLatestPrice(exchange, exchangePriceInfo);
            priceInfoLookup[currencyPair] = priceInfo;
            var list = exchangeLookup.TryGetValue(exchange, out var exchangeCurrencyList) ? exchangeCurrencyList : new Dictionary <string, ExchangePriceInfo>();

            list[currencyPair]       = exchangePriceInfo;
            exchangeLookup[exchange] = list;

            var priceChange = new PriceChange
            {
                CurrencyPair        = currencyPair,
                VolumeWeightedPrice = priceInfo.VolumeWeightedPrice,
                Exchange            = exchange,
                Price      = price,
                HighestBid = bid,
                LowestAsk  = ask
            };

            OnPriceChangeAction?.OnPriceChange(priceChange);
        }