Beispiel #1
0
        public void TestFailedRegular()
        {
            InitExchange();

            var baseSymbol  = DomainSettings.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test order amount and prices below limit
            try
            {
                buyer.OpenLimitOrder(0, 0.5m, Buy);
                Assert.IsTrue(false, "Order should fail due to insufficient amount");
            }
            catch (Exception e) { }
            try
            {
                buyer.OpenLimitOrder(0.5m, 0, Buy);
                Assert.IsTrue(false, "Order should fail due to insufficient price");
            }
            catch (Exception e) { }
        }
Beispiel #2
0
        public void TestIoCLimitMinimumQuantity()
        {
            InitExchange();

            var baseSymbol  = DomainSettings.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test order amount and prices at the limit

            var minimumBaseToken  = UnitConversion.ToDecimal(simulator.Nexus.RootChain.InvokeContract(simulator.Nexus.RootStorage, "exchange", "GetMinimumTokenQuantity", buyer.baseToken).AsNumber(), buyer.baseToken.Decimals);
            var minimumQuoteToken = UnitConversion.ToDecimal(simulator.Nexus.RootChain.InvokeContract(simulator.Nexus.RootStorage, "exchange", "GetMinimumTokenQuantity", buyer.quoteToken).AsNumber(), buyer.baseToken.Decimals);

            buyer.OpenLimitOrder(minimumBaseToken, minimumQuoteToken, Buy, IoC: true);
            seller.OpenLimitOrder(minimumBaseToken, minimumQuoteToken, Sell, IoC: true);

            buyer.OpenLimitOrder(1m, 1m, Buy);
            buyer.OpenLimitOrder(1m, 1m, Buy);
            Assert.IsTrue(seller.OpenLimitOrder(1m + (minimumBaseToken * .99m), 1m, Sell) == 1m, "Used leftover under minimum quantity");
        }
Beispiel #3
0
        public void TestLimitOrderMultipleFulfilsPerOrder()
        {
            InitExchange();

            var baseSymbol  = DomainSettings.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test multiple fills per order
            buyer.OpenLimitOrder(0.05m, 1m, Buy, IoC: false);
            buyer.OpenLimitOrder(0.05m, 2m, Buy, IoC: false);
            buyer.OpenLimitOrder(0.05m, 3m, Buy, IoC: false);
            buyer.OpenLimitOrder(0.05m, 0.5m, Buy, IoC: false);
            Assert.IsTrue(seller.OpenLimitOrder(0.15m, 1m, Sell, IoC: true) == 0.3m, "Unexpected amount of tokens received");

            InitExchange();
            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            seller.OpenLimitOrder(0.05m, 1m, Sell, IoC: false);
            seller.OpenLimitOrder(0.05m, 2m, Sell, IoC: false);
            seller.OpenLimitOrder(0.05m, 3m, Sell, IoC: false);
            seller.OpenLimitOrder(0.05m, 0.5m, Sell, IoC: false);
            Assert.IsTrue(buyer.OpenLimitOrder(0.15m, 3m, Buy, IoC: true) == 0.2m, "Unexpected amount of tokens received");

            //TODO: test multiple IoC orders against each other on the same block!
        }
Beispiel #4
0
        public void TestFailedIOC()
        {
            InitExchange();

            var baseSymbol  = Nexus.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test order amount and prices below limit
            try
            {
                buyer.OpenLimitOrder(0, 0.5m, Buy, IoC: true);
                Assert.IsTrue(false, "Order should fail due to insufficient amount");
            }
            catch (Exception e) { }
            try
            {
                buyer.OpenLimitOrder(0.5m, 0, Buy, IoC: true);
                Assert.IsTrue(false, "Order should fail due to insufficient price");
            }
            catch (Exception e) { }

            Assert.IsTrue(buyer.OpenLimitOrder(0.123m, 0.3m, Buy, IoC: true) == 0, "Shouldn't have filled any part of the order");
            Assert.IsTrue(seller.OpenLimitOrder(0.123m, 0.3m, Sell, IoC: true) == 0, "Shouldn't have filled any part of the order");
        }
Beispiel #5
0
        public void TestMarketOrderTotalFillNoOrderbookWipe()
        {
            InitExchange();

            var baseSymbol  = DomainSettings.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            seller.OpenLimitOrder(0.1m, 1m, Sell);
            seller.OpenLimitOrder(0.1m, 2m, Sell);
            Assert.IsTrue(buyer.OpenMarketOrder(0.25m, Buy) == 0.175m, "");
        }
Beispiel #6
0
        public void TestMarketOrderCompleteFulfilment()
        {
            InitExchange();

            var baseSymbol  = Nexus.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            seller.OpenLimitOrder(0.1m, 1m, Sell);
            seller.OpenLimitOrder(0.1m, 2m, Sell);
            Assert.IsTrue(buyer.OpenMarketOrder(0.3m, Buy) == 0.2m, "");
        }
Beispiel #7
0
        public void TestIoCLimitOrderUnmatched()
        {
            InitExchange();

            var baseSymbol  = DomainSettings.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test unmatched IoC orders
            seller.OpenLimitOrder(0.01m, 0.5m, Sell);
            buyer.OpenLimitOrder(0.01m, 0.1m, Buy);
            Assert.IsTrue(buyer.OpenLimitOrder(0.123m, 0.3m, Buy, IoC: true) == 0, "Shouldn't have filled any part of the order");
            Assert.IsTrue(seller.OpenLimitOrder(0.123m, 0.3m, Sell, IoC: true) == 0, "Shouldn't have filled any part of the order");
        }
Beispiel #8
0
        public void TestIoCLimitOrderCompleteFulfilment()
        {
            InitExchange();

            var baseSymbol  = DomainSettings.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test fully matched IoC orders
            buyer.OpenLimitOrder(0.1m, 1m, Buy, IoC: false);
            Assert.IsTrue(seller.OpenLimitOrder(0.1m, 1m, Sell, IoC: true) == 0.1m, "Unexpected amount of tokens received");

            seller.OpenLimitOrder(0.1m, 1m, Sell, IoC: false);
            Assert.IsTrue(buyer.OpenLimitOrder(0.1m, 1m, Buy, IoC: true) == 0.1m, "Unexpected amount of tokens received");
        }
Beispiel #9
0
        public void TestLimitMinimumQuantity()
        {
            InitExchange();

            var baseSymbol  = Nexus.StakingTokenSymbol;
            var quoteSymbol = maxDivTokenSymbol;

            var buyer  = new ExchangeUser(baseSymbol, quoteSymbol);
            var seller = new ExchangeUser(baseSymbol, quoteSymbol);

            buyer.FundQuoteToken(quantity: 2m, fundFuel: true);
            seller.FundBaseToken(quantity: 2m, fundFuel: true);

            //-----------------------------------------
            //test order amount and prices at the limit

            var minimumBaseToken  = UnitConversion.ToDecimal(simulator.Nexus.RootChain.InvokeContract("exchange", "GetMinimumTokenQuantity", buyer.baseToken).AsNumber(), buyer.baseToken.Decimals);
            var minimumQuoteToken = UnitConversion.ToDecimal(simulator.Nexus.RootChain.InvokeContract("exchange", "GetMinimumTokenQuantity", buyer.quoteToken).AsNumber(), buyer.baseToken.Decimals);

            buyer.OpenLimitOrder(minimumBaseToken, minimumQuoteToken, Buy);
            seller.OpenLimitOrder(minimumBaseToken, minimumQuoteToken, Sell);
        }