Beispiel #1
0
        public async Task <List <Trade> > GetTradeHistory(CurrencyPair pair, UnixSec start_time, UnixSec end_time, CancellationToken?cancel = null)
        {
            // https://poloniex.com/public?command=returnTradeHistory&currencyPair=BTC_NXT&start=1410158341&end=1410499372
            var jtok = await GetData(Method.Public, "returnTradeHistory", cancel, new Params
            {
                { "currencyPair", pair.Id },
                { "start", start_time },
                { "end", end_time },
            });

            return(ParseJsonReply <List <Trade> >(jtok));
        }
Beispiel #2
0
        /// <summary>Return the chart data for a given pair, over a given time range</summary>
        protected override Task <List <Candle> > CandleDataInternal(TradePair pair, ETimeFrame timeframe, UnixSec time_beg, UnixSec time_end, CancellationToken?cancel)       // Worker thread context
        {
            // Get the chart data
            var cp   = new CurrencyPair(pair.Base, pair.Quote);
            var data = Api.CandleData[cp, ToMarketPeriod(timeframe), time_beg, time_end, cancel];
            //var data = await Api.GetChartData(cp, ToMarketPeriod(timeframe), time_beg, time_end, cancel);

            // Convert it to candles
            var candles = data.Select(x => new Candle(x.Time.Ticks, x.Open, x.High, x.Low, x.Close, x.Median, x.Volume)).ToList();

            return(Task.FromResult(candles));
        }
Beispiel #3
0
        /// <summary></summary>
        public async Task <List <MarketChartData> > GetChartData(CurrencyPair pair, EMarketPeriod period, UnixSec time_beg, UnixSec time_end, CancellationToken?cancel = null)
        {
            try
            {
                var jtok = await GetData(Method.Public, "returnChartData", cancel, new Params
                {
                    { "currencyPair", pair.Id },
                    { "start", time_beg.Value },
                    { "end", time_end.Value },
                    { "period", (int)period },
                });

                var data = ParseJsonReply <List <MarketChartData> >(jtok);

                // Poloniex returns a single invalid candle if there is no data within the range
                return
                    (data.Count == 0 ? new List <MarketChartData>() :
                     data.Count == 1 && data[0].Invalid ? new List <MarketChartData>() :
                     data);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("too much data"))
                {
                    throw new PoloniexException(EErrorCode.TooMuchDataRequested, "Too much chart data was requested");
                }
                throw;
            }
        }
        ///// <summary>Return the order book for 'pair' to a depth of 'count'</summary>
        //protected async override Task<MarketDepth> MarketDepthInternal(TradePair pair, int depth) // Worker thread context
        //{
        //	var cp = new CurrencyPair(pair.Base, pair.Quote);
        //	var orders = await Api.GetOrderBook(cp, depth, cancel: Shutdown.Token);

        //	// Update the depth of market data
        //	var market_depth = new MarketDepth(pair.Base, pair.Quote);
        //	var buys = orders.BuyOffers.Select(x => new Offer(x.Price._(pair.RateUnits), x.AmountBase._(pair.Base))).ToArray();
        //	var sells = orders.SellOffers.Select(x => new Offer(x.Price._(pair.RateUnits), x.AmountBase._(pair.Base))).ToArray();
        //	market_depth.UpdateOrderBooks(buys, sells);
        //	return market_depth;
        //}

        /// <summary>Return the chart data for a given pair, over a given time range</summary>
        protected async override Task <List <Candle> > CandleDataInternal(TradePair pair, ETimeFrame timeframe, UnixSec time_beg, UnixSec time_end, CancellationToken?cancel)       // Worker thread context
        {
            var cp = new CurrencyPair(pair.Base, pair.Quote);

            // Get the chart data
            var data = await Api.GetChartData(cp, ToMarketPeriod(timeframe), time_beg, time_end, cancel);

            // Convert it to candles (yes, Polo gets the base/quote backwards for 'Volume')
            var candles = data.Select(x => new Candle(x.Time.Ticks, x.Open, x.High, x.Low, x.Close, x.WeightedAverage, x.VolumeQuote)).ToList();

            return(candles);
        }