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(); }
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); }
public void OnMessageTickerTest() { string json = _tickerData; _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json)); var actual = _unit.Ticks.First(); Assert.AreEqual("BTCUSD", actual.Symbol.Value); Assert.AreEqual(4388.005m, actual.Price); Assert.AreEqual(4388m, actual.BidPrice); Assert.AreEqual(4388.01m, actual.AskPrice); actual = _unit.Ticks.Last(); Assert.AreEqual("BTCUSD", actual.Symbol.Value); Assert.AreEqual(4388.01m, actual.Price); Assert.AreEqual(0.03m, actual.Quantity); }
public void ErrorTest() { string actual = null; // subscribe to invalid symbol const string expected = "[\"BTC-LTC\"]"; _wss.Setup(w => w.Send(It.IsAny <string>())).Callback <string>(c => actual = c); _unit.Subscribe(new[] { Symbol.Create("BTCLTC", SecurityType.Crypto, Market.GDAX) }); StringAssert.Contains(expected, actual); BrokerageMessageType messageType = 0; _unit.Message += (sender, e) => { messageType = e.Type; }; const string json = "{\"type\":\"error\",\"message\":\"Failed to subscribe\",\"reason\":\"Invalid product ID provided\"}"; _unit.OnMessage(_unit, GDAXTestsHelpers.GetArgs(json)); Assert.AreEqual(BrokerageMessageType.Warning, messageType); }
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); }