public static MarketSlice ToMarketSlice(this HashEntry[] hashEntry) { var marketSlice = new MarketSlice(); var hashDict = hashEntry.ToDictionary(); if (hashDict.TryGetValue(nameof(MarketSlice.AssetPairId), out var assetPair)) { marketSlice.AssetPairId = assetPair; } if (hashDict.TryGetValue(nameof(MarketSlice.LastPrice), out var lastPrice)) { marketSlice.LastPrice = lastPrice; } if (hashDict.TryGetValue(nameof(MarketSlice.Bid), out var bid)) { marketSlice.Bid = bid; } if (hashDict.TryGetValue(nameof(MarketSlice.Ask), out var ask)) { marketSlice.Ask = ask; } return(marketSlice); }
internal static Ticker ToTicker(this MarketSlice marketSlice) { return(new Ticker(marketSlice.AssetPairId) { AssetPairId = marketSlice.AssetPairId, VolumeBase = string.IsNullOrEmpty(marketSlice.VolumeBase) ? 0 : decimal.Parse(marketSlice.VolumeBase, NumberStyles.Any, CultureInfo.InvariantCulture), VolumeQuote = string.IsNullOrEmpty(marketSlice.VolumeQuote) ? 0 : decimal.Parse(marketSlice.VolumeQuote, NumberStyles.Any, CultureInfo.InvariantCulture), PriceChange = string.IsNullOrEmpty(marketSlice.PriceChange) ? 0 : decimal.Parse(marketSlice.PriceChange, NumberStyles.Any, CultureInfo.InvariantCulture), LastPrice = string.IsNullOrEmpty(marketSlice.LastPrice) ? 0 : decimal.Parse(marketSlice.LastPrice, NumberStyles.Any, CultureInfo.InvariantCulture), High = string.IsNullOrEmpty(marketSlice.High) ? 0 : decimal.Parse(marketSlice.High, NumberStyles.Any, CultureInfo.InvariantCulture), Low = string.IsNullOrEmpty(marketSlice.Low) ? 0 : decimal.Parse(marketSlice.Low, NumberStyles.Any, CultureInfo.InvariantCulture) }); }
private void UpdateCandlesInfo(string assetPairId, IList <Candle> candles, List <MarketSlice> marketData) { var firstCandle = candles.First(); var lastCandle = candles.Last(); var marketSlice = new MarketSlice { AssetPairId = assetPairId, VolumeBase = candles.Sum(c => c.TradingVolume).ToString(CultureInfo.InvariantCulture), VolumeQuote = candles.Sum(c => c.TradingOppositeVolume).ToString(CultureInfo.InvariantCulture), PriceChange = firstCandle.Open > 0 ? ((lastCandle.Close - firstCandle.Open) / firstCandle.Open).ToString(CultureInfo.InvariantCulture) : "0", High = candles.Max(c => c.High).ToString(CultureInfo.InvariantCulture), Low = candles.Min(c => c.Low).ToString(CultureInfo.InvariantCulture), }; var existingRecord = marketData.FirstOrDefault(x => x.AssetPairId == assetPairId); if (existingRecord != null) { existingRecord.VolumeBase = marketSlice.VolumeBase; existingRecord.VolumeQuote = marketSlice.VolumeQuote; existingRecord.PriceChange = marketSlice.PriceChange; existingRecord.High = marketSlice.High; existingRecord.Low = marketSlice.Low; } else { marketData.Add(marketSlice); } }
public static HashEntry[] ToMarketSliceHash(this MarketSlice marketSlice) { return(new[] { new HashEntry(nameof(marketSlice.AssetPairId), marketSlice.AssetPairId), new HashEntry(nameof(marketSlice.LastPrice), marketSlice.LastPrice), new HashEntry(nameof(marketSlice.Bid), marketSlice.Bid), new HashEntry(nameof(marketSlice.Ask), marketSlice.Ask) }); }
internal static Price ToPrice(this MarketSlice marketSlice) { return(new Price { PartitionKey = Price.GetPk(), RowKey = marketSlice.AssetPairId, UpdatedDt = DateTime.UtcNow, AssetPairId = marketSlice.AssetPairId, Bid = string.IsNullOrEmpty(marketSlice.Bid) ? 0 : decimal.Parse(marketSlice.Bid, NumberStyles.Any, CultureInfo.InvariantCulture), Ask = string.IsNullOrEmpty(marketSlice.Ask) ? 0 : decimal.Parse(marketSlice.Ask, NumberStyles.Any, CultureInfo.InvariantCulture) }); }