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
};
}
}