예제 #1
0
        /// <summary>
        /// 지정가 주문
        /// </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="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> CreateLimitOrderAsync(string base_name, string quote_name, decimal quantity, decimal price, SideType sideType, Dictionary <string, object> args = null)
        {
            var _result = new MyOrder(base_name, quote_name);

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

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

                var _buy_sell = sideType == SideType.Bid ? "buy" : "sell";

                var _params = new Dictionary <string, object>();
                {
                    _params.Add("symbol", _market.result.symbol);       // token_krw (ex. btc_krw)
                    _params.Add("type", _buy_sell);                     // buy,sell
                    _params.Add("price", price);                        // 범위: >= 0 ,<=1000000
                    _params.Add("amount", quantity);                    // 범위:BTC수량 >=0.01,LTC수량>=0.1,ETH수량>=0.01 등

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/v1/trade.do", _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 <OPlaceOrder>(_json_value.Content);
                    {
                        var _order = new OPlaceOrderItem
                        {
                            orderId     = _json_data.result.orderId,
                            symbol      = _market.result.symbol,
                            orderType   = OrderType.Limit,
                            orderStatus = OrderStatus.Open,
                            sideType    = sideType,
                            quantity    = quantity,
                            price       = price,
                            amount      = quantity * price,
                            //fee = quantity * price * publicApi.ExchangeInfo.Fees.trading.maker,
                            timestamp = CUnixTime.NowMilli
                        };

                        _result.result = _order;
                    }
                }

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

            return(_result);
        }
예제 #2
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 ValueTask <MyOrders> CancelOrdersAsync(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.LoadMarketAsync(_result.marketId);

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

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

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/v1/cancel_order.do", _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 <OCancelOrders>(_json_value.Content);
                    foreach (var _o in _json_data.result)
                    {
                        var _order = new OPlaceOrderItem
                        {
                            symbol      = _market.result.symbol,
                            orderId     = _o.orderId,
                            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,
                            success   = _o.success
                        };

                        _result.result.Add(_order);
                    }
                }

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

            return(_result);
        }
예제 #3
0
        /// <summary>
        /// 주문 취소
        /// </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> CancelOrderAsync(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.LoadMarketAsync(_result.marketId);

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

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

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/v1/cancel_order.do", _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 <OCancelOrders>(_json_value.Content);

                    var _cancel = _json_data.result.FirstOrDefault();
                    if (_cancel != null && _cancel.success == true)
                    {
                        var _order = new OPlaceOrderItem
                        {
                            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,
                            success   = true
                        };

                        _result.result = _order;
                    }
                    else
                    {
                        _json_result.SetFailure(errorCode: ErrorCode.OrderNotFound);
                    }
                }

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

            return(_result);
        }