예제 #1
0
        private void LoadTickers()
        {
            //toolDropDownTickerBtc.DropDown.Items.Clear();
            //toolDropDownTickerUsdt.DropDown.Items.Clear();
            //toolDropDownTickerBtc.Enabled = false;
            //toolDropDownTickerUsdt.Enabled = false;
            toolButtonTickerBtc.Enabled     = false;
            toolButtonTickerUsd.Enabled     = false;
            toolStripButtonChart.Enabled    = false;
            toolStripButtonAlerts.Enabled   = false;
            toolStripComboBoxMarket.Enabled = false;
            toolStripButtonBalance.Enabled  = false;

            // if (!ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text).HaveKey())
            //     return;

            Market market = ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text);

            tradeHandlers = new TradeRequestHandlers(market);

            /*
             * RequestItemGroup itemgroup = new RequestItemGroup(LoadTickers_UIResultHandler);
             * itemgroup.AddItem(market.GetTradePairsBegin(), tradeHandlers.GetTradePairs_RequestHandler);
             * RequestConsumer.requestManager.AddItemGroup(market.MarketName(), itemgroup);
             */

            UpdateMarkets();
        }
예제 #2
0
        private void ShowChartForm()
        {
            FormChart form = new FormChart(ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text));

            form.parent = this;
            form.Show();
        }
예제 #3
0
        private void toolStripButtonAlerts_Click(object sender, EventArgs e)
        {
            FormAlertMain form = new FormAlertMain(ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text));

//            form.parent = this;
            form.Show();
        }
예제 #4
0
        private void UpdateBalances(List <string> marketFilter)
        {
            if (requestBalancesStart)
            {
                return;
            }
            if (marketFilter.Count == 0)
            {
                return;
            }
            requestBalancesStart    = true;
            marketBalance           = new Dictionary <string, List <Balance> >();
            dgridBalance.DataSource = null;

            foreach (var itemMarket in marketFilter)
            {
                RequestItemGroup     itemgroup     = new RequestItemGroup(UpdateBalances_UIResultHandler);
                Market               market        = ExchangeManager.GetMarketByMarketName(itemMarket);
                TradeRequestHandlers tradeHandlers = new TradeRequestHandlers(market);
                itemgroup.AddItem(market.GetBalancesBegin(), tradeHandlers.GetBalances_RequestHandler);
                RequestConsumer.requestManager.AddItemGroup(market.MarketName(), itemgroup);
            }

            /*
             * foreach (var itemMarket in marketFilter)
             * {
             *  RequestItemGroup igroup = new RequestItemGroup(UpdateBala_UIRndler);
             *  Market imarket = ExchangeManager.GetMarketByMarketName("Bittrex");
             *  TradeRequestHandlers itradeHandlers = new TradeRequestHandlers(imarket);
             *  igroup.AddItem(imarket.GetBalan(), itradeHandlers.GetBala);
             *  RequestConsumer.requestManager.AddItemGroup(imarket.MarketName(), igroup);
             * }
             */
        }
예제 #5
0
        private void ShowTradeForm(string ticker)
        {
            FormTrade form = new FormTrade(ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text), ticker);

            form.parent = this;
            form.Show();
        }
예제 #6
0
        private void buttonShowGraphic_Click(object sender, EventArgs e)
        {
            FormChart form = new FormChart(ExchangeManager.GetMarketByMarketName(tradeLogic.GetMarketName()), tradeLogic.ticker);

            form.parent = this;
            form.Show();
        }
예제 #7
0
        private void UpdateMarket(string marketName)
        {
            Market market = ExchangeManager.GetMarketByMarketName(marketName);

            tradeHandlers = new TradeRequestHandlers(market);
            RequestItemGroup itemgroup = new RequestItemGroup(GetMarketCurrent_UIResultHandler);

            itemgroup.AddItem(market.GetMarketCurrentBegin(), tradeHandlers.GetMarketCurrent_RequestHandler);
            RequestConsumer.requestManager.AddItemGroup(market.MarketName(), itemgroup);
        }
예제 #8
0
파일: Form1.cs 프로젝트: SuffArt/BitWhiskey
        public void LoadTickers_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (Helper.IsResultHasErrors(resultResponse))
            {
                return;
            }
            Dictionary <string, TradePair> tradePairs = (Dictionary <string, TradePair>)resultResponse.items[0].result.resultData;

            //Global.market.tradePairs = new Dictionary<string, TradePair>();
            //Global.market.tradePairs.Add("BTC_LTC",new TradePair{currency1 = "BTC",currency2 = "LTC",ticker = "BTC_LTC",isActive =true});

            int btctickerCount = 0;

            foreach (KeyValuePair <string, TradePair> pair in tradePairs)
            {
                if (pair.Key.StartsWith("BTC"))
                {
                    btctickerCount++;
                }
            }

            ToolStripDropDown drop_downbtc = new ToolStripDropDown();

            drop_downbtc.LayoutStyle = ToolStripLayoutStyle.Table;
            //            drop_downbtc.
            ((TableLayoutSettings)drop_downbtc.LayoutSettings).ColumnCount = btctickerCount / 23 + 1;
            toolDropDownTickerBtc.DropDown = drop_downbtc;

            ToolStripDropDown drop_downusdt = new ToolStripDropDown();

            drop_downusdt.LayoutStyle = ToolStripLayoutStyle.Table;
            ((TableLayoutSettings)drop_downusdt.LayoutSettings).ColumnCount = (tradePairs.Count - btctickerCount) / 23 + 1;
            toolDropDownTickerUsdt.DropDown = drop_downusdt;

            foreach (KeyValuePair <string, TradePair> pair in tradePairs.OrderBy(p => p.Key))
            {
                if (pair.Key.StartsWith("BTC"))
                {
                    toolDropDownTickerBtc.DropDown.Items.Add(pair.Key);
                }
                else //if (pair.Key.StartsWith("USDT"))
                {
                    toolDropDownTickerUsdt.DropDown.Items.Add(pair.Key);
                }
            }

            if (ExchangeManager.GetMarketByMarketName(toolStripComboBoxMarket.Text).HaveKey())
            {
                toolDropDownTickerBtc.Enabled  = true;
                toolDropDownTickerUsdt.Enabled = true;
            }
            toolStripButtonChart.Enabled = true;
        }
예제 #9
0
        public FormBalance()
        {
            InitializeComponent();

            comboBoxExchange.Items.Add("All");
            foreach (var market in Global.markets.GetMarketList())
            {
                if (ExchangeManager.GetMarketByMarketName(market.ToString()).HaveKey())
                {
                    comboBoxExchange.Items.Add(market.ToString());
                }
            }
            comboBoxExchange.SelectedIndex = 0;
        }
예제 #10
0
        private void dGridAlerts_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            if (gvAlerts.Column(e.ColumnIndex).Name == "delete")
            {
                string id      = (string)gvAlerts.CellValue("id", e.RowIndex);
                int    alertid = int.Parse(id);
                AlertManager.Remove(alertid);
                AlertManager.CheckAlerts();
                ShowAlertList();
            }
            else if (gvAlerts.Column(e.ColumnIndex).Name == "edit")
            {
                string       id      = (string)gvAlerts.CellValue("id", e.RowIndex);
                int          alertid = int.Parse(id);
                Alert        alert   = AlertManager.alerts[alertid];
                FormAlertAdd form    = new FormAlertAdd(ExchangeManager.GetMarketByMarketName(alert.market), "", alertid);
                form.ShowDialog();
                if (form.alertAdded || form.alertChanged)
                {
                    AlertManager.SaveAlerts();
                    AlertManager.CheckAlerts();
                }
                ShowAlertList();
            }
            else if (gvAlerts.Column(e.ColumnIndex).Name == "enable")
            {
                string id      = (string)gvAlerts.CellValue("id", e.RowIndex);
                int    alertid = int.Parse(id);
                Alert  alert   = AlertManager.alerts[alertid];
                alert.enabled = !alert.enabled;
                if (!alert.enabled)
                {
                    alert.alertExecute = false;
                }
                AlertManager.SaveAlerts();
                AlertManager.CheckAlerts();
                ShowAlertList();
            }
        }
예제 #11
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();
        }