Exemplo n.º 1
0
        public void CalculateArbitrationTests_26()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(0.21482587m, 405.0m));

            bidBook.Bids.Add(new Order(0.35417808m, 410.0m));

            opportunity = hunter.CalculateArbitration(btce, anx, 0.12478543m, 25.01m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.06175308m);
            Assert.IsTrue(opportunity.SellAmount == 0.06159870m);
            Assert.IsTrue(opportunity.TotalBuyCost == 25.0099974m);
            Assert.IsTrue(opportunity.TotalSellCost == 25.1670728655m);
            Assert.IsTrue(opportunity.Profit == 0.1570754655m);
        }
Exemplo n.º 2
0
        public void AnxBalanceUpdateTest()
        {
            Anx anx = new Anx(FiatType.Usd);

            //If there is any problem connecting to the exchange, this will throw an error.
            anx.UpdateBalances();
        }
Exemplo n.º 3
0
        public void CalculateArbitrationTests_24()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(0.21482587m, 405.0m));

            bidBook.Bids.Add(new Order(0.35417808m, 410.0m));

            opportunity = hunter.CalculateArbitration(btce, anx, 1000m, 2000m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.21482587m);
            Assert.IsTrue(opportunity.SellAmount == 0.21428881m);
            Assert.IsTrue(opportunity.TotalBuyCost == 87.00447735m);
            Assert.IsTrue(opportunity.TotalSellCost == 87.55090765765m);
            Assert.IsTrue(opportunity.Profit == 0.54643030765m);
        }
Exemplo n.º 4
0
        public void CalculateArbitrationTests_19()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(1.0m, 405.0m));

            bidBook.Bids.Add(new Order(0.5m, 410.0m));

            opportunity = hunter.CalculateArbitration(btce, anx, 99m, 50m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.12345679m);
            Assert.IsTrue(opportunity.SellAmount == 0.12314815m);
            Assert.IsTrue(opportunity.TotalBuyCost == 49.99999995m);
            Assert.IsTrue(opportunity.TotalSellCost == 50.31402390475m);
            Assert.IsTrue(opportunity.Profit == 0.31402395475m);
        }
Exemplo n.º 5
0
        public void CalculateArbitrationTests_23()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            kraken.OrderBook = askBook;
            anx.OrderBook    = bidBook;

            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            askBook.Asks.Add(new Order(1.0m, 405.0m));

            bidBook.Bids.Add(new Order(0.78m, 410.0m));

            opportunity = hunter.CalculateArbitration(kraken, anx, 0.09m, 30.01m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.07391398m);
            Assert.IsTrue(opportunity.SellAmount == 0.07391398m);
            Assert.IsTrue(opportunity.TotalSellCost == 30.1986652387m);

            //Note, because Kraken rounds to 4 decimal places, the total buy cost and profit will be different that what is calculated on the sheet
            Assert.IsTrue(opportunity.TotalBuyCost == 30.01m);
            Assert.IsTrue(opportunity.Profit == 0.1886652387m);
        }
Exemplo n.º 6
0
        public void CalculateArbitrationTests_16()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(1.1m, 405.0m));

            bidBook.Bids.Add(new Order(1.0m, 410.0m));

            opportunity = hunter.CalculateArbitration(btce, anx, 0.45127846m, 200m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.45240665m);
            Assert.IsTrue(opportunity.SellAmount == 0.45127563m);
            Assert.IsTrue(opportunity.TotalBuyCost == 183.22469325m);
            Assert.IsTrue(opportunity.TotalSellCost == 184.37542777095m);
            Assert.IsTrue(opportunity.Profit == 1.15073452095m);
        }
Exemplo n.º 7
0
        public void CalculateArbitrationTests_18()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(0.99999375m, 405.0m));

            bidBook.Bids.Add(new Order(0.9975m, 410.0m));

            opportunity = hunter.CalculateArbitration(btce, anx, 99m, 1000m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.99999375m);
            Assert.IsTrue(opportunity.SellAmount == 0.99749377m);
            Assert.IsTrue(opportunity.TotalBuyCost == 404.99746875m);
            Assert.IsTrue(opportunity.TotalSellCost == 407.54104214005m);
            Assert.IsTrue(opportunity.Profit == 2.54357339005m);
        }
Exemplo n.º 8
0
        public void AnxTradeFeeIsSet()
        {
            Anx anx = new Anx();

            Assert.IsTrue(anx.TradeFee > 0);
            Assert.IsTrue(anx.TradeFeeAsDecimal > 0);
        }
Exemplo n.º 9
0
        public void CalculateArbitrationTests_15()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(1.0m, 405.0m));

            bidBook.Bids.Add(new Order(1.04m, 410.0m));

            opportunity = hunter.CalculateArbitration(btce, anx, 99m, 10.9872m, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.BuyAmount == 0.02712888m);
            Assert.IsTrue(opportunity.SellAmount == 0.02706106m);
            Assert.IsTrue(opportunity.TotalBuyCost == 10.9871964m);
            Assert.IsTrue(opportunity.TotalSellCost == 11.0562019789m);
            Assert.IsTrue(opportunity.Profit == 0.0690055789m);
        }
Exemplo n.º 10
0
        public void AnxGetTradeListTest()
        {
            Anx anx = new Anx();

            //If there is any problem connecting to the exchange, this will throw an error.
            ArrayList tradeList = anx.GetTradeList();
        }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
        public void AnxUpdateOrderBookTest()
        {
            Anx anx = new Anx();

            //If there is any problem connecting to the exchange, this will throw an error.
            anx.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(anx.OrderBook.Asks.Count == 1);
            Assert.IsTrue(anx.OrderBook.Bids.Count == 1);
        }
Exemplo n.º 13
0
        public void CalculateArbitrationTests_10()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();
            decimal   maxFiatForTrade;
            decimal   maxBtcForTrade;

            kraken.OrderBook = askBook;
            anx.OrderBook    = bidBook;

            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            //Test Case 10: Cannot take full advantage of arbitration due to max USD limitation
            maxFiatForTrade = 200m;
            maxBtcForTrade  = 10.0m;
            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            askBook.Asks.Add(new Order(0.2m, 418m));
            askBook.Asks.Add(new Order(0.1m, 419m));
            askBook.Asks.Add(new Order(1.0m, 420m));

            bidBook.Bids.Add(new Order(0.2m, 430m));
            bidBook.Bids.Add(new Order(0.24m, 429m));
            bidBook.Bids.Add(new Order(1.0m, 425m));

            opportunity = hunter.CalculateArbitration(kraken, anx, maxBtcForTrade, maxFiatForTrade, 0.01m, false);

            //Make sure opportunity was found correctly
            //Note, C# carries out more digits than when I do manual calculations, so manual calculations will be a little different than what
            //is calculated by the hunter. In these checks, I make sure the numbers returned by the hunter round to the manual calculations.
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyAmount == 0.47619344m);
            Assert.IsTrue(opportunity.SellAmount == 0.47619344m);
            Assert.IsTrue(opportunity.BuyPrice == 420m);
            Assert.IsTrue(opportunity.SellPrice == 425m);
            Assert.IsTrue(opportunity.TotalSellCost == 203.627014258m);

            //Note, because Kraken rounds to 4 decimal places, the total buy cost and profit will be different that what is calculated on the sheet
            Assert.IsTrue(opportunity.TotalBuyCost == 200.00m);
            Assert.IsTrue(opportunity.Profit == 3.627014258m);
        }
Exemplo n.º 14
0
        public void CalculateArbitrationTests_08()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();
            decimal   maxFiatForTrade;
            decimal   maxBtcForTrade;

            kraken.OrderBook = askBook;
            anx.OrderBook    = bidBook;

            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            //Test Case 8: Cannot take full advantage of arbitration due to max USD limitation
            maxFiatForTrade = 100m;
            maxBtcForTrade  = 10.0m;
            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            askBook.Asks.Add(new Order(1.0m, 405m));

            bidBook.Bids.Add(new Order(1.0m, 410m));

            opportunity = hunter.CalculateArbitration(kraken, anx, maxBtcForTrade, maxFiatForTrade, 0.01m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyAmount == 0.24629783m);
            Assert.IsTrue(opportunity.SellAmount == 0.24629783m);
            Assert.IsTrue(opportunity.BuyPrice == 405m);
            Assert.IsTrue(opportunity.SellPrice == 410m);
            Assert.IsTrue(opportunity.TotalSellCost == 100.62867291395m);

            //Note, because Kraken rounds to 4 decimal places, the total buy cost and profit will be different that what is calculated on the sheet
            Assert.IsTrue(opportunity.TotalBuyCost == 100m);
            Assert.IsTrue(opportunity.Profit == 0.62867291395m);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public void CalculateArbitrationTests_03()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            kraken.OrderBook = askBook;
            anx.OrderBook    = bidBook;

            //Test case 3: Multiple asks orders are fulfilled across one bid
            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            askBook.Asks.Add(new Order(0.2m, 399m));
            askBook.Asks.Add(new Order(0.4m, 401m));
            askBook.Asks.Add(new Order(1.0m, 410m));

            bidBook.Bids.Add(new Order(0.6m, 405m));
            bidBook.Bids.Add(new Order(1.0m, 401m));
            bidBook.Bids.Add(new Order(2.8m, 398m));

            opportunity = hunter.CalculateArbitration(kraken, anx, 99m, 999999m, 1.348m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyAmount == 0.6m);
            Assert.IsTrue(opportunity.SellAmount == 0.6m);
            Assert.IsTrue(opportunity.Profit == 1.349m);
            Assert.IsTrue(opportunity.BuyPrice == 401);
            Assert.IsTrue(opportunity.SellPrice == 405);
            Assert.IsTrue(opportunity.TotalBuyCost == 240.8005m);
            Assert.IsTrue(opportunity.TotalSellCost == 242.1495m);
        }
Exemplo n.º 17
0
        public void CalculateArbitrationTests_14()
        {
            ArbitrationHunter hunter = new ArbitrationHunter(null);
            Btce btce = new Btce();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            btce.OrderBook = askBook;
            anx.OrderBook  = bidBook;

            //Test case 13: Amount is floor rounded to the minimum of the two exchanges
            btce.TradeFee = 0.25m;
            anx.TradeFee  = 0.35m;

            askBook.Asks.Add(new Order(1.1m, 398.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.65479204m, 401.0m));
            bidBook.Bids.Add(new Order(1.0m, 399m));
            bidBook.Bids.Add(new Order(2.8m, 398m));

            opportunity = hunter.CalculateArbitration(btce, anx, 99m, 999999m, 0.30m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == btce);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyPrice == 398m);
            Assert.IsTrue(opportunity.SellPrice == 401m);
            Assert.IsTrue(opportunity.BuyAmount == 0.65642902m);
            Assert.IsTrue(opportunity.SellAmount == 0.65478795m);
            Assert.IsTrue(opportunity.TotalBuyCost == 261.25874996m);
            Assert.IsTrue(opportunity.TotalSellCost == 261.650973062175m);
            Assert.IsTrue(opportunity.Profit == 0.392223102175m);
        }
Exemplo n.º 18
0
        public void CalculateArbitrationTests_07()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            kraken.OrderBook = askBook;
            anx.OrderBook    = bidBook;

            //Test Case 7: Max amount is lower than possible arbitration
            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.35m;

            askBook.Asks.Add(new Order(0.2m, 399m));
            askBook.Asks.Add(new Order(0.4m, 401m));
            askBook.Asks.Add(new Order(1.0m, 410m));

            bidBook.Bids.Add(new Order(0.6m, 405m));
            bidBook.Bids.Add(new Order(1.0m, 401m));
            bidBook.Bids.Add(new Order(2.8m, 398m));

            opportunity = hunter.CalculateArbitration(kraken, anx, 0.4m, 999999m, 0.032m, false);

            //Make sure opportunity was found correctly
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyAmount == 0.4m);
            Assert.IsTrue(opportunity.SellAmount == 0.4m);
            Assert.IsTrue(opportunity.Profit == 1.033m);
            Assert.IsTrue(opportunity.BuyPrice == 401m);
            Assert.IsTrue(opportunity.SellPrice == 405m);
            Assert.IsTrue(opportunity.TotalBuyCost == 160.4m);
            Assert.IsTrue(opportunity.TotalSellCost == 161.433m);
        }
Exemplo n.º 19
0
        public void AnxBuySellQueryDeleteTest()
        {
            Anx    anx = new Anx(FiatType.Usd);
            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 = anx.Buy(anx.MinimumBitcoinOrderAmount, 10m);

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

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

            //Now delete both orders. If there are any errors with either of these operations,
            //an exception will be thrown.
            anx.DeleteOrder(buyOrderId);
            anx.DeleteOrder(sellorderId);
        }
Exemplo n.º 20
0
        public void CalculateArbitrationTests_02()
        {
            ArbitrationHunter      hunter = new ArbitrationHunter(null);
            Kraken                 kraken = new Kraken();
            ArbitrationOpportunity opportunity;
            Anx       anx     = new Anx();
            OrderBook askBook = new OrderBook();
            OrderBook bidBook = new OrderBook();

            kraken.OrderBook = askBook;
            anx.OrderBook    = bidBook;

            //Test case 2: All of ask order is fulfilled across multiple bids
            kraken.TradeFee = 0.25m;
            anx.TradeFee    = 0.25m;

            askBook.Asks.Add(new Order(1.2m, 398m));
            askBook.Asks.Add(new Order(0.8m, 402m));
            askBook.Asks.Add(new Order(1.0m, 410m));

            bidBook.Bids.Add(new Order(0.6m, 402m));
            bidBook.Bids.Add(new Order(1.0m, 401m));
            bidBook.Bids.Add(new Order(2.8m, 398m));

            opportunity = hunter.CalculateArbitration(kraken, anx, 99m, 999999m, 1.79m, false);
            Assert.IsTrue(opportunity != null);
            Assert.IsTrue(opportunity.BuyExchange == kraken);
            Assert.IsTrue(opportunity.SellExchange == anx);
            Assert.IsTrue(opportunity.BuyAmount == 1.2m);
            Assert.IsTrue(opportunity.SellAmount == 1.2m);
            Assert.IsTrue(opportunity.Profit == 1.8015m);
            Assert.IsTrue(opportunity.BuyPrice == 398m);
            Assert.IsTrue(opportunity.SellPrice == 401m);
            Assert.IsTrue(opportunity.TotalBuyCost == 478.794m);
            Assert.IsTrue(opportunity.TotalSellCost == 480.5955m);
        }
Exemplo n.º 21
0
        public void AnxGetAllOpenOrdersTest()
        {
            Anx anx = new Anx();

            List <Dictionary <string, dynamic> > openOrders = anx.GetAllOpenOrders();
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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);
        }