public void UpdateAllAssetsValues() { var assets = ListAssets(); foreach (var asset in assets) { AssetValueBusiness.UpdateAssetValue(asset); } }
public TickerDataModel GetRealCurrentValue(int assetId) { TickerDataModel currentValue = null; var pairs = PairBusiness.ListPairs(new int[] { assetId }); if (pairs.Any()) { var usdQuote = pairs.FirstOrDefault(c => c.QuoteAssetId == AssetUSDId); if (usdQuote != null) { var ticker = BinanceBusiness.GetTicker24h(usdQuote.Symbol); if (ticker != null) { currentValue = new TickerDataModel() { AskValue = ticker.AskPrice, BidValue = ticker.BidPrice, CurrentValue = ticker.LastPrice, Variation24Hours = ticker.PriceChangePercent / 100 }; } } else { var btcQuote = pairs.FirstOrDefault(c => c.QuoteAssetId == AssetBTCId); if (btcQuote != null) { var btcPair = PairBusiness.ListPairs(new int[] { AssetBTCId }, new int[] { AssetUSDId }).FirstOrDefault(); if (btcPair != null) { var btcValue = BinanceBusiness.GetTicker24h(btcQuote.Symbol); var btcPrice = BinanceBusiness.GetTicker24h(btcPair.Symbol); if (btcPrice != null && btcValue != null) { currentValue = new TickerDataModel() { AskValue = btcValue.AskPrice * btcPrice.AskPrice, BidValue = btcValue.BidPrice * btcPrice.BidPrice, CurrentValue = btcValue.LastPrice * btcPrice.LastPrice, Variation24Hours = AssetValueBusiness.GetVariation24h(btcValue.LastPrice, btcValue.PriceChangePercent / 100, btcPrice.LastPrice, btcPrice.PriceChangePercent / 100) }; } } } } } if (currentValue == null) { var assetCurrentValue = ListAllAssets(true, new int[] { assetId }).FirstOrDefault(); if (assetCurrentValue != null && assetCurrentValue.UpdateDate > Data.GetDateTimeNow().AddMinutes(-2)) { currentValue = new TickerDataModel() { AskValue = assetCurrentValue.AskValue, BidValue = assetCurrentValue.BidValue, CurrentValue = assetCurrentValue.CurrentValue, Variation24Hours = assetCurrentValue.Variation24Hours } } ; } return(currentValue); } }