Example #1
0
        public void ItBitTradeFeeIsSet()
        {
            ItBit itBit = new ItBit();

            Assert.IsTrue(itBit.TradeFee > 0);
            Assert.IsTrue(itBit.TradeFeeAsDecimal > 0);
        }
Example #2
0
        public void GetTotalBalances()
        {
            ItBit    itbit    = new ItBit();
            Anx      anx      = new Anx();
            Bitstamp bitstamp = new Bitstamp();
            Kraken   kraken   = new Kraken();
            //Btce btce = new Btce();
            Bitfinex bitfinex = new Bitfinex();

            itbit.UpdateBalances();
            anx.UpdateBalances();
            bitstamp.UpdateBalances();
            bitfinex.UpdateBalances();

            //TODO: Fix these! Should be calls to UpdateTotalBalances!
            kraken.UpdateBalances();
            //btce.UpdateBalances();

            Decimal itBitBtcAmount      = itbit.TotalBtc;
            Decimal itBitFiatAmount     = itbit.TotalFiat;
            Decimal anxBtcAmount        = anx.TotalBtc;
            Decimal anxFiatAmount       = anx.TotalFiat;
            Decimal bitstampBtcAmount   = bitstamp.TotalBtc;
            Decimal bitstampFiatoAmount = bitstamp.TotalFiat;
            Decimal bitfinexBtcAmount   = bitfinex.TotalBtc;
            Decimal bitfinexFiatAmount  = bitfinex.TotalFiat;

            //TODO Fix these! They should be the total amounts!
            Decimal krakenBtcAmount = kraken.AvailableBtc;
            Decimal krakenEurAmount = kraken.AvailableFiat;
            //Decimal btceBtcAmount = btce.AvailableBtc;
            //Decimal btceEuroAmount = btce.AvailableFiat;
        }
Example #3
0
        public void ItBitBalancesUpdateTest()
        {
            ItBit itBit = new ItBit(FiatType.Usd);

            //If there is any problem connecting to the exchange, this will throw an error.
            itBit.UpdateBalances();
        }
Example #4
0
        public void ItBitSellTest()
        {
            ItBit itBit = new ItBit();

            //Buy at a really low price to the order doesn't actually get executed.
            //This operation will error out if there is any problem
            string orderId = itBit.Sell(0.0538m, 999.99m);

            itBit.DeleteOrder(orderId);
        }
Example #5
0
        public void ItBitUpdateOrderBookTest()
        {
            ItBit itBit = new ItBit();

            //If there is any problem connecting to the exchange, this will throw an error.
            itBit.UpdateOrderBook(1);

            //This assumes that the exchange has at least 1 order on each side. Technically this can give a false negative, but it's unlikely.
            Assert.IsTrue(itBit.OrderBook.Asks.Count == 1);
            Assert.IsTrue(itBit.OrderBook.Bids.Count == 1);
        }
Example #6
0
        public void CalculateArbitrationTests_04()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            ItBit                  itbit  = new ItBit();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            itbit.OrderBook = askBook;
            anx.OrderBook   = bidBook;

            //Test Case 4: Multiple asks orders are fulfilled across multiple bids
            itbit.TradeFee = 0.25m;
            anx.TradeFee   = 0.3m;

            askBook.Asks.Add(new Order(0.5m, 397m));
            askBook.Asks.Add(new Order(0.4m, 399m));
            askBook.Asks.Add(new Order(1.0m, 410m));

            bidBook.Bids.Add(new Order(0.2m, 405m));
            bidBook.Bids.Add(new Order(0.5m, 403m));
            bidBook.Bids.Add(new Order(0.4m, 402m));
            bidBook.Bids.Add(new Order(2.8m, 398m));

            opportunity = hunter.CalculateArbitration(itbit, anx, 99m, 999999m, 2.80m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == itbit);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyAmount == 0.9m);
            Assert.IsTrue(opportunity.SellAmount == 0.9m);
            Assert.IsTrue(opportunity.Profit == 2.81605m);
            Assert.IsTrue(opportunity.BuyPrice == 399m);
            Assert.IsTrue(opportunity.SellPrice == 402m);
            Assert.IsTrue(opportunity.TotalBuyCost == 358.99525m);
            Assert.IsTrue(opportunity.TotalSellCost == 361.8113m);
        }
Example #7
0
        public void CalculateArbitrationTests_13()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            ItBit     itBit   = new ItBit();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            kraken.OrderBook = askBook;
            itBit.OrderBook  = bidBook;

            //Test case 13: Amount is floor rounded to the minimum of the two exchanges
            kraken.TradeFee = 0.0m;
            itBit.TradeFee  = 0.0m;

            askBook.Asks.Add(new Order(1.1m, 400.0m));
            askBook.Asks.Add(new Order(0.8m, 402.0m));
            askBook.Asks.Add(new Order(1.0m, 410.0m));

            bidBook.Bids.Add(new Order(0.65471204m, 401.0m));
            bidBook.Bids.Add(new Order(1.0m, 399m));
            bidBook.Bids.Add(new Order(2.8m, 398m));

            opportunity = hunter.CalculateArbitration(kraken, itBit, 99m, 999999m, 0.58m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == itBit);
            Assert.IsTrue(opportunity.BuyAmount == 0.6547m);
            Assert.IsTrue(opportunity.SellAmount == 0.6547m);
            Assert.IsTrue(opportunity.Profit == 0.6547m);
            Assert.IsTrue(opportunity.BuyPrice == 400m);
            Assert.IsTrue(opportunity.SellPrice == 401m);
            Assert.IsTrue(opportunity.TotalBuyCost == 261.88m);
            Assert.IsTrue(opportunity.TotalSellCost == 262.5347m);
        }
Example #8
0
        public void ItBitBuySellQueryDeleteTest()
        {
            ItBit  itBit = new ItBit();
            string buyOrderId;
            string sellorderId;

            //First, insert a buy and sell order. If there are any errors with either of these operations,
            //an exception will be thrown.

            //Buy at a really low price to the order doesn't actually get executed.
            buyOrderId = itBit.Buy(1.00m, 0.01m);

            //Sell at a really high price so the order doesn't actually get executed.
            sellorderId = itBit.Sell(itBit.MinimumBitcoinOrderAmount, 9999m);

            //Both orders should still be open
            Assert.IsFalse(itBit.IsOrderFulfilled(buyOrderId));
            Assert.IsFalse(itBit.IsOrderFulfilled(sellorderId));

            //Now delete both orders. If there are any errors with either of these operations,
            //an exception will be thrown.
            itBit.DeleteOrder(buyOrderId);
            itBit.DeleteOrder(sellorderId);
        }
Example #9
0
        public void Current()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            ItBit     itBit   = new ItBit();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook  = askBook;
            itBit.OrderBook = bidBook;

            btce.TradeFee  = 0.2m;
            itBit.TradeFee = 0.2m;

            askBook.Asks.Add(new Order(43.01161324m, 400.00m));

            bidBook.Bids.Add(new Order(50m, 403.00m));

            opportunity = hunter.CalculateArbitration(btce, itBit, 0.1m, 20.00m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
        }
Example #10
0
        public void OpportunityProfitValidatesProperly()
        {
            int                 requiredRoundsForValidarion = 3;
            Anx                 anx           = new Anx();
            Bitstamp            bitstamp      = new Bitstamp();
            Kraken              kraken        = new Kraken();
            ItBit               itBit         = new ItBit();
            List <BaseExchange> exchangeList  = new List <BaseExchange>();
            decimal             amount        = 0.2m;
            decimal             buyPrice      = 150m;
            decimal             totalBuyCost  = 30m;
            decimal             sellPrice     = 200m;
            decimal             totalSellCost = 40m;
            decimal             profit        = 10m;


            exchangeList.Add(anx);
            exchangeList.Add(bitstamp);
            exchangeList.Add(kraken);
            exchangeList.Add(itBit);

            OpportunityValidator opportunityValidator = new OpportunityValidator(requiredRoundsForValidarion, exchangeList);

            //Note, can use a fake run id here because the trade is never persisted to the db.
            ArbitrationOpportunity testOpportunity = new ArbitrationOpportunity(anx, bitstamp, amount, buyPrice, totalBuyCost, sellPrice, totalSellCost, profit, 1);

            //First, set the balances for all the exchanges.
            anx.AvailableFiat      = 100m;
            anx.AvailableBtc       = 100m;
            bitstamp.AvailableFiat = 100m;
            bitstamp.AvailableBtc  = 100m;
            kraken.AvailableFiat   = 100m;
            kraken.AvailableBtc    = 100m;
            itBit.AvailableFiat    = 100m;
            itBit.AvailableBtc     = 100m;

            //Scenario 1; happy path. Buy and selling works as expected.

            //Prep the validator
            opportunityValidator.SetFiatAndBitcoinBalanceBeforeArbitrationTrade();

            //Simulate the trade going through
            anx.AvailableFiat      -= totalBuyCost;
            anx.AvailableBtc       += amount;
            bitstamp.AvailableFiat += totalSellCost;
            bitstamp.AvailableBtc  -= amount;

            //If there was as error, this will throw it.
            opportunityValidator.ValidateExchangeBalancesAfterTrade(testOpportunity);

            //Scenario 2: Buy never happens. Validator should throw an error
            bool errorThrown = false;

            anx.AvailableFiat      = 100m;
            anx.AvailableBtc       = 100m;
            bitstamp.AvailableFiat = 100m;
            bitstamp.AvailableBtc  = 100m;
            kraken.AvailableFiat   = 100m;
            kraken.AvailableBtc    = 100m;
            itBit.AvailableFiat    = 100m;
            itBit.AvailableBtc     = 100m;

            //Prep the validator
            opportunityValidator.SetFiatAndBitcoinBalanceBeforeArbitrationTrade();

            //Simulate the trade going through, but buy never happens. This should cause the validator to throw an error.
            bitstamp.AvailableFiat += totalSellCost;
            bitstamp.AvailableBtc  -= amount;

            try
            {
                opportunityValidator.ValidateExchangeBalancesAfterTrade(testOpportunity);
            }
            catch (Exception e)
            {
                errorThrown = true;
            }

            Assert.IsTrue(errorThrown);
        }
Example #11
0
        public void OpportunityListValidatesProperly()
        {
            int      requiredRoundsForValidarion = 3;
            Anx      anx      = new Anx();
            Bitstamp bitstamp = new Bitstamp();
            Kraken   kraken   = new Kraken();
            ItBit    itBit    = new ItBit();
            List <ArbitrationOpportunity> opportunityList = new List <ArbitrationOpportunity>();
            List <ArbitrationOpportunity> validatedList;
            List <BaseExchange>           exchangeList = new List <BaseExchange>();

            exchangeList.Add(anx);
            exchangeList.Add(bitstamp);
            exchangeList.Add(kraken);
            exchangeList.Add(itBit);

            OpportunityValidator opportunityValidator = new OpportunityValidator(requiredRoundsForValidarion, exchangeList);

            //Build of a list of opportunities:
            ArbitrationOpportunity krakenItBitopportunity = new ArbitrationOpportunity(kraken, itBit)
            {
                Profit = 2.23m
            };
            ArbitrationOpportunity krakenBitstampopportunity = new ArbitrationOpportunity(kraken, bitstamp)
            {
                Profit = 0.50m
            };
            ArbitrationOpportunity anxItBitopportunity = new ArbitrationOpportunity(anx, itBit)
            {
                Profit = 2.01m
            };
            ArbitrationOpportunity anxItBitopportunity2 = new ArbitrationOpportunity(anx, itBit)
            {
                Profit = 1.98m
            };
            ArbitrationOpportunity anxItBitopportunity3 = new ArbitrationOpportunity(anx, itBit)
            {
                Profit = 0.27m
            };

            opportunityList.Add(krakenItBitopportunity);
            opportunityList.Add(krakenBitstampopportunity);
            opportunityList.Add(anxItBitopportunity);

            //Round one:
            validatedList = opportunityValidator.ValidateOpportunities(opportunityList);
            Assert.IsTrue(validatedList.Count == 0);

            //Round two:
            opportunityList.Remove(krakenBitstampopportunity);
            validatedList = opportunityValidator.ValidateOpportunities(opportunityList);
            Assert.IsTrue(validatedList.Count == 0);

            //Round three: An oppportunity between Anx and ItBit has survived until now (alebit with a different profit)
            //Add the Kraken - Bitstamp opportunity.
            //Remove Krakken - ItBit opportunity; it only lasts two rounds.
            opportunityList.Add(krakenBitstampopportunity);
            opportunityList.Remove(krakenItBitopportunity);

            //Remove the Anx - ItBit opportunity, than add another opportunity with those exchanges but a less profit
            opportunityList.Remove(anxItBitopportunity);
            opportunityList.Add(anxItBitopportunity2);

            validatedList = opportunityValidator.ValidateOpportunities(opportunityList);
            Assert.IsTrue(validatedList.Count == 1);
            Assert.IsTrue(validatedList[0].Profit == 1.98m);

            //Round 4: anxItBitopportunity should still be in the returned list
            //Remove the Anx - ItBit opportunity, than add another opportunity with those exchanges but a less profit
            opportunityList.Remove(anxItBitopportunity);
            opportunityList.Add(anxItBitopportunity3);
            validatedList = opportunityValidator.ValidateOpportunities(opportunityList);
            Assert.IsTrue(validatedList.Count == 1);
            Assert.IsTrue(validatedList[0].Profit == 0.27m);

            //Round 5: anxItBitopportunity should still be in the returned list, krakenBitstampopportunity should have been added
            validatedList = opportunityValidator.ValidateOpportunities(opportunityList);
            Assert.IsTrue(validatedList.Count == 2);
            Assert.IsTrue(validatedList[0].Profit == 0.50m);
            Assert.IsTrue(validatedList[1].Profit == 0.27m);
        }
Example #12
0
        private static void PopulateExchanges(string securityJsonFilename)
        {
            m_security = new ApiSecurity(securityJsonFilename);
            foreach (var exch in m_security.ApiKeys.Keys)
            {
                var c = m_security.ApiKeys[exch];
                //Console.WriteLine("{0} '{1}' '{2}'", exch, c.ApiKey, c.ApiSecret);
            }

            ApiCredentials creds;

            /*creds = m_security.ApiKeys["B2C2"];                             // BINANCE
             * b2c2 = B2C2.Create(creds);
             * Exchanges[CryptoExch.B2C2] = b2c2;*/

            creds   = m_security.ApiKeys["BINANCE"];                        // BINANCE
            binance = Binance.Create(creds);
            Exchanges[CryptoExch.BINANCE] = binance;

            creds    = m_security.ApiKeys["BITFINEX"];                      // BITFINEX
            bitfinex = Bitfinex.Create(creds);
            Exchanges[CryptoExch.BITFINEX] = bitfinex;

            creds    = m_security.ApiKeys["BITFLYER"];                      // BITFLYER
            bitflyer = BitFlyer.Create(creds);
            Exchanges[CryptoExch.BITFLYER] = bitflyer;

            creds    = m_security.ApiKeys["BITSTAMP"];                      // BITSTAMP
            bitstamp = Bitstamp.Create(creds, "client_id");
            Exchanges[CryptoExch.BITSTAMP] = bitstamp;

            creds   = m_security.ApiKeys["BITTREX"];                        // BITTREX
            bittrex = Bittrex.Create(creds);
            Exchanges[CryptoExch.BITTREX] = bittrex;

            creds = m_security.ApiKeys["GDAX"];                             // GDAX
            gdax  = GDAX.Create(creds, "mickey+mouse");
            Exchanges[CryptoExch.GDAX] = gdax;

            creds  = m_security.ApiKeys["HITBTC"];                          // HITBTC
            hitbtc = HitBTC.Create(creds);
            Exchanges[CryptoExch.HITBTC] = hitbtc;

            creds = m_security.ApiKeys["ITBIT"];                            // ITBIT
            itbit = ItBit.Create(creds);
            Exchanges[CryptoExch.ITBIT] = itbit;

            creds  = m_security.ApiKeys["KRAKEN"];                          // KRAKEN
            kraken = Kraken.Create(creds);
            Exchanges[CryptoExch.KRAKEN] = kraken;

            creds    = m_security.ApiKeys["POLONIEX"];                      // POLONIEX
            poloniex = Poloniex.Create(creds);
            Exchanges[CryptoExch.POLONIEX] = poloniex;

            /*creds = m_security.ApiKeys["BLEUTRADE"];                        // BLEUTRADE
             * bleutrade = Bleutrade.Create(creds);
             * Exchanges[CryptoExch.BLEUTRADE] = bleutrade;
             *
             * creds = m_security.ApiKeys["BLINKTRADE"];                       // BLINKTRADE
             * blinktrade = BlinkTrade.Create(creds);
             * Exchanges[CryptoExch.BLINKTRADE] = blinktrade;*/

            gemini = Gemini.Instance;
            Exchanges[CryptoExch.GEMINI] = Gemini.Instance;

            // For each exchange, subscribe to the various events
            foreach (var exchange in Exchanges.Values)
            {
                exchange.UpdateOrderBookEvent += Exchanges_UpdateOrderBookEvent;
                exchange.UpdateOrdersEvent    += Exchanges_UpdateOrdersEvent;
                exchange.UpdateTickerEvent    += Exchanges_UpdateTickerEvent;

                /*var ws = exchange as IExchangeWebSocket;
                 * if (ws != null)
                 *  ws.StartWebSocket(null);*/
            }

            /*Exchanges[CryptoExch.VAULTORO] = Vaultoro.Instance;
             * Exchanges[CryptoExch.CHANGELLY] = Changelly.Instance;
             * Exchanges[CryptoExch.BITHUMB] = Bithumb.Instance;
             * Exchanges[CryptoExch.BITMEX] = BitMEX.Instance;
             * Exchanges[CryptoExch.BITSQUARE] = Bitsquare.Instance;
             * Exchanges[CryptoExch.BTCC] = BTCC.Instance;
             * //Exchanges[CryptoExch.BTER] = BTER.Instance;
             * Exchanges[CryptoExch.CEX] = Cex.Instance;
             * //Exchanges[CryptoExch.COINIGY] = Coinigy.Instance;
             * Exchanges[CryptoExch.COINONE] = Coinone.Instance;
             * Exchanges[CryptoExch.GATEIO] = GateIO.Instance;
             * Exchanges[CryptoExch.HUOBI] = Huobi.Instance;
             * Exchanges[CryptoExch.KORBIT] = Korbit.Instance;
             * Exchanges[CryptoExch.KUCOIN] = Kucoin.Instance;
             * Exchanges[CryptoExch.OKCOIN] = OkCoin.Instance;
             * Exchanges[CryptoExch.OKEX] = OKEx.Instance;
             * Exchanges[CryptoExch.WEX] = Wex.Instance;
             * Exchanges[CryptoExch.XCRYPTO] = XCrypto.Instance;*/
        }