Example #1
0
        public override bool GetTickersInfo()
        {
            string text    = string.Empty;
            string address = "https://api.exmo.me/v1/pair_settings";

            try {
                text = GetDownloadString(address);
            }
            catch (Exception) {
                return(false);
            }
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            Tickers.Clear();
            Dictionary <string, object> res = null;

            lock (JsonParser) {
                res = (Dictionary <string, object>)JsonParser.Parse(text);
            }
            int index = 0;

            foreach (string s in res.Keys)
            {
                ExmoTicker t = new ExmoTicker();
                t.Index = index;
                string[] curr = s.Split('_');
                t.BaseCurrency   = curr[1];
                t.MarketCurrency = curr[0];
                index++;
                Tickers.Add(t);
            }

            return(true);
        }
Example #2
0
        public bool UpdateTradesStatistic(ExmoTicker ticker, int count)
        {
            string text    = string.Empty;
            string address = string.Format("https://api.exmo.me/v1/trades/?pair={0}", ticker.MarketName);

            try {
                text = GetDownloadString(address);
                if (text == null)
                {
                    return(false);
                }
            }
            catch (Exception) {
                return(false);
            }

            Dictionary <string, object> res = null;

            lock (JsonParser) {
                res = (Dictionary <string, object>)JsonParser.Parse(text);
            }
            List <object> trades = (List <object>)res[ticker.MarketName];

            if (trades.Count == 0)
            {
                ticker.TradeStatistic.Add(new TradeStatisticsItem()
                {
                    Time = DateTime.Now
                });
                if (ticker.TradeStatistic.Count > 5000)
                {
                    for (int i = 0; i < 100; i++)
                    {
                        ticker.TradeStatistic.RemoveAt(0);
                    }
                }
                return(true);
            }

            TradeStatisticsItem st = new TradeStatisticsItem();

            st.MinBuyPrice  = decimal.MaxValue;
            st.MinSellPrice = decimal.MaxValue;
            st.Time         = DateTime.Now;

            foreach (Dictionary <string, object> obj in trades)
            {
                TradeHistoryItem item   = new TradeHistoryItem();
                decimal          amount = Convert.ToDecimal(obj["amount"]);
                decimal          price  = Convert.ToDecimal(obj["price"]);
                bool             isBuy  = obj["type"].ToString().Length == 3;
                if (isBuy)
                {
                    st.BuyAmount  += amount;
                    st.MinBuyPrice = Math.Min(st.MinBuyPrice, price);
                    st.MaxBuyPrice = Math.Max(st.MaxBuyPrice, price);
                    st.BuyVolume  += amount * price;
                }
                else
                {
                    st.SellAmount  += amount;
                    st.MinSellPrice = Math.Min(st.MinSellPrice, price);
                    st.MaxSellPrice = Math.Max(st.MaxSellPrice, price);
                    st.SellVolume  += amount * price;
                }
            }
            if (st.MinSellPrice == decimal.MaxValue)
            {
                st.MinSellPrice = 0;
            }
            if (st.MinBuyPrice == decimal.MaxValue)
            {
                st.MinBuyPrice = 0;
            }
            ticker.LastTradeId            = Convert.ToInt64(((Dictionary <string, object>)trades.First())["trade_id"]);
            ticker.LastTradeStatisticTime = DateTime.Now;
            ticker.TradeStatistic.Add(st);
            if (ticker.TradeStatistic.Count > 5000)
            {
                for (int i = 0; i < 100; i++)
                {
                    ticker.TradeStatistic.RemoveAt(0);
                }
            }
            return(true);
        }
Example #3
0
        public bool UpdateArbitrageOrderBook(ExmoTicker ticker, int depth)
        {
            string text    = string.Empty;
            string address = string.Format("https://api.exmo.me/v1/order_book/?pair={0}", ticker.MarketName);

            try {
                text = GetDownloadString(address);
                if (text == null)
                {
                    return(false);
                }
            }
            catch (Exception) {
                return(false);
            }

            Dictionary <string, object> res = null;

            lock (JsonParser) {
                res = (Dictionary <string, object>)JsonParser.Parse(text);
            }

            res = (Dictionary <string, object>)res[ticker.MarketName];

            List <object> bids = (List <object>)res["bid"];
            List <object> asks = (List <object>)res["ask"];

            ticker.OrderBook.GetNewBidAsks();
            int index = 0;

            OrderBookEntry[] list = ticker.OrderBook.Bids;
            foreach (List <object> item in bids)
            {
                OrderBookEntry entry = list[index];
                entry.Value  = (decimal)(double.Parse((string)item.First()));
                entry.Amount = (decimal)(double.Parse((string)item.Last()));
                index++;
                if (index >= list.Length)
                {
                    break;
                }
            }
            index = 0;
            list  = ticker.OrderBook.Asks;
            foreach (List <object> item in asks)
            {
                OrderBookEntry entry = list[index];
                entry.Value  = (decimal)(double.Parse((string)item.First()));
                entry.Amount = (decimal)(double.Parse((string)item.Last()));
                index++;
                if (index >= list.Length)
                {
                    break;
                }
            }

            ticker.OrderBook.UpdateEntries();
            ticker.OrderBook.RaiseOnChanged(new OrderBookUpdateInfo()
            {
                Action = OrderBookUpdateType.RefreshAll
            });
            return(true);
        }