public async Task <(BestExchangeQuote bestBid, BestExchangeQuote bestAsk)> Get(CurrencyPair currencyPair)
        {
            var httpClient = new HttpClient();
            var httpRequestMessageService = new HttpRequestMessageService();
            var currencyPairService       = new CurrencyPairService();

            var bittrexExchange     = new BittrexExchange(httpClient, httpRequestMessageService, currencyPairService);
            var coinbaseProExchange = new CoinbaseProExchange(httpClient, httpRequestMessageService, currencyPairService);
            var krakenExchange      = new KrakenExchange(httpClient, httpRequestMessageService, currencyPairService);
            var poloniexExchange    = new PoloniexExchange(httpClient, httpRequestMessageService, currencyPairService);
            var binanceExchange     = new BinanceExchange(httpClient, httpRequestMessageService, currencyPairService);
            var bitfinexExchange    = new BitfinexExchange(httpClient, httpRequestMessageService, currencyPairService);
            var bitstampExchange    = new BitstampExchange(httpClient, httpRequestMessageService, currencyPairService);

            var exchangeResults = await Task.WhenAll(
                bittrexExchange.Get(currencyPair),
                coinbaseProExchange.Get(currencyPair),
                krakenExchange.Get(currencyPair),
                poloniexExchange.Get(currencyPair),
                binanceExchange.Get(currencyPair),
                bitfinexExchange.Get(currencyPair),
                bitstampExchange.Get(currencyPair));

            var result = arbitrageCalculator.Calculate(
                exchangeResults[0],
                exchangeResults[1],
                exchangeResults[2],
                exchangeResults[3],
                exchangeResults[4],
                exchangeResults[5],
                exchangeResults[6]);

            return(result);
        }
        public void Initialize()
        {
            try
            {
                _exchanges             = new Dictionary <BtcInfo.ExchangeEnum, ExchangeBase>();
                LastExchangeMarketData = new ConcurrentDictionary <BtcInfo.ExchangeEnum, BtcMarketData>();
                _exchangeUpdateQueue   = new ConcurrentQueue <ExchangeBase>();

                var exchanges = Enum.GetValues(typeof(BtcInfo.ExchangeEnum));
                foreach (BtcInfo.ExchangeEnum exchange in exchanges)
                {
                    var exchangeConnection = new BitfinexExchange();
                    exchangeConnection.ConnectToApi();
                    _exchanges.Add(exchange, exchangeConnection);
                    var bw = new BackgroundWorker();
                    bw.DoWork += BwOnDoWork;
                    bw.WorkerSupportsCancellation = true;
                    bw.RunWorkerCompleted        += BwOnRunWorkerCompleted;
                    bw.RunWorkerAsync(exchange);
                }
                ThreadPool.QueueUserWorkItem(ProcessExchangeUpdate);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
Esempio n. 3
0
        private void CaricaApi()
        {
            BinanceExchange binance = GestoreImpostazioni.LeggiDatiExchange <BinanceExchange>(valutaFactory);

            if (binance != null)
            {
                gestoreFondi.AggiungiExchange(binance);
            }
            BitfinexExchange bitfinex = GestoreImpostazioni.LeggiDatiExchange <BitfinexExchange>(valutaFactory);

            if (bitfinex != null)
            {
                gestoreFondi.AggiungiExchange(bitfinex);
            }
            BitcoinBlockexplorer bitcoin = GestoreImpostazioni.LeggiDatiBlockchain <BitcoinBlockexplorer>(valutaFactory);

            if (bitcoin != null)
            {
                gestoreFondi.AggiungiBlockchain(bitcoin);
            }
            EthereumEtherscan ethereum = GestoreImpostazioni.LeggiDatiBlockchain <EthereumEtherscan>(valutaFactory);

            if (ethereum != null)
            {
                gestoreFondi.AggiungiBlockchain(ethereum);
            }
        }
        public void ScaricaFondi_ChiaviOk_Array2Valute()
        {
            BitfinexExchange explorer = new BitfinexExchange(pubKey, privKey, factory);
            List <Fondo>     ris      = explorer.ScaricaFondi().Result;

            Assert.AreEqual(ris.Count, 2);
        }
Esempio n. 5
0
 public GestoreFondiTests()
 {
     convertitore  = new CryptoCompareConvertitore();
     valutaFactory = new ValutaFactory(convertitore);
     gestoreFondi  = new GestoreFondi();
     bitfinex      = new BitfinexExchange("5RMqfG7b2qOBkoPIi97UjCpPxnIhAUsDMelbT5K3pB2",
                                          "hnQNJgD80w1WJeZW7zclyJvFkTWNSN0N4r98t7oRrWw", valutaFactory);
     binance = new BinanceExchange("VhP4edkGMEmL51YSIXSdva0IkcGxC68r8dOIGg6G5PcNMr3srPcm4rXEled5KeMs",
                                   "1ET6MkbrkS2U1sIvQDu6gDzYzNuYgPX2ujG2Lt8tL5SFTygMKUeyDRFDJPT8Ry6Y", valutaFactory);
     btc = new BitcoinBlockexplorer("18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX", valutaFactory);
     eth = new EthereumEtherscan("0x901476A5a3C504398967C745F236124201298016", valutaFactory);
 }
Esempio n. 6
0
        private void TestInizializza()
        {
            BitfinexExchange bitfinex = new BitfinexExchange("5RMqfG7b2qOBkoPIi97UjCpPxnIhAUsDMelbT5K3pB2",
                                                             "hnQNJgD80w1WJeZW7zclyJvFkTWNSN0N4r98t7oRrWw", valutaFactory);

            gestoreFondi.AggiungiExchange(bitfinex);
            BinanceExchange binance = new BinanceExchange("VhP4edkGMEmL51YSIXSdva0IkcGxC68r8dOIGg6G5PcNMr3srPcm4rXEled5KeMs",
                                                          "1ET6MkbrkS2U1sIvQDu6gDzYzNuYgPX2ujG2Lt8tL5SFTygMKUeyDRFDJPT8Ry6Y", valutaFactory);

            gestoreFondi.AggiungiExchange(binance);
            BitcoinBlockexplorer btc = new BitcoinBlockexplorer("18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX", valutaFactory);

            gestoreFondi.AggiungiBlockchain(btc);
            EthereumEtherscan eth = new EthereumEtherscan("0x901476A5a3C504398967C745F236124201298016", valutaFactory);

            gestoreFondi.AggiungiBlockchain(eth);
        }
Esempio n. 7
0
        public async Task <(BestExchangeQuote bestBid, BestExchangeQuote bestAsk)> Get()
        {
            var httpClient = new HttpClient();
            var httpRequestMessageService = new HttpRequestMessageService();

            var bittrexExchange = new BittrexExchange(httpClient, httpRequestMessageService);
            var bittrexResult   = await bittrexExchange.Get();

            var gdaxExchange = new GdaxExchange(httpClient, httpRequestMessageService);
            var gdaxResult   = await gdaxExchange.Get();

            var coinExchangeExchange       = new CoinExchangeExchange(httpClient, httpRequestMessageService);
            var coinExchangeExchangeResult = await coinExchangeExchange.Get();

            var krakenExchange       = new CoinExchangeExchange(httpClient, httpRequestMessageService);
            var krakenExchangeResult = await krakenExchange.Get();

            var poloniexExchange       = new PoloniexExchange(httpClient, httpRequestMessageService);
            var poloniexExchangeResult = await poloniexExchange.Get();

            var binanceExchange       = new BinanceExchange(httpClient, httpRequestMessageService);
            var binanceExchangeResult = await binanceExchange.Get();

            var bitfinexExchange       = new BitfinexExchange(httpClient, httpRequestMessageService);
            var bitfinexExchangeResult = await bitfinexExchange.Get();

            var bitstampExchange       = new BitstampExchange(httpClient, httpRequestMessageService);
            var bitstampExchangeResult = await bitstampExchange.Get();

            var result = arbitrageCalculator.Calculate(
                bittrexResult,
                gdaxResult,
                coinExchangeExchangeResult,
                krakenExchangeResult,
                poloniexExchangeResult,
                binanceExchangeResult,
                bitfinexExchangeResult,
                bitstampExchangeResult);

            return(result);
        }
Esempio n. 8
0
        private void SalvaBitfinexBtn_Click(object sender, RoutedEventArgs e)
        {
            string apiPub  = BitfinexPubblicaTxt.Text;
            string apiPriv = BitfinexPrivataTxt.Text;

            try
            {
                BitfinexExchange bitfinex = new BitfinexExchange(apiPub, apiPriv, valutaFactory);
                if (gestoreFondi.AggiungiExchange(bitfinex))
                {
                    GestoreImpostazioni.SalvaDatiExchange(bitfinex);
                    Dispatcher.BeginInvoke(new Action(async() => { await AggiornaFondi(); }));
                    MessageBox.Show("Chiavi api salvate. Avviato aggiornamento fondi");
                }
                else
                {
                    MessageBox.Show("Ci sono già delle chiavi API associate per bitfinex, rimuoverle prima di aggiungerne delle altre.");
                }
            }
            catch (ArgumentException eccezione)
            {
                MessageBox.Show(eccezione.Message);
            }
        }
 public void ScaricaFondi_ChiaviErrate_Eccezzione()
 {
     BitfinexExchange explorer = new BitfinexExchange("blabla", "blabla", factory);
     List <Fondo>     ris      = explorer.ScaricaFondi().Result;
 }
 public void Costruttore_FactoryNull_Eccezione()
 {
     BitfinexExchange explorer = new BitfinexExchange("", privKey, null);
 }
 public void Costruttore_PubblicaVuota_Eccezione()
 {
     BitfinexExchange explorer = new BitfinexExchange("", privKey, factory);
 }
 public void Costruttore_PrivataVuota_Eccezione()
 {
     BitfinexExchange explorer = new BitfinexExchange(pubKey, "", factory);
 }
 public void Costruttore_SenzaPubblica_Eccezione()
 {
     BitfinexExchange explorer = new BitfinexExchange(null, privKey, factory);
 }
 public void Costruttore_SenzaPrivata_Eccezione()
 {
     BitfinexExchange explorer = new BitfinexExchange(pubKey, null, factory);
 }