示例#1
0
        public override Dictionary <string, TradePair> GetTradePairsEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            dynamic stuff = Newtonsoft.Json.JsonConvert.DeserializeObject(response);

            Dictionary <string, TradePair> tradePairs = new Dictionary <string, TradePair>();
            int n = 0;

            foreach (var item in stuff)
            {
                n++;
                TradePair pair = new TradePair
                {
                    currency1 = "",
                    currency2 = "",
                    ticker    = item.Name,
                    isActive  = true
                };
                //                if (item.Value["disabled"].ToString() == "1")
                //                    pair.isActive = false;

                Pair pairinfo = new Pair(pair.ticker);
                pair.currency1 = pairinfo.currency1;
                pair.currency2 = pairinfo.currency2;
                tradePairs.Add(pair.ticker, pair);
            }
            return(tradePairs);
        }
示例#2
0
        public override Dictionary <string, TradePair> GetTradePairsEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

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

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

            Dictionary <string, TradePair> tradePairs = new Dictionary <string, TradePair>();
            int n = 0;

            foreach (var item in jdata.result)
            {
                n++;
                TradePair pair = new TradePair
                {
                    currency1 = item.BaseCurrency,
                    currency2 = item.MarketCurrency,
                    ticker    = item.MarketName,
                    isActive  = item.IsActive
                };
                pair.ticker = Helper.ToStandartTicker(pair.ticker);
                tradePairs.Add(pair.ticker, pair);
            }
            return(tradePairs);
        }
示例#3
0
        public override Dictionary <string, TradePair> GetTradePairsEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

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

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

            try
            {
                jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <BMarkets>(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);
            }



            Dictionary <string, TradePair> tradePairs = new Dictionary <string, TradePair>();
            int n = 0;

            foreach (var item in jdata.result)
            {
                n++;
                TradePair pair = new TradePair
                {
                    currency1 = item.BaseCurrency,
                    currency2 = item.MarketCurrency,
                    ticker    = item.MarketName,
                    isActive  = item.IsActive
                };
                pair.ticker = Helper.ToStandartTicker(pair.ticker);
                tradePairs.Add(pair.ticker, pair);
            }
            return(tradePairs);
        }
示例#4
0
        public override Dictionary <string, TradePair> GetTradePairsEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            YInfo jdata = null;

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

            Dictionary <string, TradePair> tradePairs = new Dictionary <string, TradePair>();

            foreach (var item in jdata.pairs)
            {
                TradePair pair = new TradePair
                {
                    currency1 = "",
                    currency2 = "",
                    ticker    = ToUITicker(item.Key),
                    isActive  = true
                };
                //                if (item.Value["disabled"].ToString() == "1")
                //                    pair.isActive = false;
                Pair pairinfo = new Pair(pair.ticker);
                if (pair.ticker != "RUR_BTC" && pair.ticker != "USD_BTC" && pairinfo.currency1 != "BTC" && pairinfo.currency1 != "USD")
                {
                    continue;
                }
                pair.currency1 = pairinfo.currency1;
                pair.currency2 = pairinfo.currency2;
                tradePairs.Add(pair.ticker, pair);
            }

            return(tradePairs);
        }
示例#5
0
        public override Dictionary <string, TradePair> GetTradePairsEnd(string parameters)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            dynamic jdata = null;

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

            Dictionary <string, TradePair> tradePairs = new Dictionary <string, TradePair>();
            int n = 0;

            foreach (var item in jdata)
            {
                n++;
                TradePair pair = new TradePair
                {
                    currency1 = "",
                    currency2 = "",
                    ticker    = item.Name,
                    isActive  = true
                };
                //                if (item.Value["disabled"].ToString() == "1")
                //                    pair.isActive = false;

                Pair pairinfo = new Pair(pair.ticker);
                pair.currency1 = pairinfo.currency1;
                pair.currency2 = pairinfo.currency2;
                tradePairs.Add(pair.ticker, pair);
            }
            return(tradePairs);
        }
示例#6
0
        public void GetMarketCurrent_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (RequestManager.IsResultHasErrors(resultResponse))
            {
                return;
            }
            Dictionary <string, MarketCurrent> currenciesDict = (Dictionary <string, MarketCurrent>)resultResponse.items[0].result.resultData;

            //            Dictionary<string, TradePair> pairs = (Dictionary<string, TradePair>)resultResponse.items[0].result.resultData;

            if (!marketsLoaded)
            {
                if (Global.marketsState.curMarketPairs[resultResponse.market] == null)
                {
                    Dictionary <string, TradePair> tradePairs = new Dictionary <string, TradePair>();
                    foreach (KeyValuePair <string, MarketCurrent> pair in currenciesDict)
                    {
                        Pair      pairinfo = new Pair(pair.Value.ticker);
                        TradePair tpair    = new TradePair
                        {
                            currency1 = pairinfo.currency1,
                            currency2 = pairinfo.currency2,
                            isActive  = true,
                            ticker    = pair.Value.ticker
                        };

                        tradePairs.Add(pair.Key, tpair);
                    }
                    Global.marketsState.SetPairs(resultResponse.market, tradePairs);
                }


                bool allMarketsReady = true;
                foreach (var marketName in Global.markets.GetMarketList())
                {
                    if (Global.marketsState.curMarketPairs[marketName] == null)
                    {
                        allMarketsReady = false;
                        break;
                    }
                }
                if (allMarketsReady)
                {
                    marketsLoaded = true;
                }
            }

            if (marketsLoaded)
            {
                Market curmarket = ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text);
                if (curmarket.HaveKey())
                {
                    toolButtonTickerBtc.Enabled = true;
                    toolButtonTickerUsd.Enabled = true;
                    if (curmarket.Options().AllPairRatesSupported)
                    {
                        toolStripButtonAlerts.Enabled = true;
                    }
                }
                if (curmarket.Options().ChartDataSupported)
                {
                    toolStripButtonChart.Enabled = true;
                }
                toolStripButtonBalance.Enabled  = true;
                toolStripComboBoxMarket.Enabled = true;
                labelInfo.Text = "";
            }

            List <MarketCurrentView> currencies = currenciesDict.Values.Select(item => new MarketCurrentView
            {
                ticker        = item.ticker,
                origPrice     = item.lastPrice,
                lastPrice     = item.lastPrice,
                lastPriceUSD  = 0,
                percentChange = item.percentChange,
                volumeBtc     = item.volumeBtc,
                volumeUSDT    = item.volumeUSDT
            }).ToList();


            if (currenciesDict.ContainsKey("USDT_BTC"))
            {
                double btcPrice = currenciesDict["USDT_BTC"].lastPrice;
                foreach (var item in currencies)
                {
                    if (item.ticker.StartsWith("BTC"))
                    {
                        item.volumeUSDT = item.volumeBtc * btcPrice;
                    }

                    if (item.ticker.StartsWith("BTC"))
                    {
                        item.lastPriceUSD = item.lastPrice * btcPrice;
                    }
                    else if (item.ticker.StartsWith("USDT"))
                    {
                        double usdprice = item.lastPrice;
                        item.lastPriceUSD = usdprice;
                        item.lastPrice    = item.lastPrice / btcPrice;
                    }
                }
            }
            currencies = currencies.OrderByDescending(x => x.volumeUSDT).ToList();

            List <MarketCurrentView> currenciesCopy = new List <MarketCurrentView>();

            foreach (MarketCurrentView item in currencies)
            {
                MarketCurrentView newItem = new MarketCurrentView()
                {
                    ticker        = item.ticker,
                    origPrice     = item.origPrice,
                    lastPrice     = item.lastPrice,
                    lastPriceUSD  = item.lastPriceUSD,
                    percentChange = item.percentChange,
                    volumeBtc     = item.volumeBtc,
                    volumeUSDT    = item.volumeUSDT
                };
                currenciesCopy.Add(newItem);
            }
            if (ExchangeManager.GetMarketByMarketName(resultResponse.market).Options().AllPairRatesSupported)
            {
                Global.marketsState.Update(resultResponse.market, currenciesCopy);
            }


            if (resultResponse.market != toolStripComboBoxMarket.Text)
            {
                return;
            }


            var dataView = currencies.Select(item => new
            {
                ticker               = item.ticker,
                lastPrice            = item.lastPrice,
                lastPriceUSDT        = item.lastPriceUSD,
                percentChange        = item.percentChange,
                volumeBtc            = item.volumeBtc,
                volumeUSDT           = item.volumeUSDT,
                lastPriceDisplay     = Helper.PriceToStringBtc(item.lastPrice),
                lastPriceUSDTDisplay = item.lastPriceUSD.ToString("N3") + " $",
                percentChangeDisplay = item.percentChange.ToString("0") + " %",
                volumeBtcDisplay     = item.volumeBtc.ToString("N2"),
                volumeUSDTDisplay    = item.volumeUSDT.ToString("N0") + " $"
            }).ToList();
            List <GVColumn> columns = new List <GVColumn>()
            {
                new GVColumn("ticker", "Currency", "string"),
                new GVColumn("lastPrice", "Price BTC", "DisplayField", "lastPriceDisplay"),
                new GVColumn("lastPriceUSDT", "Price $", "DisplayField", "lastPriceUSDTDisplay"),
                new GVColumn("percentChange", "Change %", "DisplayField", "percentChangeDisplay"),
                new GVColumn("volumeBtc", "Volume BTC", "DisplayField", "volumeBtcDisplay"),
                new GVColumn("volumeUSDT", "Volume $", "DisplayField", "volumeUSDTDisplay"),
                new GVColumn("lastPriceDisplay", "Price BTC", "string", "", false),
                new GVColumn("lastPriceUSDTDisplay", "Price $", "string", "", false),
                new GVColumn("percentChangeDisplay", "Change %", "string", "", false),
                new GVColumn("volumeBtcDisplay", "Volume BTC", "string", "", false),
                new GVColumn("volumeUSDTDisplay", "Volume $", "string", "", false)
            };

            if (gvMarkets == null)
            {
                gvMarkets = new DataGridViewExWrapper();
            }
            gvMarkets.Create(dgridMarkets, dataView, columns, true);
            DataGridViewCellStyle styleTicker = new DataGridViewCellStyle {
                Font = new Font("Tahoma", 9.0F, FontStyle.Bold), ForeColor = Color.Black
            };
            DataGridViewCellStyle stylePrice = new DataGridViewCellStyle {
                Font = new Font("Tahoma", 9.0F, FontStyle.Regular), ForeColor = Color.Black
            };

            gvMarkets.SetColumnStyle("ticker", styleTicker);
            gvMarkets.SetColumnStyle("lastPrice", stylePrice);
            gvMarkets.SetColumnStyle("lastPriceUSDT", stylePrice);
            //gvMarkets.AutoSizeFillExcept("volumeUSDT");
            //            gv.RowColorByCondition("orderType", (string s) => { return s == "1"; }, Color.LightPink);


            timerMarkets.Start();
        }