示例#1
0
        public async Task GetOrderInfo_Should_RespondWithOrderInfo()
        {
            // arrange
            var expected = new HuobiOrder()
            {
                Quantity           = 0.1m,
                Type               = HuobiOrderType.LimitBuy,
                Id                 = 123,
                Price              = 0.2m,
                Symbol             = "BTCETH",
                State              = HuobiOrderState.Submitted,
                AccountId          = 1234,
                CreatedAt          = new DateTime(2018, 1, 1),
                Source             = "API",
                FilledQuantity     = 1.1m,
                FilledCashQuantity = 1.2m,
                FilledFees         = 1.3m
            };

            var client = TestHelpers.CreateAuthResponseClient(SerializeExpected(expected, true));

            // act
            var result = await client.GetOrderAsync(123);

            // assert
            Assert.AreEqual(true, result.Success);
            Assert.IsTrue(TestHelpers.AreEqual(expected, result.Data));
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        protected bool CancelOrder(HuobiOrder o)
        {
            bool traded = false;

            try
            {
                HuobiSimpleResult cancelResult = m_huobi.CancelOrder(m_market, o.id);
            }
            catch (HuobiException e)
            {
                // ignore order which have been filled, or cancelled
                if (e.m_error.code != 41 && e.m_error.code != 42)
                {
                    throw;
                }
                else
                {
                    if (e.m_error.code == 41)
                    {
                        // not found, so filled
                        m_renderer.AddMarker(o.type == HuobiOrderType.buy, true, o.order_price, UnixTime.ConvertToDateTime(o.order_time));

                        traded = true;
                    }

                    m_lastOpenOrders.RemoveAll(loo => loo.id == o.id);
                }
            }

            return(traded);
        }
示例#3
0
        public void SubscribeToOrderUpdates_Should_TriggerWithOrderUpdate()
        {
            // arrange
            var socket = new TestSocket();

            socket.CanConnect = true;
            var client = TestHelpers.CreateAuthenticatedSocketClient(socket);

            HuobiOrder result  = null;
            var        subTask = client.SubscribeToOrderUpdatesAsync(test => result = test);

            socket.InvokeMessage("{\"op\": \"auth\"}");
            Thread.Sleep(10);
            socket.InvokeMessage("{\"op\": \"sub\"}");
            var subResult = subTask.Result;

            var expected = new HuobiOrder()
            {
                Id               = 123,
                Amount           = 0.1m,
                Type             = HuobiOrderType.IOCBuy,
                Price            = 0.2m,
                Symbol           = "ethusdt",
                State            = HuobiOrderState.Canceled,
                Source           = "API",
                AccountId        = 1543,
                FilledAmount     = 0.3m,
                CreatedAt        = new DateTime(2018, 1, 1),
                FilledFees       = 0.4m,
                CanceledAt       = new DateTime(2018, 1, 2),
                FilledCashAmount = 0.5m,
                FinishedAt       = new DateTime(2018, 1, 3)
            };

            // act
            socket.InvokeMessage(SerializeExpectedAuth(expected));

            // assert
            Assert.IsTrue(subResult.Success);
            Assert.IsTrue(TestHelpers.AreEqual(expected, result));
        }
        public void QueryingOrderDetails_Should_ReturnOrderDetails()
        {
            // arrange
            var socket = new TestSocket();

            socket.CanConnect = true;
            var client = TestHelpers.CreateAuthenticatedSocketClient(socket);

            var expected = new HuobiOrder()
            {
                Id               = 123,
                Amount           = 0.1m,
                Type             = HuobiOrderType.IOCBuy,
                Price            = 0.2m,
                Symbol           = "ethusdt",
                State            = HuobiOrderState.Canceled,
                Source           = "API",
                AccountId        = 1543,
                FilledAmount     = 0.3m,
                CreatedAt        = new DateTime(2018, 1, 1),
                FilledFees       = 0.4m,
                CanceledAt       = new DateTime(2018, 1, 2),
                FilledCashAmount = 0.5m,
                FinishedAt       = new DateTime(2018, 1, 3)
            };

            // act
            var subTask = client.GetOrderDetailsAsync(123);

            socket.InvokeMessage("{\"op\": \"auth\"}");
            Thread.Sleep(10);
            socket.InvokeMessage(SerializeExpectedQuery(expected));
            var subResult = subTask.Result;

            // assert
            Assert.IsTrue(subResult.Success);
            Assert.IsTrue(TestHelpers.AreEqual(expected, subResult.Data));
        }