Пример #1
0
        public void CanCancelOrder()
        {
            var funding = GetBitcoinAddress().ToString();

            var newOrder = new NewOrder {
                AmountAsset = 100L,
                Funding = new[] {funding},
                Recipient = GetBitcoinAddress().ToString(),
                Ticker = "MTC:USD",
                Type = OrderType.Buy
            };

            var client = CreateAuthenticatedClient();
            var created = client.CreateOrder(newOrder);
            Assert.NotNull(created);
            Assert.AreEqual(100, created.AmountAsset);

            client.CancelOrder(created.Id);

            /** Wait for cancel **/
            var canceled = WaitForOrderState(client, created.Id, "Canceled");
            if (canceled == null) {
                throw new Exception("Order " + created.Id + " took to long to go to Canceled state");
            }
            Assert.AreEqual("explicit_cancel", canceled.CancelReason);
            Assert.AreEqual("Canceled", canceled.Status);
        }
Пример #2
0
        public void CanProcessOrder()
        {
            var addr = GetBitcoinAddress().ToString();
            var newOrder = new NewOrder {
                AmountAsset = 100L,
                Funding = new []{ addr },
                Recipient = addr,
                Ticker = "MTC:USD",
                Type = OrderType.Buy
            };

            var client = CreateAuthenticatedClient();

            var created = client.CreateOrder(newOrder);
            Assert.NotNull(created);
            Assert.AreEqual(100L, created.AmountAsset);

            var orderToSign = WaitForOrderState(client, created.Id, "Signing");
            if (orderToSign == null) {
                throw new Exception("Order " + created.Id + " took to long to go to Signing state");
            }

            /** Signing and submit **/
            var rawTx = new RawTransaction {
                Raw = GetHexSignedTransaction(orderToSign.Transaction)
            };

            client.SubmitSignedOrder(orderToSign.Id, rawTx);

            /** Wait for broadcasting **/
            var unconfirmed = WaitForOrderState(client, created.Id, "Unconfirmed");
            if (unconfirmed == null) {
                throw new Exception("Order " + created.Id + " took to long to go to Unconfirmed state");
            }

            Assert.AreEqual(100, unconfirmed.AmountAsset);

            /** Try to delete broadcasting order **/
            try {
                client.CancelOrder(unconfirmed.Id);
                throw new Exception("A MetacoClientException was expected!");
            } catch (MetacoClientException e) {
                Assert.AreEqual(ErrorType.OrderNotCancellable, e.ErrorType);
            }

            /** Fetch all the orders **/
            var orders = client.GetOrders();

            if (orders.Orders.All(x => x.Id != created.Id))
            {
                throw new Exception("Order " + created.Id + " is not present in orders list");
            }
        }
Пример #3
0
        /// <summary>
        /// Create an order using the provided parameters
        /// This order will be processed in our system
        /// It will require your signature later when the trade state will be Signing
        /// </summary>
        ///<param name="createOrder">The order to be created</param>
        ///<returns>The history object</returns>
        /// <exception cref="MetacoClientException"></exception>
        /// <see cref="http://docs.metaco.apiary.io/#reference/orders/orders-management/request-an-order">Online Documentation</see>
        /// <remarks>Requires Authentication</remarks>
        public Order CreateOrder(NewOrder createOrder)
        {
            if (createOrder == null)
                throw new ArgumentNullException("createOrder");

            return _httpClient.Post<Order, NewOrder>("orders", createOrder);
        }