示例#1
0
文件: tradeApi.cs 项目: lkh/ccxt.net
        /// <summary>
        /// Order_V2 - Cancel 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 ValueTask <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", _market.result.symbol);
                    _params.Add("order_id", order_id);
                    _params.Add("price", price);
                    _params.Add("qty", quantity);
                    _params.Add("is_ask", sideType == SideType.Ask ? 1 : 0);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/v2/order/cancel", _params);

#if RAWJSON
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    //var _json_data = tradeClient.DeserializeObject<JToken>(_json_value.Content);
                    {
                        var _order = new MyOrderItem
                        {
                            orderId  = order_id.ToUpper(),
                            symbol   = _market.result.symbol,
                            sideType = sideType,
                            quantity = quantity,
                            price    = price,
                            amount   = quantity * price
                        };

                        _result.result = _order;
                    }
                }

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

            return(_result);
        }
示例#2
0
        /// <summary>
        /// Cancels an order you have placed in a given market.
        /// </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 ValueTask <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("command", "cancelOrder");
                    _params.Add("currencyPair", _market.result.symbol);
                    _params.Add("orderNumber", order_id);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("", _params);

#if RAWJSON
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _json_data = tradeClient.DeserializeObject <JToken>(_json_value.Content);
                    {
                        var _order = new MyOrderItem
                        {
                            orderId = order_id,
                            symbol  = _market.result.symbol,

                            timestamp   = CUnixTime.NowMilli,
                            orderStatus = OrderStatus.Canceled,
                            sideType    = sideType,

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

                        _result.result = _order;

                        var _status = _json_data["success"].Value <int>() == 1;
                        if (_status == false)
                        {
                            _json_result.SetFailure();
                        }
                    }
                }

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

            return(_result);
        }