public List <ArbitrageOpportunity> GetArbitrageOpportunities()
        {
            List <ArbitrageOpportunity> opportunities = new List <ArbitrageOpportunity>();
            int currencyCount = prices.GetLength(0);

            // Start the data fetch running in parallel
            for (int baseCurrencyIdx = 0; baseCurrencyIdx < currencyCount; baseCurrencyIdx++)
            {
                for (int quoteCurrencyIdx = 0; quoteCurrencyIdx < currencyCount; quoteCurrencyIdx++)
                {
                    if (baseCurrencyIdx == quoteCurrencyIdx)
                    {
                        continue;
                    }

                    MarketPrice highestBid = null;
                    MarketPrice lowestAsk  = null;

                    foreach (MarketPrice marketPrice in this.prices[baseCurrencyIdx, quoteCurrencyIdx])
                    {
                        if (marketPrice.Bid != null)
                        {
                            if (highestBid == null ||
                                marketPrice.Bid > highestBid.Bid)
                            {
                                highestBid = marketPrice;
                            }
                        }
                        if (marketPrice.Ask != null)
                        {
                            if (lowestAsk == null ||
                                marketPrice.Ask < lowestAsk.Ask)
                            {
                                lowestAsk = marketPrice;
                            }
                        }
                    }

                    if (null != highestBid &&
                        null != lowestAsk)
                    {
                        if (highestBid.Bid > lowestAsk.Ask &&
                            !highestBid.Equals(lowestAsk))
                        {
                            opportunities.Add(new ArbitrageOpportunity(lowestAsk, highestBid));
                        }
                    }
                }
            }

            return(opportunities);
        }
Пример #2
0
        public override bool Equals(object obj)
        {
            if (!obj.GetType().Equals(this.GetType()))
            {
                return(false);
            }

            MarketPrice other = (MarketPrice)obj;

            return(this.ExchangeLabel.Equals(other.ExchangeLabel) &&
                   this.Ask == other.Ask &&
                   this.Bid == other.Bid);
        }
 public ArbitrageOpportunity(MarketPrice lowestAsk, MarketPrice highestBid)
 {
     this.lowestAsk = lowestAsk;
     this.highestBid = highestBid;
 }
Пример #4
0
 public ArbitrageOpportunity(MarketPrice lowestAsk, MarketPrice highestBid)
 {
     this.lowestAsk  = lowestAsk;
     this.highestBid = highestBid;
 }