Example #1
0
        public void OnMessageFillTest(decimal expectedQuantity)
        {
            string json = _matchData;
            string id   = "132fb6ae-456b-4654-b4e0-d681ac05cea1";

            //not our order
            if (expectedQuantity == 99)
            {
                var message = JsonConvert.DeserializeObject <Matched>(json);
                message.UserId = null;
                json           = JsonConvert.SerializeObject(message);
            }

            decimal orderQuantity = 6.1m;

            GDAXTestsHelpers.AddOrder(_unit, 1, id, orderQuantity);
            ManualResetEvent raised = new ManualResetEvent(false);

            decimal actualFee      = 0;
            decimal actualQuantity = 0;

            _unit.OrderStatusChanged += (s, e) =>
            {
                Assert.AreEqual("BTCUSD", e.Symbol.Value);
                actualFee += e.OrderFee.Value.Amount;
                Assert.AreEqual(Currencies.USD, e.OrderFee.Value.Currency);
                actualQuantity += e.AbsoluteFillQuantity;

                Assert.IsTrue(actualQuantity != orderQuantity);
                Assert.AreEqual(OrderStatus.PartiallyFilled, e.Status);
                Assert.AreEqual(expectedQuantity, e.FillQuantity);
                // fill quantity = 5.23512
                // fill price = 400.23
                // partial order fee = (400.23 * 5.23512 * 0.003) = 6.2857562328
                Assert.AreEqual(6.2857562328m, actualFee);
                raised.Set();
            };

            _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json));

            // not our order, market order is completed even if not totally filled
            var msg = JsonConvert.DeserializeObject <Matched>(json);

            msg.UserId = null;
            json       = JsonConvert.SerializeObject(msg);
            _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json));

            //if not our order should get no event
            Assert.AreEqual(raised.WaitOne(1000), expectedQuantity != 99);
            raised.DisposeSafely();
        }
Example #2
0
        public void OnMessageFillTest(decimal expectedQuantity)
        {
            string json = _matchData;
            string id   = "132fb6ae-456b-4654-b4e0-d681ac05cea1";

            //not our order
            if (expectedQuantity == 99)
            {
                json = json.Replace(id, Guid.NewGuid().ToString());
            }

            decimal orderQuantity = 6.1m;

            GDAXTestsHelpers.AddOrder(_unit, 1, id, orderQuantity);
            ManualResetEvent raised = new ManualResetEvent(false);

            decimal actualFee      = 0;
            decimal actualQuantity = 0;

            _unit.OrderStatusChanged += (s, e) =>
            {
                Assert.AreEqual("BTCUSD", e.Symbol.Value);
                actualFee      += e.OrderFee;
                actualQuantity += e.AbsoluteFillQuantity;

                Assert.IsTrue(actualQuantity != orderQuantity);
                Assert.AreEqual(OrderStatus.Filled, e.Status);
                Assert.AreEqual(expectedQuantity, e.FillQuantity);
                // fill quantity = 5.23512
                // fill price = 400.23
                // partial order fee = (400.23 * 5.23512 * 0.003) = 6.2857562328
                Assert.AreEqual(6.2857562328m, actualFee);
                raised.Set();
            };

            _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json));

            // not our order, market order is completed even if not totally filled
            json = json.Replace(id, Guid.NewGuid().ToString());
            _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json));

            //if not our order should get no event
            Assert.AreEqual(raised.WaitOne(1000), expectedQuantity != 99);
        }
Example #3
0
        public void OnMessageFillTest(decimal expectedQuantity)
        {
            string json = _matchData;
            string id   = "132fb6ae-456b-4654-b4e0-d681ac05cea1";

            //not our order
            if (expectedQuantity == 99)
            {
                json = json.Replace(id, Guid.NewGuid().ToString());
            }

            decimal orderQuantity = 6.1m;

            GDAXTestsHelpers.AddOrder(_unit, 1, id, orderQuantity);
            ManualResetEvent raised = new ManualResetEvent(false);

            decimal actualFee      = 0;
            decimal actualQuantity = 0;

            _unit.OrderStatusChanged += (s, e) =>
            {
                Assert.AreEqual("BTCUSD", e.Symbol.Value);
                actualFee      += e.OrderFee;
                actualQuantity += e.AbsoluteFillQuantity;

                Assert.AreEqual(actualQuantity != orderQuantity ? Orders.OrderStatus.PartiallyFilled : Orders.OrderStatus.Filled, e.Status);
                Assert.AreEqual(expectedQuantity, e.FillQuantity);
                // order fees are pro-rated for partial fills
                // total order fee = 0.01
                // partial order fee = (0.01 * 5.23512 / 6.1) = 0.0085821639344262295081967213
                Assert.AreEqual(0.00858216m, Math.Round(actualFee, 8));
                raised.Set();
            };

            _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json));

            //if not our order should get no event
            Assert.AreEqual(raised.WaitOne(1000), expectedQuantity != 99);
        }