public void OnPrice(IDictionary <string, PriceDto> priceCache, bool wasTraded) { var isLong = _baseTradedAmount >= 0; PriceDto monitoredPrice, crossedPrice; if (!priceCache.TryGetValue(CurrencyPair, out monitoredPrice) || !priceCache.TryGetValue(CrossedPair, out crossedPrice)) { return; } _baseSpot = isLong ? _counterTradedAmount / monitoredPrice.Bid : _counterTradedAmount / monitoredPrice.Ask; var basePnl = _baseTradedAmount - _baseSpot; var usdPnl = isLong ? basePnl * crossedPrice.Bid : basePnl * crossedPrice.Ask; _currentPosition = new CurrencyPairPositionReport { Symbol = CurrencyPair, BaseTradedAmount = _baseTradedAmount, BasePnl = basePnl, UsdPnl = usdPnl, WasTraded = wasTraded }; }
public void OnPrice(IDictionary <string, PriceDto> priceCache, bool wasTraded) { var isLong = _baseTradedAmount >= 0; var isUsdBased = CurrencyPair.StartsWith("USD"); PriceDto monitoredPrice, crossedPrice = null; if (!priceCache.TryGetValue(CurrencyPair, out monitoredPrice) || (!isUsdBased && !priceCache.TryGetValue(CrossedPair, out crossedPrice))) { return; } _baseSpot = isLong ? _counterTradedAmount / monitoredPrice.Bid : _counterTradedAmount / monitoredPrice.Ask; var basePnl = _baseTradedAmount - _baseSpot; decimal usdPnl; if (isUsdBased) { usdPnl = basePnl; } else { usdPnl = isLong ? basePnl * crossedPrice.Bid : basePnl * crossedPrice.Ask; } _currentPosition = new CurrencyPairPositionReport { Symbol = CurrencyPair, BaseTradedAmount = _baseTradedAmount, BasePnl = basePnl, UsdPnl = usdPnl, WasTraded = wasTraded }; }
public void OnPrice(IDictionary<string, SpotPriceDto> priceCache, bool wasTraded) { var isLong = _baseTradedAmount >= 0; var isUsdBased = CurrencyPair.StartsWith("USD"); SpotPriceDto monitoredPrice, crossedPrice = null; if (!priceCache.TryGetValue(CurrencyPair, out monitoredPrice) || (!isUsdBased && !priceCache.TryGetValue(CrossedPair, out crossedPrice))) { return; } _baseSpot = isLong ? _counterTradedAmount/monitoredPrice.Bid : _counterTradedAmount/monitoredPrice.Ask; var basePnl = _baseTradedAmount - _baseSpot; decimal usdPnl; if (isUsdBased) { usdPnl = basePnl; } else { usdPnl = isLong ? basePnl*crossedPrice.Bid : basePnl*crossedPrice.Ask; } CurrentPosition = new CurrencyPairPositionReport { Symbol = CurrencyPair, BaseTradedAmount = _baseTradedAmount, BasePnl = basePnl, UsdPnl = usdPnl, WasTraded = wasTraded }; }