Exemple #1
0
        /// <summary>
        /// Cancel Open Orders
        /// </summary>
        /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param>
        /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param>
        /// <param name="order_ids"></param>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async Task <MyOrders> CancelOrders(string base_name, string quote_name, string[] order_ids, Dictionary <string, object> args = null)
        {
            var _result = new MyOrders(base_name, quote_name);

            var _market = await publicApi.LoadMarket(_result.marketId);

            if (_market.success == true)
            {
                tradeClient.ExchangeInfo.ApiCallWait(TradeType.Trade);

                var _params = new Dictionary <string, object>();
                {
                    _params.Add("currency_pair", _market.result.symbol);
                    _params.Add("id", new CArgument {
                        isArray = true, value = order_ids
                    });

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/user/orders/cancel", _params);

#if DEBUG
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _json_data = tradeClient.DeserializeObject <List <KCancelOrderItem> >(_json_value.Content);
                    {
                        foreach (var _o in _json_data)
                        {
                            var _order = new KMyOrderItem
                            {
                                orderId   = _o.orderId,
                                symbol    = _market.result.symbol,
                                timestamp = CUnixTime.NowMilli,

                                orderStatus = _o.status == "success" ? OrderStatus.Canceled : OrderStatus.Unknown,
                                orderType   = OrderType.Limit
                            };

                            _result.result.Add(_order);
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Exemple #2
0
        /// <summary>
        /// Cancel Open Order
        /// </summary>
        /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param>
        /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param>
        /// <param name="order_id">Order number registered for sale or purchase</param>
        /// <param name="quantity">amount of coin</param>
        /// <param name="price">price of coin</param>
        /// <param name="sideType">type of buy(bid) or sell(ask)</param>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async Task <MyOrder> CancelOrder(string base_name, string quote_name, string order_id, decimal quantity, decimal price, SideType sideType, Dictionary <string, object> args = null)
        {
            var _result = new MyOrder(base_name, quote_name);

            var _market = await publicApi.LoadMarket(_result.marketId);

            if (_market.success == true)
            {
                tradeClient.ExchangeInfo.ApiCallWait(TradeType.Trade);

                var _params = new Dictionary <string, object>();
                {
                    _params.Add("currency_pair", _market.result.symbol);
                    _params.Add("id", order_id);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/user/orders/cancel", _params);

#if DEBUG
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _json_data = tradeClient.DeserializeObject <List <KCancelOrderItem> >(_json_value.Content);
                    {
                        var _cancel_order = _json_data.FirstOrDefault();
                        if (_cancel_order != null)
                        {
                            var _order = new KMyOrderItem
                            {
                                orderId   = _cancel_order.orderId,
                                symbol    = _market.result.symbol,
                                timestamp = CUnixTime.NowMilli,

                                orderStatus = OrderStatus.Canceled,
                                orderType   = OrderType.Limit,
                                sideType    = sideType,

                                quantity = quantity,
                                price    = price,
                                amount   = quantity * price
                            };

                            _result.result = _order;

                            var _success = _cancel_order.status == "success";
                            if (_success == false)
                            {
                                _json_result.SetFailure(_cancel_order.status, ErrorCode.OrderNotFound);
                            }
                        }
                        else
                        {
                            _json_result.SetFailure();
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }