/// <summary>
        ///		<para>
        ///			Gets the historic rates for a product. Rates are returned in grouped buckets based on requested granularity.
        ///		</para>
        ///		<para>
        ///			The maximum number of data points for a single request is 200 candles. If your selection of start/end time and granularity
        ///			will result in more than 200 data points, your request will be rejected. If you wish to retrieve fine granularity data over
        ///			a larger time range, you will need to make multiple requests with new start/end ranges.
        ///		</para>
        /// </summary>
        /// <remarks>
        /// Historical rate data may be incomplete. No data is published for intervals where there are no ticks.
        /// Historical rates should not be polled frequently. If you need real-time information, use the trade and book endpoints along with the websocket feed.
        /// </remarks>
        /// <param name="productId">The currency pair.</param>
        /// <param name="start">Start time in ISO 8601.</param>
        /// <param name="end">End time in ISO 8601.</param>
        /// <param name="granularity">Desired timeslice in seconds.</param>
        /// <returns></returns>
        public static async Task <IList <HistoricRate> > GetHistoricRatesAsync(this GdaxClient client, String productId, DateTime?start = null, DateTime?end = null, Int32?granularity = null)
        {
            Check.NotNull(client, nameof(client));
            Check.NotNullOrWhiteSpace(productId, nameof(productId));

            var request = new GdaxRequestBuilder($"/products/{productId}/candles")
                          .AddParameterIfNotNull("start", start?.ToString("o"))
                          .AddParameterIfNotNull("end", end?.ToString("o"))
                          .AddParameterIfNotNull("granularity", granularity?.ToString())
                          .Build();

            var rates = (await client.GetResponseAsync <IList <Decimal[]> >(request).ConfigureAwait(false)).Value;

            var results = new List <HistoricRate>();

            foreach (var rate in rates)
            {
                results.Add(new HistoricRate
                {
                    Time   = rate[0],
                    Low    = rate[1],
                    High   = rate[2],
                    Open   = rate[3],
                    Close  = rate[4],
                    Volume = rate[5],
                });
            }

            return(results);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a list of available currency pairs for trading.
        /// </summary>
        /// <returns></returns>
        public static async Task <IList <Product> > GetProductsAsync(this GdaxClient client)
        {
            Check.NotNull(client, nameof(client));

            var request = new GdaxRequestBuilder("/products")
                          .Build();

            return((await client.GetResponseAsync <IList <Product> >(request).ConfigureAwait(false)).Value);
        }
Ejemplo n.º 3
0
        public static async Task <Time> GetServerTimeAsync(this GdaxClient client)
        {
            Check.NotNull(client, nameof(client));

            var request = new GdaxRequestBuilder("/time")
                          .Build();

            return((await client.GetResponseAsync <Time>(request).ConfigureAwait(false)).Value);
        }
Ejemplo n.º 4
0
        public static async Task <OrderBook> GetOrderBookAsync(this GdaxClient client, String productId, OrderBookLevel level = OrderBookLevel.Level1)
        {
            Check.NotNull(client, nameof(client));
            Check.NotNullOrWhiteSpace(productId, nameof(productId));

            var request = new GdaxRequestBuilder($"/products/{productId}/book")
                          .AddParameterIfNotNull("level", ((Int32)level).ToString())
                          .Build();

            return((await client.GetResponseAsync <OrderBook>(request).ConfigureAwait(false)).Value);
        }
Ejemplo n.º 5
0
        public static async Task <PaginatedResult <Ledger> > GetAccountHistoryAsync(this GdaxClient client, Guid accountId, PaginationOptions paging = null)
        {
            Check.NotNull(client, nameof(client));
            Check.NotEmpty(accountId, nameof(accountId));

            var request = new GdaxRequestBuilder($"/accounts/{accountId}/ledger")
                          .SetPageOptions(paging)
                          .Build();

            var response = await client.GetResponseAsync <IList <Ledger> >(request).ConfigureAwait(false);

            return(new PaginatedResult <Ledger>(response, paging));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///		<para>
        ///			Get a list of recent fills.
        ///		</para>
        ///		<para>
        ///			Fees are recorded in two stages. Immediately after the matching engine completes a match, the fill is inserted
        ///			into the datastore. Once the fill is recorded, a settlement process will settle the fill and credit both trading
        ///			counterparties.
        ///		</para>
        /// </summary>
        /// <remarks>
        /// Fills are returned sorted by descending trade_id from the largest trade_id to the smallest trade_id.
        /// </remarks>
        /// <param name="orderId">Limit list of fills to this order.</param>
        /// <param name="productId">Limit list of fills to this product.</param>
        /// <param name="paging">The paging options.</param>
        /// <returns></returns>
        public static async Task <PaginatedResult <Fill> > GetFillsAsync(this GdaxClient client, String orderId = null, String productId = null, PaginationOptions paging = null)
        {
            Check.NotNull(client, nameof(client));

            var request = new GdaxRequestBuilder("/fills")
                          .AddParameterIfNotNull("order_id", orderId)
                          .AddParameterIfNotNull("product_id", productId)
                          .SetPageOptions(paging)
                          .Build();

            var response = await client.GetResponseAsync <IList <Fill> >(request).ConfigureAwait(false);

            return(new PaginatedResult <Fill>(response, paging));
        }
        /// <summary>
        /// Gets snapshot information about the last trade (tick), best bid/ask, and 24h volume.
        /// </summary>
        /// <remarks>
        /// Polling is discouraged in favor of connecting via the websocket stream and listening for match messages.
        /// </remarks>
        /// <param name="productId">The product identifier.</param>
        /// <returns></returns>
        public static async Task <ProductTicker> GetProductTickerAsync(this GdaxClient client, String productId)
        {
            Check.NotNull(client, nameof(client));
            Check.NotNullOrWhiteSpace(productId, nameof(productId));

            var request = new GdaxRequestBuilder($"/products/{productId}/ticker")
                          .Build();

            var response = await client.GetResponseAsync <ProductTicker>(request).ConfigureAwait(false);

            if (response.Value != null)
            {
                response.Value.ProductId = productId;
            }

            return(response.Value);
        }