示例#1
0
        public void DoArbitrage(Dictionary <ExchangeName, IExchange> exchanges, Action <BittrexArbitrageData> saveArbitrageData)
        {
            foreach (var pair in _pairs)
            {
                double    maxBid, minAsk;
                IExchange ex1, ex2;

                var data = new BittrexArbitrageData
                {
                    Instrument1 = pair.Instrument1.GetInstrument(),
                    Instrument2 = pair.Instrument2.GetInstrument()
                };

                if (!GetBestPrices(exchanges, pair.Instrument1, pair.Instrument2, out maxBid, out minAsk, out ex1, out ex2))
                {
                    continue;
                }

                data.Exchange1 = ex1.GetExchangeName();
                data.Exchange2 = ex2.GetExchangeName();
                data.BuyPrice  = maxBid;
                data.SellPrice = minAsk;

                lock (pair)
                {
                    data.Ratio        = pair.Instrument1.GetInstrument() == CurrencyName.BTC ? minAsk / maxBid : maxBid / minAsk;
                    data.ProfitRatio  = pair.BaseRatio == Double.MaxValue ? 0 : Math.Round(100 - (100 * data.Ratio / pair.BaseRatio), 3);
                    data.BittrexRatio = pair.BaseRatio;
                }
                if (data.Profit > MinProfitRatio)
                {
                    double sellUsd   = maxBid * pair.Instrument1.GetBalanceStep();
                    double buyAmount = sellUsd / minAsk;

                    data.Fees         = ex1.TradingFee * sellUsd + ex2.TradingFee * sellUsd;
                    data.ProfitRatio -= Math.Round(data.Fees, ex1.CountryCurrencyDecimal);

                    saveArbitrageData(data);
                }
            }
        }
 public Task SaveBittrexArbitrageAsync(BittrexArbitrageData data)
 {
     return(Task.Run(() => _dbRepo.SaveBittrexArbitrageAsync(data)));
 }