コード例 #1
0
        public void CompleteTransfersTest()
        {
            Btce    buyExchange  = new Btce();
            Kraken  sellExchange = new Kraken();
            decimal initialBuyExchangeBTCBalance  = 10;
            decimal initialSellExchangeBTCBalance = 10;

            buyExchange.AvailableBtc  = initialBuyExchangeBTCBalance;
            sellExchange.AvailableBtc = initialSellExchangeBTCBalance;

            List <Transfer> transferList = new List <Transfer>();
            Transfer        transfer1    = TransferManager.OnTimeTransfer_Simulate(buyExchange, sellExchange, 2.01m);;
            Transfer        transfer2    = TransferManager.OnTimeTransfer_Simulate(buyExchange, sellExchange, 1.022m);
            Transfer        transfer3    = TransferManager.OnTimeTransfer_Simulate(buyExchange, sellExchange, 0.654968519m);
            Transfer        transfer4    = TransferManager.OnTimeTransfer_Simulate(buyExchange, sellExchange, 3.6549871m);

            try
            {
                transfer1.CompleteDateTime = DateTime.Now.AddHours(-1);
                transfer4.CompleteDateTime = DateTime.Now.AddHours(-1);

                //Calcualte expected balances
                decimal expectedBuyExchangeBtcBalance   = initialBuyExchangeBTCBalance - transfer1.Amount - transfer2.Amount - transfer3.Amount - transfer4.Amount;
                decimal expectedSellExchangeBtcTransfer = transfer1.Amount - transfer1.OriginExchange.BtcTransferFee + transfer2.Amount - transfer2.OriginExchange.BtcTransferFee + transfer3.Amount - transfer3.OriginExchange.BtcTransferFee + transfer4.Amount - transfer4.OriginExchange.BtcTransferFee;
                decimal expectedSellExchangeBtcBalance  = initialSellExchangeBTCBalance + transfer1.Amount - transfer1.OriginExchange.BtcTransferFee + transfer4.Amount - transfer4.OriginExchange.BtcTransferFee;
                decimal expectedSellBtcInTransferAfterTransferCompletion = transfer2.Amount - transfer2.OriginExchange.BtcTransferFee + transfer3.Amount - transfer3.OriginExchange.BtcTransferFee;

                //Make sure the btce has been placed in transit and removed from the origin exchange
                Assert.IsTrue(buyExchange.AvailableBtc == expectedBuyExchangeBtcBalance);
                Assert.IsTrue(sellExchange.BTCInTransfer == expectedSellExchangeBtcTransfer);

                transferList.Add(transfer1);
                transferList.Add(transfer2);
                transferList.Add(transfer3);
                transferList.Add(transfer4);

                TransferManager.CompleteTransfers(transferList);

                Assert.IsTrue(transferList.Count == 2);
                Assert.IsTrue(sellExchange.AvailableBtc == expectedSellExchangeBtcBalance);
                Assert.IsTrue(sellExchange.BTCInTransfer == expectedSellBtcInTransferAfterTransferCompletion);
            }
            finally
            {
                DatabaseManager.ExecuteNonQuery(String.Format("delete from TRANSFER where ID in ({0}, {1}, {2}, {3})", DatabaseManager.FormatNullableIntegerForDb((transfer1.Id)), DatabaseManager.FormatNullableIntegerForDb((transfer2.Id)), DatabaseManager.FormatNullableIntegerForDb((transfer3.Id)), DatabaseManager.FormatNullableIntegerForDb((transfer4.Id))));
            }
        }