Пример #1
0
        public void CreateBalancesGridView(List <ExchangeBalance> balances)
        {
            var dataView = balances.Select(item => new
            {
                exchangeName = item.exchangeName,
                currency     = item.currency,
                balance      = Helper.PriceToStringBtc(item.balance),
                btcBalance   = Helper.PriceToStringBtc(item.btcBalance),
                usdBalance   = ((int)item.usdBalance).ToString()
            }).OrderBy(p => p.exchangeName).ThenBy(p => p.currency).ToList();

            List <GVColumn> columns = new List <GVColumn>()
            {
                new GVColumn("exchangeName", "Exchange", "string"),
                new GVColumn("currency", "Currency", "string"),
                new GVColumn("balance", "Balance", "string"),
                new GVColumn("btcBalance", "BTC Balance", "string"),
                new GVColumn("usdBalance", "USD Balance", "string")
            };

            if (gv == null)
            {
                gv = new DataGridViewExWrapper();
            }
            gv.Create(dgridBalance, dataView, columns, true);
            DataGridViewCellStyle styleBTC = new DataGridViewCellStyle {
                Font = new Font("Tahoma", 9.0F, FontStyle.Regular), ForeColor = Color.OrangeRed
            };
            DataGridViewCellStyle styleUSD = new DataGridViewCellStyle {
                Font = new Font("Tahoma", 9.0F, FontStyle.Regular), ForeColor = Color.Green
            };

            gv.SetColumnStyle("btcBalance", styleBTC);
            gv.SetColumnStyle("usdBalance", styleUSD);
        }
Пример #2
0
        public void UpdateMyOpenOrders_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (RequestManager.IsResultHasErrors(resultResponse))
            {
                return;
            }
            List <OpenOrder> myOpenOrders = (List <OpenOrder>)resultResponse.items[0].result.resultData;

            var dataView = myOpenOrders.Select(item => new
            {
                openUuid  = item.openUuid,
                date      = item.openedDate,
                orderType = item.orderType,
                price     = Helper.PriceToStringBtc(item.price),
                amount    = Helper.PriceToStringBtc(item.quantity),
                remain    = Helper.PriceToStringBtc(item.quantityRemaining)
            }).ToList();

            GVButtonColumn  buttDeleteRow = new GVButtonColumn("delete", "", "c_button", "Cancel");
            List <GVColumn> columns       = new List <GVColumn>()
            {
                new GVColumn("openUuid", "Order Id", "string"),
                new GVColumn("date", "Date", "string"),
                new GVColumn("orderType", "Type", "string"),
                new GVColumn("price", "Price", "string"),
                new GVColumn("amount", "Amount", "string"),
                new GVColumn("remain", "Remain", "string"),
                buttDeleteRow
            };

            //            GVState gvstate = new GVState();
            if (gvMyOpenOrders == null)
            {
                gvMyOpenOrders = new DataGridViewExWrapper();
            }
            gvMyOpenOrders.Create(dgridOpenOrders, dataView, columns, true);
            gvMyOpenOrders.AutoSizeFillExcept("date");
            gvMyOpenOrders.RowColorByCondition("orderType", "SELL LIMIT", Color.LightPink);

            /*
             * List<DGVColumn> columns = new List<DGVColumn>()
             * {
             *  new DGVColumn( "date", "Date","string") ,
             *  new DGVColumn( "orderType", "Type","string") ,
             *  new DGVColumn( "price", "Price","string") ,
             *  new DGVColumn( "amount", "Amount","string") ,
             *  new DGVColumn( "remain", "Remain","string")
             * };
             * DataGridViewWrapper gv = new DataGridViewWrapper(dgridOpenOrders, true);
             * gv.Create(dataView, columns);
             * gv.AutoSizeDisplayedExcept("price");
             * gv.RowColorByCondition("orderType", "SELL LIMIT", Color.LightPink);
             */
        }
Пример #3
0
        public void ShowAlertList()
        {
            var dataView = AlertManager.alerts.Select(item => new
            {
                id           = item.Value.id.ToString(),
                caption      = item.Value.caption,
                tickerPair   = item.Value.tickerPair,
                priceAlert   = item.Value.priceAlert.ToString(),
                playSound    = item.Value.playSound.ToString(),
                showInChart  = item.Value.showInChart.ToString(),
                enabled      = item.Value.enabled.ToString(),
                alertExecute = item.Value.alertExecute.ToString()
            }).ToList();

            GVButtonColumn  buttEnableAlert = new GVButtonColumn("enable", "", "c_button", "On\\Off");
            GVButtonColumn  buttEditAlert   = new GVButtonColumn("edit", "", "c_button", "Edit");
            GVButtonColumn  buttDeleteAlert = new GVButtonColumn("delete", "", "c_button", "Delete");
            List <GVColumn> columns         = new List <GVColumn>()
            {
                new GVColumn("id", "Id", "string"),
                new GVColumn("caption", "Name", "string"),
                new GVColumn("tickerPair", "Currency", "string"),
                new GVColumn("priceAlert", "Alert Price", "string"),
                new GVColumn("playSound", "PlaySound", "string"),
                new GVColumn("showInChart", "ShowInChart", "string"),
                new GVColumn("enabled", "Enabled", "string"),
                new GVColumn("alertExecute", "Executing", "string"),
                buttEnableAlert,
                buttEditAlert,
                buttDeleteAlert
            };

            if (gvAlerts == null)
            {
                gvAlerts = new DataGridViewExWrapper();
            }
            gvAlerts.Create(dGridAlerts, dataView, columns, true);
            gvAlerts.AutoSizeFillExcept("caption");
            gvAlerts.RowColorByCondition("alertExecute", "True", Color.LightPink);
        }
Пример #4
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();
        }
Пример #5
0
        private void InitGrid()
        {
            List <TickerGridRow> rows = new List <TickerGridRow>();

            TickerGridRow row;
            int           total = selPairs.Count;

            for (int f = 0; f < total; f += 8)
            {
                row = new TickerGridRow();
                if (f < total)
                {
                    row.f1 = selPairs[f].ticker;
                }
                if (f + 1 < total)
                {
                    row.f2 = selPairs[f + 1].ticker;
                }
                if (f + 2 < total)
                {
                    row.f3 = selPairs[f + 2].ticker;
                }
                if (f + 3 < total)
                {
                    row.f4 = selPairs[f + 3].ticker;
                }
                if (f + 4 < total)
                {
                    row.f5 = selPairs[f + 4].ticker;
                }
                if (f + 5 < total)
                {
                    row.f6 = selPairs[f + 5].ticker;
                }
                if (f + 6 < total)
                {
                    row.f7 = selPairs[f + 6].ticker;
                }
                if (f + 7 < total)
                {
                    row.f8 = selPairs[f + 7].ticker;
                }
                rows.Add(row);
            }

            List <GVColumn> columns = new List <GVColumn>()
            {
                new GVColumn("f1", "F1", "string"),
                new GVColumn("f2", "F2", "string"),
                new GVColumn("f3", "F3", "string"),
                new GVColumn("f4", "F4", "string"),
                new GVColumn("f5", "F5", "string"),
                new GVColumn("f6", "F6", "string"),
                new GVColumn("f7", "F7", "string"),
                new GVColumn("f8", "F8", "string")
            };

            //            GVState gvstate = new GVState();
            if (gvTicker == null)
            {
                gvTicker = new DataGridViewExWrapper();
            }
            gvTicker.Create(dGridTicker, rows, columns);
            gvTicker.HighlightMouseMoveCell(true);
            DataGridViewCellStyle styleLeft = new DataGridViewCellStyle {
                Font = new Font("Tahoma", 9.0F, FontStyle.Regular), Alignment = DataGridViewContentAlignment.MiddleLeft
            };

            for (int n = 1; n <= 8; n++)
            {
                gvTicker.SetColumnStyle("f" + n, styleLeft);
            }
        }