示例#1
0
        /// <summary>
        /// Get all open orders on a symbol. Careful when accessing this with no symbol.
        /// </summary>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async ValueTask <MyOrders> FetchAllOpenOrdersAsync(Dictionary <string, object> args = null)
        {
            var _result = new MyOrders();

            var _markets = await publicApi.LoadMarketsAsync();

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

                var _params = new Dictionary <string, object>();
                {
                    _params.Add("reverse", true);
                    _params.Add("filter", new CArgument
                    {
                        isJson = true,
                        value  = new Dictionary <string, object>
                        {
                            { "open", true }
                        }
                    });

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiGet1Async("/api/v1/order", _params);

#if RAWJSON
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _orders = tradeClient.DeserializeObject <List <BMyOrderItem> >(_json_value.Content);
                    foreach (var _o in _orders.Where(o => OrderStatusConverter.IsAlive(o.orderStatus) == true))
                    {
                        //var _multiplier = publicApi.publicClient.ExchangeInfo.GetAmountMultiplier(_o.symbol, 1.0m);

                        _o.makerType = MakerType.Maker;

                        _o.amount = _o.price * _o.quantity;
                        _o.filled = Math.Max(_o.quantity - _o.remaining, 0);
                        _o.cost   = _o.price * _o.filled;

                        _result.result.Add(_o);
                    }
                }

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

            return(_result);
        }
示例#2
0
        /// <summary>
        /// Get all open orders on a symbol. Careful when accessing this with no symbol.
        /// </summary>
        /// <param name="count">Number of results to fetch.</param>
        /// <param name="start">Starting point for results.</param>
        /// <returns></returns>
        public async ValueTask <MyOrders> GetAllOrders(long count, long start = 0)
        {
            var _result = new MyOrders();

            var _params = new Dictionary <string, object>();
            {
                if (count > 0)
                {
                    _params.Add("count", count);
                }
                _params.Add("start", start);
                _params.Add("reverse", true);
                _params.Add("filter", new CArgument
                {
                    isJson = true,
                    value  = new Dictionary <string, object>
                    {
                        { "open", true }
                    }
                });
            }

            var _response = await privateClient.CallApiGet2Async("/api/v1/order", _params);

            if (_response != null)
            {
#if RAWJSON
                _result.rawJson = _response.Content;
#endif
                if (_response.IsSuccessful == true)
                {
                    var _orders = privateClient.DeserializeObject <List <BMyOrderItem> >(_response.Content);
                    if (_orders != null)
                    {
                        foreach (var _o in _orders.Where(o => OrderStatusConverter.IsAlive(o.orderStatus) == true))
                        {
                            _o.makerType = MakerType.Maker;

                            _o.amount = _o.price * _o.quantity;
                            _o.filled = Math.Max(_o.quantity - _o.remaining, 0);
                            _o.cost   = _o.price * _o.filled;
                        }

                        _result.result = _orders.ToList <IMyOrderItem>();
                        _result.SetSuccess();
                    }
                }
                else
                {
                    var _message = privateClient.GetResponseMessage(_response);
                    _result.SetFailure(_message.message);
                }
            }

            return(_result);
        }
示例#3
0
        /// <summary>
        /// Get 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="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async ValueTask <MyOrders> FetchOpenOrdersAsync(string base_name, string quote_name, 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("status", "open");
                    _params.Add("instrument", _market.result.symbol);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiGet1Async($"/v1/wallets/{__wallet_id}/orders", _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 <List <TMyOrderItem> >(_json_value.Content);
                    {
                        var _orders = _json_data
                                      .Where(o => OrderStatusConverter.IsAlive(o.orderStatus) == true)
                                      .OrderByDescending(o => o.timestamp);

                        foreach (var _o in _orders)
                        {
                            _o.amount = _o.price * _o.quantity;
                            _result.result.Add(_o);
                        }
                    }
                }

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

            return(_result);
        }
示例#4
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="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async ValueTask <MyOrders> FetchOpenOrders(string base_name, string quote_name, 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>();
                {
                    var _since  = 0; // CUnixTime.ConvertToUnixTimeMilli(CUnixTime.UtcNow.AddYears(-1));
                    var _limits = 100;

                    _params.Add("currency", _market.result.symbol);
                    _params.Add("after", _since);
                    _params.Add("count", _limits);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/info/orders", _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 <BMyOpenOrders>(_json_value.Content);
                    if (_json_data.success == true)
                    {
                        foreach (var _o in _json_data.result)
                        {
                            if (OrderStatusConverter.IsAlive(_o.orderStatus) == false)
                            {
                                continue;
                            }

                            _o.symbol = _market.result.symbol;

                            _o.orderType = OrderType.Limit;
                            _o.makerType = MakerType.Maker;

                            _o.filled = _o.quantity - _o.remaining;
                            _o.amount = _o.quantity * _o.price;

                            _result.result.Add(_o);
                        }
                    }
                    else
                    {
                        _json_result.SetResult(_json_data);
                    }
                }

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

            return(_result);
        }