示例#1
0
        private void IntialLoadMarketWatch()
        {
            string symbols = string.Empty;

            using (var streamReader = new StreamReader("Symbols.txt"))
            {
                symbols = streamReader.ReadLine();
                streamReader.Close();
            }
            ticker = BitfinexAPI.Get <string[][]>($"tickers?symbols=" + symbols);

            if (ticker != null)
            {
                BindingList <FinexTicker> customerList = new BindingList <FinexTicker>();
                for (int i = 0; i < ticker.Length; i++)
                {
                    customerList.Add(new FinexTicker {
                        pair = ticker[i][0].Replace("t", ""), bid = ticker[i][1], ask = ticker[i][3], last_price = ticker[i][7], volume = ticker[i][8]
                    });
                }
                //this.bindingSource1.DataSource = customerList;
                ObjTrading = customerList;
            }
        }
示例#2
0
        private void LoadMarketWatch()
        {
            string symbols = string.Empty;

            using (var streamReader = new StreamReader("Symbols.txt"))
            {
                symbols = streamReader.ReadLine();
                streamReader.Close();
            }
            ticker = BitfinexAPI.Get <string[][]>($"tickers?symbols=" + symbols);

            if (ticker != null)
            {
                // dt.Clear();
                var bindingSource = this.dataGridMarketData.DataSource as BindingList <FinexTicker>;
                if (bindingSource != null)
                {
                    OldWatchList = new List <OldData>();
                    foreach (var item in bindingSource)
                    {
                        OldData oldWatch = new OldData();
                        oldWatch.ask        = item.ask;
                        oldWatch.bid        = item.bid;
                        oldWatch.last_price = item.last_price;
                        oldWatch.pair       = item.pair;
                        oldWatch.volume     = item.volume;
                        OldWatchList.Add(oldWatch);
                    }
                }

                BindingList <FinexTicker> customerList = new BindingList <FinexTicker>();
                for (int i = 0; i < ticker.Length; i++)
                {
                    if (bindingSource != null)
                    {
                        var result    = bindingSource.Where(d => d.pair == ticker[i][0].Replace("t", "")).FirstOrDefault();
                        var oldResult = OldWatchList.Where(d => d.pair == ticker[i][0].Replace("t", "")).FirstOrDefault();
                        if (result != null)
                        {
                            result.ask = ticker[i][3];
                            result.bid = ticker[i][1];
                            bool bidBlue = true;
                            bool askBlue = true;
                            if (Convert.ToDecimal(result.bid) > Convert.ToDecimal(oldResult.bid))
                            {
                                this.dataGridMarketData.Rows[i].Cells[1].Style.ForeColor = Color.Blue;
                            }
                            else
                            {
                                this.dataGridMarketData.Rows[i].Cells[1].Style.ForeColor = Color.Red;
                                bidBlue = false;
                            }
                            if (Convert.ToDecimal(result.ask) > Convert.ToDecimal(oldResult.ask))
                            {
                                this.dataGridMarketData.Rows[i].Cells[2].Style.ForeColor = Color.Blue;
                            }
                            else
                            {
                                this.dataGridMarketData.Rows[i].Cells[2].Style.ForeColor = Color.Red;
                                askBlue = false;
                            }
                            if (!bidBlue || !askBlue)
                            {
                                ((TextAndImageCell)dataGridMarketData.Rows[i].Cells[0]).Image = imgList.Images[0];
                            }
                            else
                            {
                                ((TextAndImageCell)dataGridMarketData.Rows[i].Cells[0]).Image = imgList.Images[1];
                            }
                            result.last_price = ticker[i][7];
                            result.volume     = ticker[i][8];
                        }
                    }
                }
                dispatcherTimer.Interval = new TimeSpan(0, 0, 3);
            }
            else
            {
                dispatcherTimer.Interval = new TimeSpan(0, 1, 0);
            }
        }