public async Task <TradesResponse> GetTradesAsync(long blockHeight = 0, string symbol = "", string address = "", OrderSideQuery side = OrderSideQuery.All, string buyerOrderId = "", string sellerOrderId = "",
                                                          long limit       = 500, long offset = 0, int start       = 0, int end = 0, bool totalRequired = false)
        {
            var br = await Task.Run(() =>
            {
                return(GetTrades(blockHeight, symbol, address, side, buyerOrderId, sellerOrderId,
                                 limit, offset, start, end, totalRequired));
            });

            return(br);
        }
        public async Task <OrdersResponse> GetOrdersClosedAsync(string address, string symbol = "", OrderStatusQuery status = OrderStatusQuery.All, OrderSideQuery side = OrderSideQuery.All, int limit = 500,
                                                                int offset = 0, bool totalRequired = false, long start = 0, long end = 0)
        {
            var br = await Task <OrdersResponse> .Run(() =>
            {
                return(GetOrdersClosed(address, symbol, status, side, limit, offset, totalRequired, start, end));
            });

            return(br);
        }
        /// <summary>
        /// Description: Gets a list of historical trades.
        /// Query Window: Default query window is latest 7 days; The maximum start - end query window is 3 months.
        /// </summary>
        /// <returns></returns>
        public TradesResponse GetTrades(long blockHeight = 0, string symbol = "", string address = "", OrderSideQuery side = OrderSideQuery.All, string buyerOrderId = "", string sellerOrderId = "",
                                        long limit       = 500, long offset = 0, int start       = 0, int end = 0, bool totalRequired = false)
        {
            //Call specific settings
            string        urlPattern    = "{0}/trades";
            string        url           = string.Format(urlPattern, _env.HttpsApiAddress);
            StringBuilder sbQueyrFilter = new StringBuilder();

            if (side != OrderSideQuery.All)
            {
                sbQueyrFilter.AppendFormat("&side={0}", (int)side);
            }
            if (!string.IsNullOrWhiteSpace(address))
            {
                sbQueyrFilter.AppendFormat("&address={0}", address);
            }
            if (!string.IsNullOrWhiteSpace(buyerOrderId))
            {
                sbQueyrFilter.AppendFormat("&buyerOrderId={0}", buyerOrderId);
            }
            if (!string.IsNullOrWhiteSpace(sellerOrderId))
            {
                sbQueyrFilter.AppendFormat("&sellerOrderId={0}", sellerOrderId);
            }
            if (blockHeight > 0)
            {
                sbQueyrFilter.AppendFormat("&height={0}", blockHeight);
            }
            if (end > 0)
            {
                sbQueyrFilter.AppendFormat("&end={0}", end);
            }
            if (limit != 500)
            {
                sbQueyrFilter.AppendFormat("&limit={0}", limit);
            }
            if (offset > 0)
            {
                sbQueyrFilter.AppendFormat("&offset={0}", offset);
            }
            if (start > 0)
            {
                sbQueyrFilter.AppendFormat("&start={0}", start);
            }
            if (!string.IsNullOrWhiteSpace(symbol))
            {
                sbQueyrFilter.AppendFormat("&symbol={0}", symbol);
            }
            if (totalRequired)
            {
                sbQueyrFilter.Append("&total=1");
            }



            if (sbQueyrFilter.Length > 0)
            {
                //reset first parameter start according to url params
                sbQueyrFilter[0] = '?';
                url = string.Format("{0}{1}", url, sbQueyrFilter);
            }

            int callsPerSecondAllowed = 5;

            //Generic items for calls
            var response = GetStringResponse(url, urlPattern, callsPerSecondAllowed);

            //Call specific processing of returned values
            var ret = JsonConvert.DeserializeObject <TradesResponse>(response);

            return(ret);
        }
        /// <summary>
        /// Description: Gets closed (filled and cancelled) orders for a given address.
        /// Query Window: Default query window is latest 7 days; The maximum start - end query window is 3 months.
        /// </summary>
        /// <returns></returns>
        public OrdersResponse GetOrdersClosed(string address, string symbol = "", OrderStatusQuery status = OrderStatusQuery.All, OrderSideQuery side = OrderSideQuery.All, int limit = 500,
                                              int offset = 0, bool totalRequired = false, long start = 0, long end = 0)
        {
            //Call specific settings
            string        urlPattern    = "{0}/orders/closed?address={1}";
            string        url           = string.Format(urlPattern, _env.HttpsApiAddress, address);
            StringBuilder sbQueyrFilter = new StringBuilder();

            if (end > 0)
            {
                sbQueyrFilter.AppendFormat("&end={0}", end);
            }
            if (limit != 500)
            {
                sbQueyrFilter.AppendFormat("&limit={0}", limit);
            }
            if (offset > 0)
            {
                sbQueyrFilter.AppendFormat("&offset={0}", offset);
            }
            if (start > 0)
            {
                sbQueyrFilter.AppendFormat("&start={0}", start);
            }
            if (status != OrderStatusQuery.All)
            {
                sbQueyrFilter.AppendFormat("&status={0}", status.ToString());
            }
            if (!string.IsNullOrWhiteSpace(symbol))
            {
                sbQueyrFilter.AppendFormat("&symbol={0}", symbol);
            }
            if (totalRequired)
            {
                sbQueyrFilter.Append("&total=1");
            }

            if (sbQueyrFilter.Length > 0)
            {
                url = string.Format("{0}{1}", url, sbQueyrFilter);
            }
            int callsPerSecondAllowed = 5;

            //Generic items for calls
            var response = GetStringResponse(url, urlPattern, callsPerSecondAllowed);

            //Call specific processing of returned values
            var ret = JsonConvert.DeserializeObject <OrdersResponse>(response);

            return(ret);
        }