Beispiel #1
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 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 ScaricaFondi_ChiaviOk_Array30Valute()
        {
            BinanceExchange explorer = new BinanceExchange(pubKey, privKey, factory);
            List <Fondo>    ris      = explorer.ScaricaFondi().Result;

            Assert.AreEqual(ris.Count, 30);
        }
Beispiel #4
0
        public async Task <ISpotExchangeFacade> CreateExchanges(ExchangeDTO exx)
        {
            ISpotExchangeFacade fac = null;

            if (exx.Name == ExchangeName.Binance.ToString() && this.exchanges.FirstOrDefault(x => x.ExchangeName == ExchangeName.Binance) != null)
            {
                UserExchangeSecretDTO secrets = await this.repoExchangeSecrets.GetByExchangeId(exx.ID);

                fac = new BinanceExchange(exx, secrets, logger);
            }
            else if (exx.Name == ExchangeName.HitBTC.ToString() && this.exchanges.FirstOrDefault(x => x.ExchangeName == ExchangeName.Binance) != null)
            {
                UserExchangeSecretDTO secrets = await this.repoExchangeSecrets.GetByExchangeId(exx.ID);

                fac = new HitBTCExchange(exx, secrets, logger);
            }
            else if (exx.Name == ExchangeName.KuCoin.ToString() && this.exchanges.FirstOrDefault(x => x.ExchangeName == ExchangeName.Binance) != null)
            {
                UserExchangeSecretDTO secrets = await this.repoExchangeSecrets.GetByExchangeId(exx.ID);

                fac = new KuCoinExchange(exx, secrets, logger);
            }

            if (fac != null)
            {
                this.exchanges.Add(fac);
            }
            else
            {
                fac = this.exchanges.FirstOrDefault(x => x.ExchangeName.ToString() == exx.Name);
            }

            return(fac);
        }
 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);
 }
Beispiel #6
0
        public static void SubscribeInstruments(BinanceExchange ex, CurrencyName[] btcInstruments, CurrencyName[] usdInstruments, Action <object, ExchangePricesEventArgs> callback, string usdToken = "usdt")
        {
            var str = new StringBuilder(ex.WsUrl);

            foreach (var ins in btcInstruments)
            {
                str.AppendFormat("{0}btc@depth20/", ins.ToString().ToLower());
            }
            foreach (var ins in usdInstruments)
            {
                str.AppendFormat("{0}{1}@depth20/", ins.ToString().ToLower(), usdToken);
            }
            ex.WsUrl = str.ToString();
            ex.InstrumentReceived += (s, e) => callback(ex, e);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        private void SalvaBinanceBtn_Click(object sender, RoutedEventArgs e)
        {
            string apiPub  = BinancePubblicaTxt.Text;
            string apiPriv = BinancePrivataTxt.Text;

            try
            {
                BinanceExchange binance = new BinanceExchange(apiPub, apiPriv, valutaFactory);
                if (gestoreFondi.AggiungiExchange(binance))
                {
                    GestoreImpostazioni.SalvaDatiExchange(binance);
                    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 binance, rimuoverle prima di aggiungerne delle altre.");
                }
            }
            catch (ArgumentException eccezione)
            {
                MessageBox.Show(eccezione.Message);
            }
        }
 public void Costruttore_SenzaPubblica_Eccezione()
 {
     BinanceExchange explorer = new BinanceExchange(null, privKey, factory);
 }
        public void TestBinanceOrderbookMerge()
        {
            //Arrange
            //Beginning Orderbooks: one empty, one with 10 values, one with 5 values
            var dummyExchange = new BinanceExchange("binance");

            dummyExchange.ProfitableSymbolMapping.TryAdd("dummy", DateTime.UtcNow);

            var beginningEmptyOrderbook = new BinanceOrderbook();


            var beginningFullOrderbook = new BinanceOrderbook();

            beginningFullOrderbook.OfficialBids = new ConcurrentDictionary <decimal, decimal>();
            beginningFullOrderbook.OfficialBids.TryAdd(32115.28m, 0.02m);


            beginningFullOrderbook.OfficialAsks = new ConcurrentDictionary <decimal, decimal>();
            beginningFullOrderbook.OfficialAsks.TryAdd(32115.29m, 0.005m);

            beginningEmptyOrderbook.Symbol = "XRPETH";
            beginningFullOrderbook.Symbol  = "XRPETH";

            beginningEmptyOrderbook.Sequence = 1;
            //beginningHalfFullOrderbook.Sequence = 1;
            beginningFullOrderbook.Sequence = 1;

            beginningEmptyOrderbook.Exchange = dummyExchange;
            //beginningHalfFullOrderbook.Exchange = dummyExchange;
            beginningFullOrderbook.Exchange = dummyExchange;

            //arrange orderbook updates: one empty, one full, one with 6 values
            var updateFullOrderbook = new BinanceOrderbook();

            updateFullOrderbook.OfficialBids = new ConcurrentDictionary <decimal, decimal>();
            updateFullOrderbook.OfficialBids.TryAdd(1m, 0.02m);
            updateFullOrderbook.OfficialBids.TryAdd(2m, 0.15m);
            updateFullOrderbook.OfficialBids.TryAdd(3m, 0.072382m);
            updateFullOrderbook.OfficialBids.TryAdd(4m, 0.066716m);
            updateFullOrderbook.OfficialBids.TryAdd(5m, 0.02m);
            updateFullOrderbook.OfficialBids.TryAdd(6m, 2.521393m);
            updateFullOrderbook.OfficialBids.TryAdd(7m, 0.117404m);
            updateFullOrderbook.OfficialBids.TryAdd(8m, 0.139009m);
            updateFullOrderbook.OfficialBids.TryAdd(9m, 0.123m);
            updateFullOrderbook.OfficialBids.TryAdd(10m, 0.11175m);

            updateFullOrderbook.OfficialAsks = new ConcurrentDictionary <decimal, decimal>();
            updateFullOrderbook.OfficialAsks.TryAdd(11m, 0.005m);
            updateFullOrderbook.OfficialAsks.TryAdd(12m, 0.03m);
            updateFullOrderbook.OfficialAsks.TryAdd(13m, 0.01759m);
            updateFullOrderbook.OfficialAsks.TryAdd(14m, 0.03m);
            updateFullOrderbook.OfficialAsks.TryAdd(15m, 0.03m);
            updateFullOrderbook.OfficialAsks.TryAdd(16m, 0.12m);
            updateFullOrderbook.OfficialAsks.TryAdd(17m, 0.08m);
            updateFullOrderbook.OfficialAsks.TryAdd(18m, 0.125775m);
            updateFullOrderbook.OfficialAsks.TryAdd(19m, 0.03563m);
            updateFullOrderbook.OfficialAsks.TryAdd(20m, 0.001m);

            var updateHalfFullOrderbook = new BinanceOrderbook();

            updateHalfFullOrderbook.OfficialBids = new ConcurrentDictionary <decimal, decimal>();
            updateHalfFullOrderbook.OfficialBids.TryAdd(1m, 0.02m);
            updateHalfFullOrderbook.OfficialBids.TryAdd(2m, 0.15m);
            updateHalfFullOrderbook.OfficialBids.TryAdd(3m, 0.072382m);
            updateHalfFullOrderbook.OfficialBids.TryAdd(4m, 0.066716m);
            updateHalfFullOrderbook.OfficialBids.TryAdd(5m, 0.02m);

            updateHalfFullOrderbook.OfficialAsks = new ConcurrentDictionary <decimal, decimal>();
            updateHalfFullOrderbook.OfficialAsks.TryAdd(6m, 0.005m);
            updateHalfFullOrderbook.OfficialAsks.TryAdd(7m, 0.03m);
            updateHalfFullOrderbook.OfficialAsks.TryAdd(8m, 0.01759m);
            updateHalfFullOrderbook.OfficialAsks.TryAdd(9m, 0.03m);
            updateHalfFullOrderbook.OfficialAsks.TryAdd(10m, 0.03m);

            updateFullOrderbook.Sequence     = 2;
            updateHalfFullOrderbook.Sequence = 2;

            updateFullOrderbook.Exchange     = dummyExchange;
            updateHalfFullOrderbook.Exchange = dummyExchange;

            updateFullOrderbook.Symbol     = "BTCUSDT";
            updateHalfFullOrderbook.Symbol = "BTCUSDT";

            //Act: run the following merge combinations:
            // empty beginning orderbook -> full update | full beginning -> half-full update | half-full beginning to full update

            beginningEmptyOrderbook.Merge(updateFullOrderbook);
            beginningFullOrderbook.Merge(updateHalfFullOrderbook);
            //beginningHalfFullOrderbook.Merge(updateFullOrderbook);

            //Assert: check that the beginning orderbooks now match the updates
            Assert.IsTrue(beginningEmptyOrderbook.OfficialAsks.Count == updateFullOrderbook.OfficialAsks.Count &&
                          beginningEmptyOrderbook.OfficialBids.Count == updateFullOrderbook.OfficialBids.Count);

            Assert.IsTrue(beginningFullOrderbook.OfficialAsks.Count == updateHalfFullOrderbook.OfficialAsks.Count &&
                          beginningFullOrderbook.OfficialBids.Count == updateHalfFullOrderbook.OfficialBids.Count);

            //Assert.IsTrue(beginningHalfFullOrderbook.OfficialAsks.Count == updateFullOrderbook.OfficialAsks.Count &&
            //    beginningHalfFullOrderbook.OfficialBids.Count == updateFullOrderbook.OfficialBids.Count);

            Assert.IsTrue(CheckLayers(updateFullOrderbook, beginningEmptyOrderbook));
            Assert.IsTrue(CheckLayers(updateHalfFullOrderbook, beginningFullOrderbook));
            //Assert.IsTrue(CheckLayers(updateFullOrderbook, beginningHalfFullOrderbook));
        }
 public void ScaricaFondi_ChiaviErrate_Eccezzione()
 {
     BinanceExchange explorer = new BinanceExchange("blabla", "blabla", factory);
     List <Fondo>    ris      = explorer.ScaricaFondi().Result;
 }
 public void Costruttore_FactoryNull_Eccezione()
 {
     BinanceExchange explorer = new BinanceExchange("", privKey, null);
 }
 public void Costruttore_PubblicaVuota_Eccezione()
 {
     BinanceExchange explorer = new BinanceExchange("", privKey, factory);
 }
 public void Costruttore_PrivataVuota_Eccezione()
 {
     BinanceExchange explorer = new BinanceExchange(pubKey, "", factory);
 }
Beispiel #16
0
 public BinanceTicker(BinanceExchange exchange) : base(exchange)
 {
     // https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md
     // Receiving an event that removes a price level that is not in your local order book can happen and is normal.
     OrderBook.EnableValidationOnRemove = false;
 }
 public void Costruttore_SenzaPrivata_Eccezione()
 {
     BinanceExchange explorer = new BinanceExchange(pubKey, null, factory);
 }