private void SendSymbol(dynamic RefForm) { var ObjTrading = RefForm.ObjTrading as BindingList <FinexTicker>; string symbols = string.Empty; using (var streamReader = new StreamReader(RefForm.Name + ".txt")) { symbols = streamReader.ReadLine(); streamReader.Close(); } if (symbols != null) { comman.Seprateticklers(symbols, ref sbBitfinex, ref sbTraders, ref sbIGMarket, ref sbICMarket); //Check if Symbol Exist var hasSymbol = list.Where(m => sbBitfinex.ToString().Split(',').Contains(m.Symbol)).ToList(); if (hasSymbol != null) { List <int> channelList = new List <int>(); foreach (var item in hasSymbol) { channelList.Add(item.ChannelId); } listForms.Add(new WatchListForm { form = RefForm, symbol = sbBitfinex.ToString(), channelId = channelList }); } else { listForms.Add(new WatchListForm { form = RefForm, symbol = sbBitfinex.ToString() }); } foreach (var item in sbBitfinex.ToString().Split(',')) { if (item != string.Empty) { var request = new webSocketListner(); request.channel = "ticker"; request.symbol = item; request._event = "subscribe"; var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(request); jsonString = jsonString.Replace("_event", "event"); webSocket.Send(jsonString); } } } else { RefForm.Invoke((Action) delegate() { RefForm.dataGridMarketData.DataSource = ObjTrading; }); } }
public void AddSymbolTxtFile(dynamic form, dynamic txtAddRow) { string symbols = string.Empty; using (var streamReader = new StreamReader(form.Name + ".txt")) { symbols = streamReader.ReadLine(); streamReader.Close(); } if (symbols == null) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(form.Name + ".txt", true)) { file.Write(txtAddRow.Text.ToUpper()); file.Close(); } if (txtAddRow.Text.ToLower().IndexOf("bitfinex") > -1) { List <int> channel = new List <int>(); var checkmapping = list.Where(m => m.Symbol == "t" + txtAddRow.Text.Split('.')[1].ToUpper()).FirstOrDefault(); if (checkmapping != null) { channel.Add(checkmapping.ChannelId); } else { checkmapping = list.Where(m => m.Symbol == "f" + txtAddRow.Text.Split('.')[1].ToUpper()).FirstOrDefault(); if (checkmapping != null) { channel.Add(checkmapping.ChannelId); } } listForms.Add(new WatchListForm { form = form, symbol = txtAddRow.Text.ToUpper(), channelId = channel }); var request = new webSocketListner(); request.channel = "ticker"; request.symbol = txtAddRow.Text.Split('.')[1].ToUpper(); request._event = "subscribe"; //listWebList.Add(request); var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(request); jsonString = jsonString.Replace("_event", "event"); webSocket.Send(jsonString); } } else if (!symbols.Contains(txtAddRow.Text.ToUpper())) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(form.Name + ".txt", true)) { file.Write("," + txtAddRow.Text.ToUpper()); file.Close(); } using (var streamReader = new StreamReader(form.Name + ".txt")) { symbols = streamReader.ReadLine(); streamReader.Close(); } // listForms.Add(new WatchListForm { form = form, symbol = sbBitfinex.ToString() }); if (txtAddRow.Text.ToLower().IndexOf("bitfinex") > -1) { var checkmapping = list.Where(m => m.Symbol == "t" + txtAddRow.Text.Split('.')[1].ToUpper()).FirstOrDefault(); int channel = 0; if (checkmapping != null) { channel = checkmapping.ChannelId; } else { checkmapping = list.Where(m => m.Symbol == "f" + txtAddRow.Text.Split('.')[1].ToUpper()).FirstOrDefault(); if (checkmapping != null) { channel = checkmapping.ChannelId; } } comman.Seprateticklers(symbols, ref sbBitfinex, ref sbTraders, ref sbIGMarket, ref sbICMarket); var checkForm = listForms.Where(m => m.form == form).FirstOrDefault(); if (checkForm != null) { checkForm.symbol = sbBitfinex.ToString(); checkForm.channelId.Add(channel); } var request = new webSocketListner(); request.channel = "ticker"; request.symbol = txtAddRow.Text.Split('.')[1].ToUpper(); request._event = "subscribe"; //listWebList.Add(request); var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(request); jsonString = jsonString.Replace("_event", "event"); webSocket.Send(jsonString); } } }