Пример #1
0
 private void GenerateExchangePairs()
 {
     for (var i = 0; i < _exchanges.Count; i++)
     {
         for (var j = i + 1; j < _exchanges.Count; j++)
         {
             var exchangePair = new ExchangePair(_exchanges[i], _exchanges[j]);
             _exchangePairs.Add(exchangePair);
         }
     }
 }
Пример #2
0
        private async Task ProcessItem(ExchangePair exchangePair, IProducerConsumerCollection <ArbitrageInfo> output)
        {
            foreach (TradePair pair in exchangePair.Pairs)
            {
                (decimal buy, decimal sell)first = await exchangePair.First.GetBookOrderPriceAsync(pair);

                (decimal buy, decimal sell)second = await exchangePair.Second.GetBookOrderPriceAsync(pair);

                if (first.buy == 0 && first.sell == 0 || second.buy == 0 && second.sell == 0)
                {
                    continue;
                }

                //decimal first = await exchangePair.First.GetPriceAsync(pair);
                //decimal second = await exchangePair.Second.GetPriceAsync(pair);

                var model = new ArbitrageInfo();
                model.Symbol = pair.Label;
                //model.BuyPrice = first < second ? first : second;
                //model.SellPrice = first > second ? first : second;

                model.BuyPrice  = first.sell > second.sell ? second.sell : first.sell;
                model.SellPrice = first.buy > second.buy ? first.buy : second.buy;

                if (model.BuyPrice < model.SellPrice)
                {
                    model.Route = $"{exchangePair.Second.Type}->{exchangePair.First.Type}";
                    model.Rate  = GetPercent(model.SellPrice, model.BuyPrice);
                }
                else
                {
                    model.Route = $"{exchangePair.First.Type}->{exchangePair.Second.Type}";
                    model.Rate  = GetPercent(model.BuyPrice, model.SellPrice);
                }

                output.TryAdd(model);
                await Task.Delay(1000);
            }
        }