Exemplo n.º 1
0
        /// <summary>
        /// Cancel a previously placed 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 = tradeClient.MergeParamsAndArgs(args);

                var _json_value = await tradeClient.CallApiDelete1Async($"/orders/{order_id}", _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 <JValue>(_json_value.Content);
                    if (_json_data != null)
                    {
                        var _order_id = _json_data.Value <string>();

                        var _order = new GMyOrderItem
                        {
                            symbol      = _market.result.symbol,
                            orderId     = _order_id,
                            orderType   = OrderType.Limit,
                            orderStatus = OrderStatus.Canceled,
                            sideType    = sideType,
                            quantity    = quantity,
                            price       = price,
                            amount      = quantity * price,
                            //fee = quantity * price * publicApi.ExchangeInfo.Fees.trading.maker,
                            timestamp = CUnixTime.NowMilli
                        };

                        _result.result = _order;
                    }
                    else
                    {
                        _json_result.SetFailure();
                    }
                }

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

            return(_result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// With best effort, cancel open orders. The response is a list of ids of the canceled 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("product_id", _market.result.symbol);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiDelete1Async($"/orders", _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 <JArray>(_json_value.Content);
                    {
                        foreach (var _o in _json_data)
                        {
                            var _order = new GMyOrderItem
                            {
                                orderId   = _o.Value <string>(),
                                symbol    = _market.result.symbol,
                                timestamp = CUnixTime.NowMilli,

                                orderStatus = OrderStatus.Canceled,
                                orderType   = OrderType.Limit
                            };

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

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

            return(_result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// With best effort, cancel all open orders. The response is a list of ids of the canceled orders.
        /// </summary>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async Task <MyOrders> CancelAllOrders(Dictionary <string, object> args = null)
        {
            var _result = new MyOrders();

            var _markets = await publicApi.LoadMarkets();

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

                var _params = tradeClient.MergeParamsAndArgs(args);

                // symbol이 required 인지 아닌지 document에 안나와있음. required면 cancelAllOrders 제공안함.
                var _json_value = await tradeClient.CallApiDelete1Async($"/orders", _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 <JArray>(_json_value.Content);
                    {
                        foreach (var _o in _json_data)
                        {
                            var _order = new GMyOrderItem
                            {
                                orderId = _o.Value <string>(),

                                timestamp = CUnixTime.NowMilli,

                                orderStatus = OrderStatus.Canceled,
                                orderType   = OrderType.Limit
                            };

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

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

            return(_result);
        }