public async Task <OrderBook> GetOrderBookAsync(OrderBookContext context) { var api = GdaxApiProvider.GetApi(context); var pairCode = context.Pair.ToTicker(this); var r = await api.GetProductOrderBookAsync(pairCode, OrderBookDepthLevel.FullNonAggregated).ConfigureAwait(false); var bids = context.MaxRecordsCount == Int32.MaxValue ? r.bids.ToArray() : r.bids.Take(context.MaxRecordsCount).ToArray(); var asks = context.MaxRecordsCount == Int32.MaxValue ? r.asks.ToArray() : r.asks.Take(context.MaxRecordsCount).ToArray(); var orderBook = new OrderBook(Network, context.Pair); foreach (var i in bids.Select(ConvertToOrderBookRecord)) { orderBook.AddBid(i.Price, i.Size); } foreach (var i in asks.Select(ConvertToOrderBookRecord)) { orderBook.AddAsk(i.Price, i.Size); } return(orderBook); }
public async Task <OhlcDataResponse> GetOhlcAsync(OhlcContext context) { var api = GdaxApiProvider.GetApi(context); var currencyCode = context.Pair.ToTicker(this); var ohlc = new OhlcDataResponse(context.Resolution); var seriesId = OhlcUtilities.GetHash(context.Pair, context.Resolution, Network); var granularitySeconds = GetSeconds(context.Resolution); var maxNumberOfCandles = 200; var tsFrom = (long)context.Range.UtcFrom.ToUnixTimeStamp(); var tsTo = (long)context.Range.UtcTo.ToUnixTimeStamp(); var tsStep = maxNumberOfCandles * granularitySeconds; var currTsTo = tsTo; var currTsFrom = tsTo - tsStep; while (currTsTo > tsFrom) { var candles = await api.GetCandlesAsync(currencyCode, currTsFrom.ToUtcDateTime(), currTsTo.ToUtcDateTime(), granularitySeconds).ConfigureAwait(false); foreach (var candle in candles) { var dateTime = ((long)candle[0]).ToUtcDateTime(); ohlc.Add(new OhlcEntry(seriesId, dateTime, this) { Low = candle[1], High = candle[2], Open = candle[3], Close = candle[4], VolumeTo = candle[5], VolumeFrom = candle[5], WeightedAverage = 0 // Is not provided by API. }); } currTsTo = currTsFrom; if (currTsTo - tsStep >= tsFrom) { currTsFrom -= tsStep; } else { currTsFrom = tsFrom; } ApiHelpers.EnterRate(this, context); } return(ohlc); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { var api = GdaxApiProvider.GetApi(context); var r = await api.GetProductsAsync().ConfigureAwait(false); var pairs = new AssetPairs(); foreach (var rProduct in r) { pairs.Add(new AssetPair(rProduct.base_currency, rProduct.quote_currency)); } return(pairs); }