Пример #1
0
        public void SetAsk_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (Helper.IsResultHasErrors(resultResponse))
            {
                return;
            }
            //            TradeLast tradelast = (TradeLast)resultResponse.result.resultData;
            //            if (tradelast.ask != 0) textPrice.Text = Helper.PriceToStringBtc(tradelast.ask);
            AllOrders orders = (AllOrders)resultResponse.items[0].result.resultData;

            double quantityToBuy = 0;

            if (Helper.IsDouble(textAmount.Text))
            {
                quantityToBuy = Helper.ToDouble(textAmount.Text);
            }
            else
            {
                MessageBox.Show("Amount is Invalid");
                return;
            }

            List <SellOrder> sellOrders = orders.sellOrders.Where(o => o.quantity >= quantityToBuy).OrderBy(o => o.rate).ToList();

            if (sellOrders.Count > 0)
            {
//                double price = tradeLogic.LastAskFromOrderBook(quantity);
                textPrice.Text = Helper.PriceToStringBtc(sellOrders[0].rate);
            }
        }
Пример #2
0
        public void SetBid_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (Helper.IsResultHasErrors(resultResponse))
            {
                return;
            }
            AllOrders orders = (AllOrders)resultResponse.items[0].result.resultData;

            double quantityToSell = 0;

            if (Helper.IsDouble(textAmount.Text))
            {
                quantityToSell = Helper.ToDouble(textAmount.Text);
            }
            else
            {
                MessageBox.Show("Amount is Invalid");  return;
            }

            List <BuyOrder> buyOrders = orders.buyOrders.Where(o => o.quantity >= quantityToSell).OrderByDescending(o => o.rate).ToList();

            if (buyOrders.Count > 0)
            {
                textPrice.Text = Helper.PriceToStringBtc(buyOrders[0].rate);
            }
        }
Пример #3
0
        public void UpdateOrderBook_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (Helper.IsResultHasErrors(resultResponse))
            {
                return;
            }
            AllOrders orders = (AllOrders)resultResponse.items[0].result.resultData;

            var dataViewSell = orders.sellOrders.Select(item => new
            {
                amount = Helper.PriceToStringBtc(item.quantity),
                price  = Helper.PriceToStringBtc(item.rate)
            }).Take(150).ToList();
            List <DGVColumn> columnsSell = new List <DGVColumn>()
            {
                new DGVColumn("amount", "Amount", "string"),
                new DGVColumn("price", "Price", "string")
            };
            DataGridViewWrapper gvSell = new DataGridViewWrapper(dgridSellOrders, true);

            gvSell.Create(dataViewSell, columnsSell);
            gvSell.AutoSizeFillExcept("amount");

            var dataViewBuy = orders.buyOrders.Select(item => new
            {
                price  = Helper.PriceToStringBtc(item.rate),
                amount = Helper.PriceToStringBtc(item.quantity)
            }).Take(150).ToList();
            DataGridViewWrapper gvBuy = new DataGridViewWrapper(dgridBuyOrders, true);

            gvBuy.Create(dataViewBuy, columnsSell);
            gvBuy.AutoSizeFillExcept("amount");
        }
Пример #4
0
        public override AllOrders GetOrderBookEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            POrderBook items  = Newtonsoft.Json.JsonConvert.DeserializeObject <POrderBook>(response);
            AllOrders  orders = new AllOrders();

            orders.buyOrders  = new List <BuyOrder>();
            orders.sellOrders = new List <SellOrder>();
            int n = 0;

            foreach (var item in items.bids)
            {
                n++;
                orders.buyOrders.Add(new BuyOrder {
                    quantity = Helper.ToDouble(item[1].ToString()), rate = Helper.ToDouble((string)item[0])
                });
            }
            n = 0;
            foreach (var item in items.asks)
            {
                n++;
                orders.sellOrders.Add(new SellOrder {
                    quantity = Helper.ToDouble(item[1].ToString()), rate = Helper.ToDouble((string)item[0])
                });
            }
            orders.sellOrders = orders.sellOrders.OrderBy(o => o.rate).ToList();
            orders.buyOrders  = orders.buyOrders.OrderByDescending(o => o.rate).ToList();

            return(orders);
        }
Пример #5
0
        public override AllOrders GetOrderBookEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            POrderBook jdata = null;

            try
            {
                jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <POrderBook>(response);
            }
            catch (Exception ex)
            { throw new MarketAPIException("Parsing Response Error" + " >>>> " + ex.Message + " ## Response: ## " + response); }


            AllOrders orders = new AllOrders();

            orders.buyOrders  = new List <BuyOrder>();
            orders.sellOrders = new List <SellOrder>();
            int n = 0;

            foreach (var item in jdata.bids)
            {
                n++;
                orders.buyOrders.Add(new BuyOrder {
                    quantity = Helper.ToDouble(item[1].ToString()), rate = Helper.ToDouble((string)item[0])
                });
            }
            n = 0;
            foreach (var item in jdata.asks)
            {
                n++;
                orders.sellOrders.Add(new SellOrder {
                    quantity = Helper.ToDouble(item[1].ToString()), rate = Helper.ToDouble((string)item[0])
                });
            }
            orders.sellOrders = orders.sellOrders.OrderBy(o => o.rate).ToList();
            orders.buyOrders  = orders.buyOrders.OrderByDescending(o => o.rate).ToList();

            return(orders);
        }
Пример #6
0
        public override AllOrders GetOrderBookEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

            BOrderBook jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <BOrderBook>(response);

            //lastRequestMsg = jdata.message;
            //lastRequestStatus = jdata.success;
            if (!jdata.success)
            {
                throw new MarketAPIException("Market API Error:" + jdata.message);
            }

            AllOrders orders = new AllOrders();

            orders.buyOrders  = new List <BuyOrder>();
            orders.sellOrders = new List <SellOrder>();

            int n = 0;

            foreach (var item in jdata.result.buy)
            {
                n++;
                orders.buyOrders.Add(new BuyOrder {
                    quantity = item.Quantity, rate = item.Rate
                });
            }
            n = 0;
            foreach (var item in jdata.result.sell)
            {
                n++;
                orders.sellOrders.Add(new SellOrder {
                    quantity = item.Quantity, rate = item.Rate
                });
            }

            orders.sellOrders = orders.sellOrders.OrderBy(o => o.rate).ToList();
            orders.buyOrders  = orders.buyOrders.OrderByDescending(o => o.rate).ToList();

            return(orders);
        }
Пример #7
0
        public override AllOrders GetOrderBookEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

//            BOrderBook jdata = Newtonsoft.Json.JsonConvert.DeserializeObject<BOrderBook>(response);
            //lastRequestMsg = jdata.message;
            //lastRequestStatus = jdata.success;
            //           if (!jdata.success)
            //               throw new MarketAPIException("Market API Error:" + jdata.message);

            string     errmsg     = "";
            string     errcaption = "";
            BOrderBook jdata      = null;

            try
            {
                jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <BOrderBook>(response);
                if (!jdata.success)
                {
                    errcaption = "Market API Error:";
                    errmsg     = jdata.message;
                }
                if (jdata.result == null)
                {
                    errcaption += "Market API Error:";
                    errmsg     += "DataResult=Null >>> " + response;
                }
            }
            catch (Exception ex)
            {
                errcaption = "Parsing Response Error:";
                errmsg     = ex.Message + " >>> " + response;
            }
            if (errmsg != "")
            {
                throw new MarketAPIException(errcaption + " >> " + errmsg);
            }


            AllOrders orders = new AllOrders();

            orders.buyOrders  = new List <BuyOrder>();
            orders.sellOrders = new List <SellOrder>();

            int n = 0;

            foreach (var item in jdata.result.buy)
            {
                n++;
                orders.buyOrders.Add(new BuyOrder {
                    quantity = item.Quantity, rate = item.Rate
                });
            }
            n = 0;
            foreach (var item in jdata.result.sell)
            {
                n++;
                orders.sellOrders.Add(new SellOrder {
                    quantity = item.Quantity, rate = item.Rate
                });
            }

            orders.sellOrders = orders.sellOrders.OrderBy(o => o.rate).ToList();
            orders.buyOrders  = orders.buyOrders.OrderByDescending(o => o.rate).ToList();

            return(orders);
        }
Пример #8
0
        public void UpdateOrderBook_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (RequestManager.IsResultHasErrors(resultResponse))
            {
                return;
            }

            try
            {
                AllOrders orders = (AllOrders)resultResponse.items[0].result.resultData;

                var dataViewSell = orders.sellOrders.Select(item => new
                {
                    amount = Helper.PriceToStringBtc(item.quantity),
                    price  = Helper.PriceToStringBtc(item.rate)
                }).Take(150).ToList();
                List <DGVColumn> columnsSell = new List <DGVColumn>()
                {
                    new DGVColumn("amount", "Amount", "string"),
                    new DGVColumn("price", "Price", "string")
                };
                DataGridViewWrapper gvSell = new DataGridViewWrapper(dgridSellOrders, true);
                gvSell.Create(dataViewSell, columnsSell);
                gvSell.AutoSizeFillExcept("amount");

                var dataViewBuy = orders.buyOrders.Select(item => new
                {
                    price  = Helper.PriceToStringBtc(item.rate),
                    amount = Helper.PriceToStringBtc(item.quantity)
                }).Take(150).ToList();
                DataGridViewWrapper gvBuy = new DataGridViewWrapper(dgridBuyOrders, true);
                gvBuy.Create(dataViewBuy, columnsSell);
                // gvBuy.AutoSizeFillExcept("amount");


                // contr orderbook data grid
                var dataViewContrSell = orders.sellOrders.Select(item => new
                {
                    price  = Helper.PriceToStringBtc(item.rate),
                    amount = Helper.PriceToStringBtc(item.quantity)
                }).Take(5).OrderByDescending(o => o.price).ToList();

                DataGridViewWrapper gvContrSell = new DataGridViewWrapper(dGridContrSell, true);
                gvContrSell.Create(dataViewContrSell, columnsSell);
//                if (dGridContrSell.RowCount>0)
//                  dGridContrSell.FirstDisplayedScrollingRowIndex = dGridContrSell.RowCount - 1;

                var dataViewContrBuy = orders.buyOrders.Select(item => new
                {
                    price  = Helper.PriceToStringBtc(item.rate),
                    amount = Helper.PriceToStringBtc(item.quantity)
                }).Take(5).ToList();
                DataGridViewWrapper gvContrBuy = new DataGridViewWrapper(dGridContrBuy, true);
                gvContrBuy.Create(dataViewContrBuy, columnsSell);
                gvContrBuy.ShowColumnHeaders(false);
            }
            catch (Exception ex)
            {
                Logman.Log(ex);
            }
        }