Exemple #1
0
        public bool LoadExchange(ExchangeApi exchangeApi)
        {
            var loadedHub = _exchangeHubs.Where(e => e.GetExchange().Equals(exchangeApi.Exchange.ToString()) && e.GetApiKey().Equals(exchangeApi.ApiKey)).FirstOrDefault();

            if (loadedHub == null)
            {
                if (exchangeApi.Exchange == Exchange.CoinbasePro)
                {
                    loadedHub = new ExchangeHubRepository((ExchangeHub.Contracts.Exchange)exchangeApi.Exchange, exchangeApi.ApiKey, exchangeApi.ApiSecret, exchangeApi.ApiExtra);
                }
                else if (exchangeApi.Exchange == Exchange.Switcheo)
                {
                    loadedHub = new ExchangeHubRepository((ExchangeHub.Contracts.Exchange)exchangeApi.Exchange, exchangeApi.WIF);
                }
                else
                {
                    loadedHub = new ExchangeHubRepository((ExchangeHub.Contracts.Exchange)exchangeApi.Exchange, exchangeApi.ApiKey, exchangeApi.ApiSecret);
                }
                _exchangeHubs.Add(loadedHub);
            }
            _currentExchange = loadedHub.GetExchange();
            _currentHub      = loadedHub;

            return(true);
            //var e = OnBuildExchangeCoins(loadedHub);
            //var o = OnBuildOrders(loadedHub);
        }
Exemple #2
0
        public async Task LoadBuilder(bool test = false)
        {
            _exchangeApis = await _xchApiBldr.Get();

            _exchangeHubs = new List <IExchangeHubRepository>();

            if (!test)
            {
                foreach (var api in _exchangeApis)
                {
                    if (api.Exchange == Exchange.Binance)
                    {
                        _exchangeHubs.Add(new ExchangeHubRepository(ExchangeHub.Contracts.Exchange.Binance, api.ApiKey, api.ApiSecret));
                    }
                    else if (api.Exchange == Exchange.Bittrex)
                    {
                        _exchangeHubs.Add(new ExchangeHubRepository(ExchangeHub.Contracts.Exchange.Bittrex, api.ApiKey, api.ApiSecret));
                    }
                    else if (api.Exchange == Exchange.CoinbasePro)
                    {
                        _exchangeHubs.Add(new ExchangeHubRepository(ExchangeHub.Contracts.Exchange.CoinbasePro, api.ApiKey, api.ApiSecret, api.ApiExtra));
                    }
                    else if (api.Exchange == Exchange.KuCoin)
                    {
                        _exchangeHubs.Add(new ExchangeHubRepository(ExchangeHub.Contracts.Exchange.KuCoin, api.ApiKey, api.ApiSecret));
                    }
                }
                if (_currentHub == null)
                {
                    _currentHub      = _exchangeHubs[0];
                    _currentExchange = _currentHub.GetExchange();
                }
            }
        }
        private async Task OnBuildOrders(IExchangeHubRepository hub)
        {
            currentHub = hub;

            var markets = await currentHub.GetMarkets();

            currentHubMarkets = markets.ToList();
        }
        /// <summary>
        /// Build Coins
        /// </summary>
        /// <param name="hub">ExchangeHub for current exchange</param>
        /// <returns>Collection of ExchangeCoins</returns>
        private async Task <IEnumerable <ExchangeCoin> > OnBuildExchangeCoins(IExchangeHubRepository hub)
        {
            currentHub = hub;
            var markets = await currentHub.GetMarkets();

            currentHubMarkets = markets.ToList();

            return(await GetExchangeCoins());
        }
Exemple #5
0
        public bool SetExchange(Exchange exchange)
        {
            var xchg = exchange.ToString();

            this._currentHub      = _exchangeHubs.Where(e => e.GetExchange().Equals(xchg)).FirstOrDefault();
            this._currentExchange = xchg;

            return(true);
        }
Exemple #6
0
        /// <summary>
        /// Get Prices for trading pairs
        /// </summary>
        /// <param name="hub">Current exchange hub</param>
        /// <param name="pairs">Unique array of trading pairs</param>
        /// <returns>Dictionary of trading pair and current price</returns>
        private Dictionary <string, decimal> GetPricePairs(IExchangeHubRepository hub, string[] pairs)
        {
            var tickers        = hub.GetLatestPrices().Result;
            var arbitragePairs = new Dictionary <string, decimal>();

            for (var i = 0; i < pairs.Length; i++)
            {
                var price = tickers.Where(t => t.Pair.Equals(pairs[i])).Select(t => t.Price).FirstOrDefault();
                arbitragePairs.Add(pairs[i], price);
            }

            return(arbitragePairs);
        }
 /// <summary>
 /// Constructor for unit tests
 /// </summary>
 /// <param name="exchangeApiBldr">Exchange Api Builder</param>
 /// <param name="exchangeUpdateRepo">Exchange Update repository</param>
 /// <param name="arbitragePathRepo">Arbitrage Path repository</param>
 /// <param name="arbitrageBuilder">Arbitrage builder</param>
 /// <param name="exchangeHubRepo">Exchange Hub repository</param>
 /// <param name="cmcBuilder">CMC builder</param>
 public ExchangeBuilder(IExchangeApiBuilder exchangeApiBldr,
                        IExchangeUpdateRepository exchangeUpdateRepo,
                        IArbitragePathRepository arbitragePathRepo,
                        IArbitrageBuilder arbitrageBuilder,
                        IExchangeHubRepository exchangeHubRepo,
                        ICMCBuilder cmcBuilder)
 {
     _exchangeApiBldr    = exchangeApiBldr;
     _exchangeUpdateRepo = exchangeUpdateRepo;
     _arbitragePathRepo  = arbitragePathRepo;
     _arbitrageBldr      = arbitrageBuilder;
     currentHub          = exchangeHubRepo;
     _cmcBldr            = cmcBuilder;
     currentExchange     = "Binance";
     LoadBuilder(true).RunSynchronously();
 }
Exemple #8
0
        /// <summary>
        /// Get internal arbitrage values for a currency
        /// </summary>
        /// <param name="symbol">Symbol of a currency</param>
        /// <param name="quantity">Starting quantity</param>
        /// <param name="hub">Current exchange hub</param>
        /// <returns>Collection of ArbitrageLoop objects</returns>
        public IEnumerable <ArbitrageLoop> GetInternalArbitrage(string symbol,
                                                                decimal quantity,
                                                                IExchangeHubRepository hub)
        {
            var paths     = GetPaths(symbol, quantity);
            var pathPairs = GetUniquePairs(paths);

            var arbitragePairs = GetPricePairs(hub, pathPairs);

            for (var i = 0; i < paths.Count(); i++)
            {
                paths[i].FinalQuantity = ArbitrageCalculator(arbitragePairs, paths[i].Path, paths[i].StartingQuantity);
            }

            return(paths);
        }
        public void LoadExchange(ExchangeApi exchangeApi)
        {
            IExchangeHubRepository loadedHub = null;

            if (exchangeApi.Exchange == Exchange.CoinbasePro)
            {
                loadedHub = new ExchangeHubRepository((ExchangeHub.Contracts.Exchange)exchangeApi.Exchange, exchangeApi.ApiKey, exchangeApi.ApiSecret, exchangeApi.ApiExtra);
            }
            else if (exchangeApi.Exchange == Exchange.Switcheo)
            {
                loadedHub = new ExchangeHubRepository((ExchangeHub.Contracts.Exchange)exchangeApi.Exchange, exchangeApi.WIF);
            }
            else
            {
                loadedHub = new ExchangeHubRepository((ExchangeHub.Contracts.Exchange)exchangeApi.Exchange, exchangeApi.ApiKey, exchangeApi.ApiSecret);
            }
            currentHub = loadedHub;
            exchangeHubs.Add(loadedHub);

            var e = OnBuildExchangeCoins(loadedHub);
            var o = OnBuildOrders(loadedHub);
        }
 public IEnumerable <ArbitrageLoop> GetInternalArbitrages(string symbol, decimal quantity, Exchange exchange)
 {
     currentHub      = exchangeHubs.Where(e => e.GetExchange().Equals(exchange.ToString())).FirstOrDefault();
     currentExchange = exchange.ToString();
     return(_arbitrageBldr.GetInternalArbitrage(symbol, quantity, currentHub));
 }