void Connect() { try { this.Log("Quote Feed Client initialization"); this.quoteClient = new QuoteStore("QuotesDownloader", port: Convert.ToInt32(this.m_port.Text), validateClientCertificate: (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true); this.quoteClient.LoginResultEvent += new QuoteStore.LoginResultDelegate(this.OnLogon); this.quoteClient.LogoutEvent += new QuoteStore.LogoutDelegate(this.OnLogout); this.quoteClient.DisconnectEvent += new QuoteStore.DisconnectDelegate(this.OnDisconnect); this.quoteClient.SymbolListResultEvent += new QuoteStore.SymbolListResultDelegate(this.OnSymbolInfo); this.Log("Connecting..."); this.quoteClient.Connect(this.m_address.Text, 5000); this.quoteClient.Login(this.m_username.Text, this.m_password.Text, "", "", "", 5000); } catch (TimeoutException ex) { MessageBox.Show("Connection timeout", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Disconnect(); return; } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Disconnect(); return; } this.ApplyConnectingState(); quoteClient.GetSymbolList(-1); }
//todo //1. search by index - DONE //2. add - DONE //3. random - DONE //4. multiline display - DONE //5. search by text - DONE //6. delete - DONE //7. help - DONE //8. popularity - DONE //9. multiline submission //10. browse by text (random quote with search term in it) - DONE //11. multiple person deletion - DONE public Quote(IrcClient irc) { _irc = irc; _store = new QuoteStore(_storeFileName); _quotes = _store.Load(); _rng = new Random((int)DateTime.Now.Ticks); _last20QuoteIds = new List<int>(); }
void OnLogon(QuoteStore quoteFeedClient, object sender) { if (this.InvokeRequired) { this.InvokeInPrimaryThread(OnLogon, quoteFeedClient, sender); return; } this.Log("Quote Feed Client is connected"); }
public Downloader(QuoteStore quoteClient, string outputType, String location, String symbol, DateTime from, DateTime to, Boolean includeLevel2) : this() { this.quoteClient = quoteClient; this.outputType = outputType; this.location = location; this.symbol = symbol; this.from = from; this.to = to; this.includeLevel2 = includeLevel2; }
public Downloader(QuoteStore quoteClient, string outputType, String location, String symbol, DateTime from, DateTime to, PriceType priceType, BarPeriod period) : this() { this.quoteClient = quoteClient; this.outputType = outputType; this.location = location; this.symbol = symbol; this.from = from; this.to = to; this.priceType = priceType; this.period = period; }
public void OneQuoteTest() { var q = new Quote { Symbol = "EURUSD", Price = 1.0m }; var store = new QuoteStore(); store.PushQuote(q); var market = store.GetCurrentMarket(); Assert.AreEqual(1, market.Count); Assert.AreEqual("EURUSD", market[0].Symbol); Assert.AreEqual(1.0, market[0].Price); }
public void OnLogout(QuoteStore quoteFeedClient, LogoutInfo info) { if (this.InvokeRequired) { this.InvokeInPrimaryThread(OnLogout, quoteFeedClient, info); return; } try { Console.WriteLine("Logout : " + info.Message); } catch (Exception exception) { Console.WriteLine("Error : " + exception.Message); } }
void OnDisconnect(QuoteStore quoteFeedClient, string text) { if (this.InvokeRequired) { this.InvokeInPrimaryThread(OnDisconnect, quoteFeedClient, text); return; } try { Console.WriteLine("Disconnected : " + text); } catch (Exception exception) { Console.WriteLine("Error : " + exception.Message); } }
public void ResetChangesTest1() { var q = new Quote { Symbol = "EURUSD", Price = 1.0m }; var store = new QuoteStore(); store.PushQuote(q); q.Price = 2.0m; store.PushQuote(q); store.ResetChanges(); var market = store.GetChanges(); Assert.AreEqual(0, market.Count); }
void OnSymbolInfo(QuoteStore quoteFeedClient, object sender, string[] symbols) { if (this.InvokeRequired) { this.InvokeInPrimaryThread(OnSymbolInfo, quoteFeedClient, sender, symbols); return; } this.m_checkedListBox.Items.Clear(); foreach (var symbol in symbols) { this.m_checkedListBox.Items.Add(symbol); _symbols.Add(symbol, false); } this.Log("Symbols information is received"); this.ApplyConnectedState(); }
public void GetChangesTest1() { var q = new Quote { Symbol = "EURUSD", Price = 1.0m }; var store = new QuoteStore(); store.PushQuote(q); q.Price = 2.0m; store.PushQuote(q); var market = store.GetChanges(); Assert.AreEqual(1, market.Count); Assert.AreEqual("EURUSD", market[0].Symbol); Assert.AreEqual(2.0, market[0].Price); }
public void GetChangesTest3() { var q1 = new Quote { Symbol = "EURUSD", Price = 1.0m }; var q2 = new Quote { Symbol = "EURUSD", Price = 2.0m }; var store = new QuoteStore(); store.PushQuote(q1); store.PushQuote(q2); var market = store.GetChanges(); Assert.AreEqual(1, market.Count); Assert.IsTrue(market.Any(quote => quote.Symbol == "EURUSD" && quote.Price == 2.0m)); }
void Disconnect() { try { this.Log("Disconnecting..."); if (quoteClient != null) { this.quoteClient.Disconnect("Disconnecting"); this.quoteClient.Dispose(); this.quoteClient = null; } this.Log("Quote Feed Client is disconnected"); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } this.ApplyDisconnectedState(); }
public void SomeQuotesTest() { var q1 = new Quote { Symbol = "EURUSD", Price = 1.0m }; var q2 = new Quote { Symbol = "USDJPY", Price = 2.0m }; var store = new QuoteStore(); store.PushQuote(q1); store.PushQuote(q2); var market = store.GetCurrentMarket(); Assert.AreEqual(2, market.Count); Assert.IsTrue(market.Any(quote => quote.Symbol == "EURUSD" && quote.Price == 1.0m)); Assert.IsTrue(market.Any(quote => quote.Symbol == "USDJPY" && quote.Price == 2.0m)); }
public static void ConsoleMain(string[] args) { if (AllocConsole()) { var ptr = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, 3, 0, IntPtr.Zero); if (!SetStdHandle(-11, ptr)) { throw new Exception("Failed to set handle."); } var newOut = new StreamWriter(Console.OpenStandardOutput()); newOut.AutoFlush = true; Console.SetOut(newOut); Console.SetError(newOut); try { bool help = false; string address = "ttlive.fxopen.com"; string login = "******"; string password = "******"; int port = 5050; var to = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day); to = to.AddDays(-7); var from = to.AddDays(-7); string symbol = "EURUSD"; string periodicity = "H1"; PriceType priceType = PriceType.Bid; bool bars = false; bool ticks = false; bool level2 = false; bool verbose = false; string outputType = "text"; var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); path = Path.Combine(path, "Quotes"); Directory.CreateDirectory(path); string location = path; var options = new OptionSet() { { "a|address=", v => address = v }, { "u|username="******"w|password="******"p|port=", v => port = int.Parse(v) }, { "h|?|help", v => help = v != null }, { "t|dateto=", v => to = DateTime.Parse(v) }, { "f|datefrom=", v => from = DateTime.Parse(v) }, { "s|symbol=", v => symbol = v }, { "d|periodicity=", v => periodicity = v }, { "o|output=", v => outputType = v }, { "l|location=", v => location = v }, { "v|verbose=", v => verbose = bool.Parse(v) }, { "r|request=", v => { switch (v.ToLowerInvariant()) { case "bids": priceType = PriceType.Bid; bars = true; break; case "asks": priceType = PriceType.Ask; bars = true; break; case "ticks": ticks = true; break; case "level2": level2 = true; break; default: throw new Exception("Unknown request type: " + v); } } }, }; try { options.Parse(args); } catch (OptionException e) { Console.Error.WriteLine(e.Message); Console.WriteLine("Try `QuotesDownloader --help' for more information."); return; } if (help) { Console.WriteLine("QuotesDownloader usage:"); options.WriteOptionDescriptions(Console.Out); Console.ReadKey(); return; } var client = new QuoteStore("QuotesDownloader", port: port, validateClientCertificate: (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true); client.Connect(address, -1); client.Login(login, password, "", "", "", -1); if (verbose) { Console.WriteLine("The Quote Client is connected."); Console.WriteLine("Start downloading..."); } Downloader downloader; if (bars) { downloader = new Downloader(client, outputType, location, symbol, from, to, priceType, new BarPeriod(periodicity)); } else if (level2) { downloader = new Downloader(client, outputType, location, symbol, from, to, true); } else { downloader = new Downloader(client, outputType, location, symbol, from, to, false); } downloader.Start(); while (!downloader.IsFinished) { Thread.Sleep(50); } if (verbose) { Console.WriteLine("Downloading finished successfully."); } client.Disconnect("Disconnecting"); client.Dispose(); if (verbose) { Console.WriteLine("The Quote Client is disconnected."); } } catch (Exception ex) { Console.WriteLine("Error : " + ex.Message); } } Console.ReadKey(); FreeConsole(); }