public void UpdatePrice(ExchangeTradePair exchangeTradePair, decimal price, DateTime utcPriceUpdateTime) { // We want to do the following: // If the price is older than priceInvalidationDelaySeconds, then just remove it. // If you find the exchange, delete it. // Calculate the min and max again. var exchangesToRemove = priceDic.Values.Where(x => x.UtcLastUpdateTime.AddSeconds(priceInvalidationDelaySeconds) > DateTime.Now).Select(x => x.ExchangeTradePair.Exchange); TradePairPrice priceRemoved = null; foreach (var exchangeToRemove in exchangesToRemove) { priceDic.TryRemove(exchangeToRemove, out priceRemoved); } // Get latest price or add it. var latestPrice = priceDic.AddOrUpdate( exchangeTradePair.Exchange, new TradePairPrice() { ExchangeTradePair = exchangeTradePair, Price = price, UtcLastUpdateTime = utcPriceUpdateTime }, (e, oldVal) => { oldVal.ExchangeTradePair = exchangeTradePair; oldVal.Price = price; oldVal.UtcLastUpdateTime = utcPriceUpdateTime; return(oldVal); } ); // Now that the maximum and minimum have been calculated, we want to pass the ball to the Arb this.MaximumValuedPair = this.priceDic.Max(x => x.Value); this.MinimumValuedPair = this.priceDic.Min(x => x.Value); }
internal ArbOpportunity(TradePairPrice lowerPricePair, TradePairPrice higherPricePair, Currency currency) { this.LowerPricePair = lowerPricePair; this.HigherPricePair = higherPricePair; this.OpportunityBaseCurrency = currency; // The actions to be taken this.Actions = new ITradeAction[][] { new ITradeAction [] { }, new ITradeAction [] { //new ExchangeOrderAction() } }; }
private static decimal CalculateOpportunityMargin(TradePairPrice lowerPricePair, TradePairPrice higherPricePair) { // The opportunity is calculated by comparing the higher price with the lower price. decimal marginPercent = ((higherPricePair.Price / lowerPricePair.Price) - 1m) * 100m; // Then we remove the fees on both sides. marginPercent -= (higherPricePair.ExchangeTradePair.FeePercent + lowerPricePair.ExchangeTradePair.FeePercent); #warning Still need to calculated the amount for transfering and balancing accounts!! // If the margin percent is higher than the minimum opportunity threshold, then report it. if (marginPercent >= MinimumOpportunityTreshold) { return(marginPercent); } // Else just filter to zero return(0m); }
/// <summary> /// Gets the key describing an arb opportunity. /// </summary> internal static string GetOpportunityKey(TradePairPrice lowerPricePair, TradePairPrice higherPricePair) { return(lowerPricePair.ExchangeTradePair.TradePair.ToString() + " - " + lowerPricePair.ExchangeTradePair.Exchange.ToString() + " -> " + higherPricePair.ExchangeTradePair.Exchange.ToString()); }