public void LimitOrderTest() { try { // Place order NewOrderRequest request = new NewOrderRequest(); request.SetLimitOrder("BTCUSDT", OrderSide.BUY, 0.02m, 10000); OrderInfo response = trade.PlaceOrder(request); Assert.Greater(response.OrderId, 0); Assert.AreEqual(0.02m, response.OrigQty); Assert.AreEqual(10000, response.Price); Assert.AreEqual(OrderSide.BUY, response.Side); //Assert.AreEqual(PositionSide.LONG, response.PositionSide); StringAssert.AreEqualIgnoringCase("BTCUSDT", response.Symbol); Assert.AreEqual(OrderType.LIMIT, response.Type); // Cancel order response = trade.CancelOrder("BTCUSDT", response.OrderId); Assert.AreEqual(OrderStatus.CANCELED, response.Status); Assert.AreEqual(0.02m, response.OrigQty); Assert.AreEqual(10000, response.Price); Assert.AreEqual(OrderType.LIMIT, response.Type); } catch (ErrorMessageException e) { Tools.OnThrowErrorMessageException(e); } }
public void TwoLimitOrderTest() { List <NewOrderRequest> orders = new List <NewOrderRequest>(); List <ValidOrErrorResponse <OrderInfo> > responseNew; bool[] filled = new bool[2]; orders.Add(new NewOrderRequest().SetLimitOrder("BTCUSDT", OrderSide.BUY, 0.02m, 8000)); orders.Add(new NewOrderRequest().SetLimitOrder("BTCUSDT", OrderSide.SELL, 0.01m, 12000)); //Add new orders. try { responseNew = trade.PlaceMultipleOrders(orders); }catch (ErrorMessageException e) { Tools.OnThrowErrorMessageException(e); return; } for (int i = 0; i < responseNew.Count; i++) { if (responseNew[i].IsValid) { Assert.AreNotEqual(OrderStatus.CANCELED, responseNew[i].ValidResponse.Status); if (responseNew[i].ValidResponse.Status == OrderStatus.FILLED) { filled[i] = true; } } else { Assert.Fail("Order fail response code " + responseNew[i].ErrorResponse.Code + ": " + responseNew[i].ErrorResponse.Msg); } } /*for(int i = 0; i < responseNew.Count; i++) * { * Assert.AreEqual(true, filled[i], i.ToString()); * }*/ /*if (responseNew[0].IsValid) * trade.CancelOrder("BTCUSDT", responseNew[0].ValidResponse.OrderId);*/ //Get orders and check status. List <OrderInfo> responseGet = new List <OrderInfo>(); for (int i = 0; i < responseNew.Count; i++) { try { if (responseNew[i].IsValid) { if (responseNew[i].ValidResponse.Status != OrderStatus.FILLED && responseNew[i].ValidResponse.Status != OrderStatus.EXPIRED && responseNew[i].ValidResponse.Status != OrderStatus.CANCELED) { responseGet.Add(trade.GetOrder("BTCUSDT", responseNew[i].ValidResponse.OrderId)); } else { Assert.Fail("Order fail response code " + responseNew[i].ErrorResponse.Code + ": " + responseNew[i].ErrorResponse.Msg); } } } catch (ErrorMessageException) { } } //Delete orders. for (int i = 0; i < responseGet.Count; i++) { try { trade.CancelOrder("BTCUSDT", responseGet[i].OrderId); }catch (ErrorMessageException e) { Tools.OnThrowErrorMessageException(e); } } }