Exemplo n.º 1
0
        public async Task <IEnumerable <OpenOrder> > OpenOrders(SymbolPair pair, CancellationToken?cancelToken = null)
        {
            const string basePath = "/open_orders";
            var          path     = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To);

            try
            {
                return(await this.PostToService(
                           path,
                           EmptyRequestParams,
                           x =>
                {
                    var ja = x as JsonArray;
                    return ja == null
                            ? Enumerable.Empty <OpenOrder>()
                            : ja.Select(OpenOrder.FromDynamic).ToArray();
                },
                           cancelToken
                           ));
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 2
0
 internal static Ticker FromDynamic(SymbolPair symbolPair, dynamic data)
 {
     return(new Ticker
     {
         SymbolPair = symbolPair,
         Ask = JsonHelpers.ToDecimal(data["ask"]),
         Bid = JsonHelpers.ToDecimal(data["bid"]),
         High = JsonHelpers.ToDecimal(data["high"]),
         Last = JsonHelpers.ToDecimal(data["last"]),
         Low = JsonHelpers.ToDecimal(data["low"]),
         Volume = JsonHelpers.ToDecimal(data["volume"]),
         Timestamp = data["timestamp"]
     });
 }
Exemplo n.º 3
0
        public async Task <Ticker> Ticker(SymbolPair pair, CancellationToken?cancelToken = null)
        {
            const string basePath = "/ticker";
            var          path     = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To);

            try
            {
                return(await this.GetFromService(
                           path,
                           json => Cex.Ticker.FromDynamic(pair, json),
                           cancelToken
                           ));
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 4
0
        public async Task <OrderBook> OrderBook(SymbolPair pair, CancellationToken?cancelToken = null)
        {
            const string basePath = "/order_book";
            var          path     = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To);

            try
            {
                return(await this.GetFromService(
                           path,
                           Cex.OrderBook.FromDynamic,
                           cancelToken
                           ));
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 5
0
        public async Task <OHLCV> Historical_1m_OHLCV_Chart(
            SymbolPair pair, DateTime date, string mhd, CancellationToken?cancelToken = null)
        {
            const string basePath = "/ohlcv/hd";
            var          path     = string.Format("{0}/{1}/{2}/{3}", basePath, date.ToString("yyyyMMdd"), pair.From, pair.To);

            try
            {
                return(await this.GetFromService(
                           path,
                           Cex.OHLCV.FromDynamic,
                           cancelToken
                           ));

                //return mhd == "m" ? result.data1m : mhd == "h" ? result.data1h : result.data1d;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <Chart> > Chart(SymbolPair pair, CancellationToken?cancelToken = null)
        {
            const string basePath = "/price_stats";
            var          path     = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To);

            try
            {
                return(await this.PostToService(
                           path,
                           () => new[] {
                    this.NewRequestParam("lastHours", 24),
                    this.NewRequestParam("maxRespArrSize", 100)
                },
                           Cex.Chart.FromDynamic,
                           cancelToken
                           ));
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 7
0
        public async Task <IEnumerable <Trade> > TradeHistory(SymbolPair pair, TradeId?tradeId = null, CancellationToken?cancelToken = null)
        {
            const string basePath = "/trade_history";
            var          path     = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To);

            if (tradeId != null)
            {
                path += string.Format("/?since={0}", tradeId.Value);
            }

            try
            {
                return(await this.GetFromService(
                           path,
                           Trade.FromDynamic,
                           cancelToken
                           ));
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 8
0
        public async Task <OpenOrder> PlaceOrder(SymbolPair pair, Order order, CancellationToken?cancelToken = null)
        {
            const string basePath = "/place_order";
            var          path     = string.Format("{0}/{1}/{2}", basePath, pair.From, pair.To);

            try
            {
                return(await this.PostToService(
                           path,
                           () => new[]
                {
                    this.NewRequestParam("type", order.Type == OrderType.Sell ? "sell" : "buy"),
                    this.NewRequestParam("price", order.Price),
                    this.NewRequestParam("amount", order.Amount)
                },
                           OpenOrder.FromDynamic,
                           cancelToken
                           ));
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
Exemplo n.º 9
0
 public bool Equals(SymbolPair other)
 {
     return(From == other.From && To == other.To);
 }