public void GetNonExistentOrderUsingOrderId()
 {
     try
     {
         OrderInfo result = trade.GetOrder("BTCUSDT", 1546262163);
         Assert.IsNotNull(result);
     }
     catch (ErrorMessageException e)
     {
         if (e.Code != -2013)
         {
             Tools.OnThrowErrorMessageException(e);
         }
     }
 }
Ejemplo n.º 2
0
        public void MarketOrderTest()
        {
            try
            {
                NewOrderRequest request = new NewOrderRequest();
                request.SetMarketOrder("BTCUSDT", OrderSide.SELL, 0.06m);

                OrderInfo response = trade.PlaceOrder(request);

                Assert.Greater(response.OrderId, 0);
                Assert.AreEqual(0.06m, response.OrigQty);
                Assert.AreEqual(OrderSide.SELL, response.Side);
                Assert.AreEqual(PositionSide.BOTH, response.PositionSide);
                StringAssert.AreEqualIgnoringCase("BTCUSDT", response.Symbol);
                Assert.AreEqual(OrderType.MARKET, response.Type);

                response = trade.GetOrder("BTCUSDT", response.OrderId);
                Assert.AreEqual(OrderStatus.FILLED, response.Status);

                if (response.Status != OrderStatus.FILLED)
                {
                    // Cancel order
                    response = trade.CancelOrder("BTCUSDT", response.OrderId);

                    Assert.AreEqual(OrderStatus.CANCELED, response.Status);
                    Assert.Greater(response.OrderId, 0);
                    Assert.AreEqual(0.06m, response.OrigQty);
                    Assert.AreEqual(OrderSide.SELL, response.Side);
                    Assert.AreEqual(OrderType.MARKET, 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);
                }
            }
        }