예제 #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();
            }
        }
예제 #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"]
     });
 }
예제 #3
0
 internal static Ticker FromDynamic(SymbolPair symbolPair, dynamic data)
 {
     return new Ticker
     {
         SymbolPair = symbolPair,
         Ask = decimal.Parse(data["ask"]),
         Bid = decimal.Parse(data["bid"]),
         High = decimal.Parse(data["high"]),
         Last = decimal.Parse(data["last"]),
         Low = decimal.Parse(data["low"]),
         Volume = decimal.Parse(data["volume"]),
         Timestamp = data["timestamp"]
     };
 }
예제 #4
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"]
     };
 }
예제 #5
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();
            }
        }
예제 #6
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();
            }
        }
예제 #7
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();
            }
        }
예제 #8
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();
            }
        }
예제 #9
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();
            }
        }
예제 #10
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();
            }
        }
예제 #11
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();
            }
        }
예제 #12
0
 public bool Equals(SymbolPair other)
 {
     return From == other.From && To == other.To;
 }
예제 #13
0
 public bool Equals(SymbolPair other)
 {
     return(From == other.From && To == other.To);
 }
예제 #14
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();
            }
        }
예제 #15
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();
            }
        }
예제 #16
0
		private async void PlaceOrder(SymbolPair pair, Balance balance, OrderType orderType)
		{
			Order order = new Order();
			OrderBook orderBook = await _cexClient.OrderBook(pair);
			_apiCallCount = ++_apiCallCount;
			
			
			IEnumerable<OrderBookOrder> bids = orderBook.Bids;
			order.Price = ((OrderBookOrder[]) (bids))[0].Price;

			decimal amount = 0;
			decimal availableBalance;
			if (orderType == OrderType.Buy)
			{
				if (pair.To == Symbol.NMC)
				{
					availableBalance = balance.NMC.Available;
					amount = PurchaseAmount(order.Price, availableBalance);
				}


				if (pair.To == Symbol.BTC)
				{
					availableBalance = balance.BTC.Available - udMaintanMinBtcBalance.Value;
					amount = PurchaseAmount(order.Price, availableBalance);
				}

				if (amount <= (decimal) 0.00000001)
					return;
			}

			if (orderType == OrderType.Sell)
			{
				if (pair.From == Symbol.IXC)
				{
					availableBalance = balance.IXC.Available;

					if (availableBalance < (decimal) .00000001)
						return;
					decimal saleValue = order.Price*availableBalance;
					if (saleValue < (decimal) .00000001)
						return;
				}
			}

			order.Type = orderType;
			order.Amount = amount;

			try
			{
				OpenOrder orderDetails = await _cexClient.PlaceOrder(pair, order);
				_apiCallCount = ++_apiCallCount;

				decimal totalOrder = order.Price*order.Amount;
				decimal totalOrderCostRounded = Math.Round(totalOrder, 8);

				richTextBox1.AppendText(string.Format(@"Sold:{8} {1} @ {2} for {0} {7}: Total: {3} @ {4} -- Order #{5}{6}",
				                                      order.Amount,
				                                      pair.To,
				                                      order.Price,
				                                      totalOrderCostRounded,
				                                      DateTime.Now,
				                                      orderDetails.Id,
				                                      Environment.NewLine, pair.From,
				                                      Math.Round(orderDetails.Price*order.Amount, 8)));
				_ghsPurchased = _ghsPurchased + order.Amount;
				_orderCount = ++_orderCount;
				UpdateUi();
			}
			catch
			{
				Console.WriteLine(@"oops");

			}

		}