public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r.success == false || r.data == null) { throw new ApiResponseException(r.msg, this); } var prices = new MarketPrices(); var rPairsDict = r.data.ToDictionary(x => x.symbol.ToAssetPair(this), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.lastDealPrice) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.sell, currentTicker.buy, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.vol) }); } } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r == null || r.Count == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var rPairsDict = r.Values.ToDictionary(x => new AssetPair(x.primary_currency, x.secondary_currency, this), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, 1 / currentTicker.last_price) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.orderbook.asks.highbid, currentTicker.orderbook.bids.highbid), Volume = new NetworkPairVolume(Network, pair, currentTicker.volume_24hours) }); } } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); var prices = new MarketPrices(); //Treats results as dictionary just incase the API add more asset pairs later on. var rPairsDict = r.ToDictionary(x => x.ticker.ToAssetPair(this, 3), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.last_traded_price) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.total_volume_24h) }); } } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r?.Count == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var rPairsDict = r.ToDictionary(x => x.Key.ToAssetPair(this), x => x.Value); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, 1 / currentTicker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.lowestAsk, currentTicker.highestBid, currentTicker.low24hr, currentTicker.high24hr), Volume = new NetworkPairVolume(Network, pair, currentTicker.baseVolume, currentTicker.quoteVolume) }); } } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var pairsCsv = string.Join(",", context.Pairs.Select(x => x.ToTicker(this, ""))); var r = await api.GetTickerInformationAsync(pairsCsv).ConfigureAwait(false); CheckResponseErrors(r); var prices = new MarketPrices(); foreach (var pair in context.Pairs) { var rTicker = r.result.Where(x => ComparePairs(pair, x.Key)).ToArray(); if (!rTicker.Any()) { prices.MissedPairs.Add(pair); continue; } var ticker = rTicker.First().Value; prices.Add(new MarketPrice(Network, pair, ticker.c[0]) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, ticker.a[0], ticker.b[0], ticker.l[1], ticker.h[1]), Volume = new NetworkPairVolume(Network, pair, ticker.v[1]) }); } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickerAsync().ConfigureAwait(false); var rPaired = r.ToDictionary(x => x.Key.ToAssetPair(this), y => y.Value); var pairsQueryable = context.IsRequestAll ? rPaired.Select(x => x.Key) : context.Pairs; var prices = new MarketPrices(); foreach (var pair in pairsQueryable) { var rTickers = rPaired.Where(x => x.Key.Equals(pair)).ToList(); if (rTickers.Count == 0) { prices.MissedPairs.Add(pair); continue; } var rTicker = rTickers[0]; var v = rTicker.Value; prices.Add(new MarketPrice(Network, pair, 1 / v.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, v.lowestAsk, v.highestBid, v.low24hr, v.high24hr), Volume = new NetworkPairVolume(Network, pair, v.baseVolume, v.quoteVolume) }); } return(prices); }
private async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var privateCtx = new NetworkProviderPrivateContext(UserContext.Testing); var api = ApiProvider.GetApi(privateCtx); var pairsCsv = string.Join(",", context.Pairs.Select(x => x.ToTicker(this))); var r = await api.GetPrices(pairsCsv).ConfigureAwait(false); var prices = new MarketPrices(); foreach (var pair in context.Pairs) { if (!r.TryGetValue(pair.ToTicker(this), out var price)) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, (price.ask + price.bid) / 2) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, price.ask, price.bid) }); } return(prices); }
private async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetMarketInfos().ConfigureAwait(false); var pairsDict = r.ToDictionary(x => x.pair.ToAssetPair(this), x => x); var pairsQueryable = context.IsRequestAll ? pairsDict.Keys.ToArray() : context.Pairs; var prices = new MarketPrices(); foreach (var pair in pairsQueryable) { if (!pairsDict.TryGetValue(pair, out var price)) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, price.rate)); } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r == null || r.Count == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var pairsQueryable = context.IsRequestAll ? r.Keys.Select(x => x.ToAssetPair(this, 3)).ToList() : context.Pairs; foreach (var pair in pairsQueryable) { r.TryGetValue(pair.ToTicker(this).ToLower(), out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.volume) }); } } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetLastPricesAsync().ConfigureAwait(false); CheckResponseError(r); var dictPairsPrices = r.data.ToDictionary(x => new AssetPair(x.symbol1, x.symbol2, this), x => x); var pairsQueryable = context.IsRequestAll ? dictPairsPrices.Keys.ToList() : context.Pairs; var prices = new MarketPrices(); foreach (var pair in pairsQueryable) { if (!dictPairsPrices.TryGetValue(pair, out var rPair)) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, rPair.lprice)); } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var products = await GetAllProductsAsync().ConfigureAwait(false); var prices = new MarketPrices(); var rPairsDict = products.ToDictionary(x => x.currency_pair_code.ToAssetPair(this, 3), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, (decimal?)currentTicker.last_traded_price ?? 0) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, (decimal)currentTicker.high_market_ask, (decimal)currentTicker.low_market_bid), Volume = new NetworkPairVolume(Network, pair, currentTicker.volume_24h) }); } } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r?.instruments == null || r.instruments.Length == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var rPairsDict = r.instruments.ToDictionary(x => x.symbol.ToAssetPair(this, 3), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.last == 0 ? (currentTicker.ask + currentTicker.bid) / 2 : currentTicker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.volume) }); } } return(prices); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetTickersAsync().ConfigureAwait(false); CheckResponseErrors(rRaw); var r = ParseTicker(rRaw); var prices = new MarketPrices(); var krwAsset = Asset.Krw; foreach (var pair in context.Pairs) { var ticker = new CoinoneSchema.TickerEntryResponse(); if (!r.TryGetValue(pair.Asset1.ShortCode.ToLower(), out ticker) || !pair.Asset2.Equals(krwAsset)) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, ticker.last)); } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r == null || r.responseStatus?.message?.Equals("OK", StringComparison.InvariantCultureIgnoreCase) == false || r.tickers == null || r.tickers.Length == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var rPairsDict = r.tickers.ToDictionary(x => x.currencyPair.ToAssetPair(this, 3), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.ask, currentTicker.bid, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.volume) }); } } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProviderPublic.GetApi(context); var pairsCsv = string.Join("-", context.Pairs.Select(x => x.ToTicker(this).ToLower())); var r = await api.GetTickerAsync(pairsCsv).ConfigureAwait(false); if (r == null || r.Count == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); foreach (var pair in context.Pairs) { var currentTicker = r.FirstOrDefault(x => x.Key.ToAssetPair(this).Equals(pair)).Value; if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.sell, currentTicker.buy, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.vol) }); } } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetLatestPricesAsync().ConfigureAwait(false); var pairsDict = r.ToDictionary(x => new AssetPair(x.underlying, x.quoteCurrency, this), x => x); var pairsQueryable = context.IsRequestAll ? pairsDict.Keys.ToList() : context.Pairs; var prices = new MarketPrices(); foreach (var pair in pairsQueryable) { if (!pairsDict.TryGetValue(pair, out var data) || data.lastPrice.HasValue == false) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, data.lastPrice.Value) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, data.askPrice, data.bidPrice, data.lowPrice, data.highPrice), Volume = new NetworkPairVolume(Network, pair, data.volume24h) }); } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetMarketSummariesAsync().ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var rPairsDict = r.result.ToDictionary(x => x.MarketName.ToAssetPair(this), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; var prices = new MarketPrices(); foreach (var pair in pairsQueryable) { if (!rPairsDict.TryGetValue(pair, out var e)) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair.Reversed, e.Last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, e.Ask, e.Bid, e.Low, e.High), Volume = new NetworkPairVolume(Network, pair, e.BaseVolume, e.Volume) }.Reversed); } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var r = await ApiProvider.GetApi(context).GetTickersAsync().ConfigureAwait(false); if (r == null || r.Length == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var rPairsDict = r.ToDictionary(x => x.Symbol.ToAssetPair(this, 3), x => x); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { prices.Add(new MarketPrice(Network, pair, currentTicker.LastBuyPrice) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, r[0].BestAsk, r[0].BestBid), Volume = new NetworkPairVolume(Network, pair, r[0].DailyTradedTotalVolume) }); } } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetTickersAsync().ConfigureAwait(false); if (r == null || r.Count == 0) { throw new ApiResponseException("No tickers returned", this); } var prices = new MarketPrices(); var knownPairs = new AssetPairs(); if (context.IsRequestAll) { foreach (var rPrice in r.OrderBy(x => x.Key.Length)) { var tPair = AssetsUtilities.GetAssetPair(rPrice.Key, knownPairs); if (!tPair.HasValue) { continue; } var pair = new AssetPair(tPair.Value.AssetCode1, tPair.Value.AssetCode2, this); knownPairs.Add(pair); prices.Add(new MarketPrice(Network, pair, rPrice.Value.ticker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, rPrice.Value.ticker.sell, rPrice.Value.ticker.buy, rPrice.Value.ticker.low, rPrice.Value.ticker.high), Volume = new NetworkPairVolume(Network, pair, rPrice.Value.ticker.vol) }); } } else { foreach (var pair in context.Pairs) { var lowerPairTicker = pair.ToTicker(this, "").ToLower(); var lpr = r.FirstOrDefault(x => x.Key.ToLower().Equals(lowerPairTicker)); if (lpr.Value == null) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, lpr.Value.ticker.last) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, lpr.Value.ticker.sell, lpr.Value.ticker.buy, lpr.Value.ticker.low, lpr.Value.ticker.high), Volume = new NetworkPairVolume(Network, pair, lpr.Value.ticker.vol) }); } } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetAllTickersAsync().ConfigureAwait(false); var r = rRaw.GetContent(); var prices = new MarketPrices(); if (context.IsRequestAll) { var knownPairs = new AssetPairs(); foreach (var ticker in r.OrderBy(x => x.symbol.Length)) { var pairCodes = AssetsUtilities.GetAssetPair(ticker.symbol, knownPairs); if (!pairCodes.HasValue || !ticker.last.HasValue) { continue; } var pair = new AssetPair(pairCodes.Value.AssetCode1, pairCodes.Value.AssetCode2, this); knownPairs.Add(pair); prices.Add(new MarketPrice(Network, pair, ticker.last.Value) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, ticker.ask, ticker.bid, ticker.low, ticker.high), Volume = new NetworkPairVolume(Network, pair, ticker.volume, ticker.volumeQuote) }); } } else { foreach (var pair in context.Pairs) { var pairCode = pair.ToTicker(this); var ticker = r.FirstOrDefault(x => x.symbol.Equals(pairCode, StringComparison.OrdinalIgnoreCase)); if (ticker?.last == null) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, ticker.last.Value) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, ticker.ask, ticker.bid, ticker.low, ticker.high), Volume = new NetworkPairVolume(Network, pair, ticker.volume, ticker.volumeQuote) }); } } return(prices); }
private void AssertPrice(MarketPrices price, bool canVolumeBase, bool canVolumeQuote) { Assert.IsFalse( price.FirstPrice.Volume.HasVolume24Base && canVolumeBase, "Provider returns base volume using both pricing and volume interfaces"); Assert.IsFalse( price.FirstPrice.Volume.HasVolume24Quote && canVolumeQuote, "Provider returns quote volume using both pricing and volume interfaces"); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var rRaw = await api.GetSymbolPriceTickerAsync().ConfigureAwait(false); CheckResponseErrors(rRaw); var r = rRaw.GetContent(); var prices = new MarketPrices(); var knownPairs = new AssetPairs(); if (context.IsRequestAll) { foreach (var rPrice in r.OrderBy(x => x.symbol.Length)) { var tPair = AssetsUtilities.GetAssetPair(rPrice.symbol, knownPairs); if (!tPair.HasValue) { continue; } var pair = new AssetPair(tPair.Value.AssetCode1, tPair.Value.AssetCode2, this); knownPairs.Add(pair); prices.Add(new MarketPrice(Network, pair, rPrice.price)); } } else { foreach (var pair in context.Pairs) { var lowerPairTicker = pair.ToTicker(this).ToLower(); var lpr = r.FirstOrDefault(x => x.symbol.ToLower().Equals(lowerPairTicker)); if (lpr == null) { prices.MissedPairs.Add(pair); continue; } prices.Add(new MarketPrice(Network, pair, lpr.price)); } } return(prices); }
public async Task <MarketPrices> GetPriceAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var ticker = context.Pair.ToTicker(this); var r = await api.Get24HrTickerAsync(ticker).ConfigureAwait(false); var marketPrice = new MarketPrices(new MarketPrice(Network, context.Pair, r.lastPrice) { PriceStatistics = new PriceStatistics(Network, context.Pair.Asset2, r.askPrice, r.bidPrice, r.lowPrice, r.highPrice), Volume = new NetworkPairVolume(Network, context.Pair, r.volume) }); return(marketPrice); }
public void MarketPrices() { var date = DateTime.Now.Date; var businessDate = date.BusinessDate(); var prevEodDate = businessDate.PrevBusinessDate(); var eodPrices = new MarketPrices().Get(businessDate); var prevEodPrices = new MarketPrices().Get(prevEodDate); Assert.IsTrue(prevEodDate < businessDate, $"{prevEodDate} should be less than {businessDate}"); Assert.IsTrue(eodPrices.Count > 0, $"expected data for {businessDate}"); Assert.IsTrue(prevEodPrices.Count > 0, $"expected data for {prevEodDate}"); }
/// <summary> /// Calcualte the Unrealized Pnl for this Tax lot /// </summary> /// <param name="env"></param> /// <returns></returns> public static double CalculateUnrealizedPnl(PostingEngineEnvironment env, TaxLotStatus taxLotStatus, double residualQuantity = 0, double endPrice = 0) { double multiplier = 1.0; if (env.SecurityDetails.ContainsKey(taxLotStatus.Trade.BloombergCode)) { multiplier = env.SecurityDetails[taxLotStatus.Trade.BloombergCode].Multiplier; } double fxrate = 1.0; // Lets get fx rate if needed if (!taxLotStatus.Trade.SettleCurrency.Equals(env.BaseCurrency)) { fxrate = Convert.ToDouble(FxRates.Find(env.ValueDate, taxLotStatus.Trade.SettleCurrency).Rate); } var eodPrice = 0.0; var prevEodPrice = 0.0; if (env.ValueDate == taxLotStatus.Trade.TradeDate) { prevEodPrice = taxLotStatus.Trade.SettleNetPrice; var eodMarketPrice = MarketPrices.GetPrice(env, env.ValueDate, taxLotStatus.Trade); if (!eodMarketPrice.Valid) { env.AddMessage(eodMarketPrice.Error); } eodPrice = eodMarketPrice.Price; } else { prevEodPrice = MarketPrices.GetPrice(env, env.PreviousValueDate, taxLotStatus.Trade).Price; eodPrice = MarketPrices.GetPrice(env, env.ValueDate, taxLotStatus.Trade).Price; } eodPrice = endPrice != 0 ? endPrice : eodPrice; // Use residual Quantity if specified var quantity = residualQuantity != 0.0 ? residualQuantity : taxLotStatus.Quantity; var priceDiff = (eodPrice - prevEodPrice); var unrealizedPnl = priceDiff * quantity; return(unrealizedPnl * fxrate * multiplier); }
// Get Market Prices for today public void GetMarketPrices() { DateTime today = DateTime.Today; FirebaseCommunicator.instance.GetObject(new string[] { marketReferenceName, today.ToString(dateFormat) }, (task) => { if (task.IsFaulted) { Debug.LogError("Failed to get market prices: " + task.Exception.Message); } else if (task.IsCompleted) { Debug.Log("yey got oracle data"); string json = task.Result.GetRawJsonValue(); marketPrices = new MarketPrices(JsonConvert.DeserializeObject <Dictionary <string, int>[]>(json)); } }); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var rates = await GetRatesAsync().ConfigureAwait(false); var lp = new MarketPrices(); foreach (var pair in context.Pairs) { var rate = rates.FirstOrDefault(x => Equals(x.Key, pair)); if (rate.Key == null) { continue; } lp.Add(new MarketPrice(Network, rate.Key, rate.Value)); } return(lp); }
public async Task <MarketPrices> GetPricingAsync(PublicPricesContext context) { var api = GetApi <ICryptoCompareApi>(); var froms = string.Join(",", context.Pairs.Select(x => x.Asset1).Distinct().Select(x => x.ShortCode)); var tos = string.Join(",", context.Pairs.Select(x => x.Asset2).Distinct().Select(x => x.ShortCode)); var str = await api.GetPricesAsync(froms, tos, Name, "prime", "false", "false").ConfigureAwait(false); if (str.Contains("market does not exist for this coin pair")) { throw new AssetPairNotSupportedException(context.Pair, this); } var apir = JsonConvert.DeserializeObject <CryptoCompareSchema.PriceMultiResult>(str); var prices = new MarketPrices(); foreach (var i in context.Pairs) { var a1 = i.Asset1.ShortCode.ToLower(); var k = apir.FirstOrDefault(x => x.Key.ToLower() == a1); if (k.Key == null) { prices.MissedPairs.Add(i); continue; } var a2 = i.Asset2.ShortCode.ToLower(); var r = k.Value.FirstOrDefault(x => x.Key.ToLower() == a2); if (r.Key == null) { prices.MissedPairs.Add(i); continue; } prices.Add(new MarketPrice(Network, i, (decimal)r.Value)); } return(prices); }
public async Task <MarketPrices> GetPricesAsync(PublicPricesContext context) { var api = ApiProvider.GetApi(context); var r = await api.GetAllTickers().ConfigureAwait(false); var prices = new MarketPrices(); var rPairsDict = r.ToDictionary(x => x.Key.ToAssetPair(this), x => x.Value); var pairsQueryable = context.IsRequestAll ? rPairsDict.Keys.ToList() : context.Pairs; foreach (var pair in pairsQueryable) { rPairsDict.TryGetValue(pair, out var currentTicker); if (currentTicker == null) { prices.MissedPairs.Add(pair); } else { if (currentTicker.last != null) { prices.Add(new MarketPrice(Network, pair, currentTicker.last.Value) { PriceStatistics = new PriceStatistics(Network, pair.Asset2, currentTicker.sell, currentTicker.buy, currentTicker.low, currentTicker.high), Volume = new NetworkPairVolume(Network, pair, currentTicker.volume_left, currentTicker.volume_right) }); } else { prices.MissedPairs.Add(pair); } } } return(prices); }
/// <summary> /// Relieves the passed TaxLostStatus, this should only be used for FORWARDS etc that expire /// </summary> /// <param name="env">Environment</param> /// <param name="lot">The Tax Lot to relieve</param> /// <param name="trade">The current trade</param> /// <param name="quantity">Quantity to relieve</param> /// <param name="fxrate">Appropriate fxrate</param> internal static TaxLot RelieveTaxLot(PostingEngineEnvironment env, Transaction taxLotToRelieve, Transaction trade, double quantity, bool reverse = false) { var SettleNetPrice = trade.SettleNetPrice; if (taxLotToRelieve.LpOrderId.Equals(trade.LpOrderId)) { // Same, so we are dealing with the same trade, so we are backing out the same trade SettleNetPrice = MarketPrices.GetPrice(env, trade.SettleDate, trade).Price; } var prevFxRate = FxRates.Find(taxLotToRelieve.TradeDate, taxLotToRelieve.SettleCurrency).Rate; var investmentAtCost = quantity * taxLotToRelieve.SettleNetPrice * prevFxRate; if (reverse) { investmentAtCost = investmentAtCost * -1; } var tl = new TaxLot { Trade = trade, TradeDate = trade.TradeDate, InvestmentAtCost = investmentAtCost, // Needs to be the Investment Cost that we are relieving from the Tax BusinessDate = env.ValueDate, OpeningLotId = taxLotToRelieve.LpOrderId, ClosingLotId = trade.LpOrderId, TradePrice = taxLotToRelieve.SettleNetPrice, CostBasis = SettleNetPrice, Quantity = quantity }; CalculateRealizedPnl(env, tl); tl.Save(env.Connection, env.Transaction); return(tl); }