private void WriteToFileHelper(string filePath) { TurnOnAllSecurityProtocolTypes(); InstrumentProfileReader reader = new InstrumentProfileReader(); InstrumentProfileWriter writer = new InstrumentProfileWriter(); IList <InstrumentProfile> profilesFromHttp = reader.ReadFromFile(dxfToolsHost, dxfToolsUser, dxfToolsPassword); Assert.Greater(profilesFromHttp.Count, 0); writer.WriteToFile(filePath, profilesFromHttp); IList <InstrumentProfile> profilesFromFile; using (FileStream inputStream = new FileStream(filePath, FileMode.Open)) { profilesFromFile = reader.Read(inputStream, filePath); } Assert.AreEqual(profilesFromHttp.Count, profilesFromFile.Count); /* NOTE: Next commented code may not performed if current instrument * format was extended with new. */ //for (int i = 0; i < profilesFromHttp.Count; i++) { // Assert.AreEqual(profilesFromHttp[i], profilesFromFile[i]); //} }
public void ReadFromHttpTest() { TurnOnAllSecurityProtocolTypes(); InstrumentProfileReader reader = new InstrumentProfileReader(); IList <InstrumentProfile> profiles = reader.ReadFromFile(dxfToolsHost, dxfToolsUser, dxfToolsPassword); Assert.Greater(profiles.Count, 0); }
private static void Main(string[] args) { if (args.Length < 7) { Console.WriteLine( "Usage: dxf_option_chain_sample <host> <user> <password> <symbol> <nStrikes> <nMonths> <price>\n" + "where\n" + " host - valid host to download instruments (https://tools.dxfeed.com/ipf)\n" + " user - user name to host access\n" + " password - user password to host access\n" + " symbol - is the product or underlying symbol (GOOG, AAPL, IBM etc)" + " nStrikes - number of strikes to print for each series" + " nMonths - number of months to print" + " price - price of the last trade" + "example: dxf_option_chain_sample https://tools.dxfeed.com/ipf demo demo AAPL 500 5 90.5\n" ); return; } var path = args[0]; var user = args[1]; var password = args[2]; var symbol = args[3]; try { var nStrikes = int.Parse(args[4]); var nMonths = int.Parse(args[5]); var price = double.Parse(args[6], CultureInfo.InvariantCulture); var reader = new InstrumentProfileReader(); //Read profiles from server var profiles = reader.ReadFromFile(path, user, password); Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count); Console.WriteLine("Building option chains ..."); IDictionary <string, OptionChain> chains = OptionChainsBuilder.Build(profiles).Chains; var chain = chains[symbol]; nMonths = Math.Min(nMonths, chain.GetSeries().Count); var seriesList = new List <OptionSeries>(chain.GetSeries()).GetRange(0, nMonths); Console.WriteLine("Printing option series ..."); foreach (var series in seriesList) { Console.WriteLine("Option series {0}", series); var strikes = series.GetNStrikesAround(nStrikes, price); Console.WriteLine("Strikes:"); foreach (var strike in strikes) { Console.Write("{0} ", strike); } Console.WriteLine(); } } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc}"); } }
private static void Main(string[] args) { if (args.Length == 0) { PrintUsage(); return; } var path = args[0]; var user = string.Empty; var password = string.Empty; var token = string.Empty; const string ZIP_FILE_PATH = "profiles.zip"; try { var reader = new InstrumentProfileReader(); IList <InstrumentProfile> profiles; if (IsFilePath(path)) { //Read profiles from local file system using (var inputStream = new FileStream(path, FileMode.Open)) { profiles = reader.Read(inputStream, path); } } else { if (args.Length >= 2) { if (args[1].Equals("-T")) { if (args.Length >= 3) { token = args[2]; } else { PrintUsage(); return; } } else { user = args[1]; if (args.Length >= 3) { password = args[2]; } } } //Read profiles from server profiles = string.IsNullOrEmpty(token) ? reader.ReadFromFile(path, user, password) : reader.ReadFromFile(path, token); } //Iterate through received profiles Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count); Console.WriteLine("Print first {0} instruments:", MaxPrintCount); for (var i = 0; i < Math.Min(profiles.Count, MaxPrintCount); i++) { Console.WriteLine("#{0}:{1}", i, profiles[i]); } if (profiles.Count > MaxPrintCount) { Console.WriteLine(" {0} instruments left...", profiles.Count - MaxPrintCount); } //Write profiles to local file system var writer = new InstrumentProfileWriter(); writer.WriteToFile(ZIP_FILE_PATH, profiles); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc}"); } }
private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine( "Usage: dxf_instrument_profile_sample <host> <user> <password>\n" + "or: dxf_instrument_profile_sample <file>\n" + "where\n" + " host - The valid host to download instruments (https://tools.dxfeed.com/ipf)\n" + " user - The user name to host access\n" + " password - The user password to host access\n" + " file - The name of file or archive (.gz or .zip) contains instrument profiles\n\n" + "example: dxf_instrument_profile_sample https://tools.dxfeed.com/ipf demo demo\n" + "or: dxf_instrument_profile_sample profiles.zip\n" ); return; } var path = args[0]; var user = string.Empty; var password = string.Empty; const string ZIP_FILE_PATH = "profiles.zip"; try { var reader = new InstrumentProfileReader(); IList <InstrumentProfile> profiles; if (IsFilePath(path)) { //Read profiles from local file system using (var inputStream = new FileStream(path, FileMode.Open)) { profiles = reader.Read(inputStream, path); } } else { if (args.Length >= 2) { user = args[1]; } if (args.Length >= 3) { password = args[2]; } //Read profiles from server profiles = reader.ReadFromFile(path, user, password); } //Iterate through received profiles Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count); Console.WriteLine("Print first {0} instruments:", MAX_PRINT_COUNT); for (var i = 0; i < Math.Min(profiles.Count, MAX_PRINT_COUNT); i++) { Console.WriteLine("#{0}:{1}", i, profiles[i]); } if (profiles.Count > MAX_PRINT_COUNT) { Console.WriteLine(" {0} instruments left...", profiles.Count - MAX_PRINT_COUNT); } //Write profiles to local file system var writer = new InstrumentProfileWriter(); writer.WriteToFile(ZIP_FILE_PATH, profiles); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc}"); } }
private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine( "Usage: dxf_ipf_connect_sample <ipf_host> <user> <password> <host:port> <events>\n" + "or: dxf_ipf_connect_sample <file> <host:port> <event>\n" + "where\n" + " ipf_host - The valid ipf host to download instruments (https://tools.dxfeed.com/ipf)\n" + " user - The user name to host access\n" + " password - The user password to host access\n" + " host:port - The address of dxfeed server (demo.dxfeed.com:7300)\n" + " events - Any of the {Profile,Quote,Trade,TimeAndSale,Summary,\n" + " TradeETH,Candle,Greeks,TheoPrice,Underlying,Series,\n" + " Configuration}\n" + " file - The name of file or archive (.gz or .zip) contains instrument profiles\n\n" + "example: dxf_ipf_connect_sample https://tools.dxfeed.com/ipf?TYPE=STOCK demo demo demo.dxfeed.com:7300 Quote,Trade\n" + "or: dxf_ipf_connect_sample https://demo:[email protected]/ipf?TYPE=STOCK demo.dxfeed.com:7300 Quote,Trade\n" + "or: dxf_ipf_connect_sample profiles.zip demo.dxfeed.com:7300 Quote,Trade\n" ); return; } var path = args[0]; var user = string.Empty; var password = string.Empty; string dxFeedAddress; EventType events; List <string> symbols; try { var reader = new InstrumentProfileReader(); IList <InstrumentProfile> profiles; var dxFeedAddressParamIndex = 1; if (IsFilePath(path)) { //Read profiles from local file system using (var inputStream = new FileStream(path, FileMode.Open)) { profiles = reader.Read(inputStream, path); } } else { if (args.Length == 5) { user = args[1]; password = args[2]; dxFeedAddressParamIndex += 2; } //Read profiles from server profiles = reader.ReadFromFile(path, user, password); } dxFeedAddress = args[dxFeedAddressParamIndex]; var eventsString = args[dxFeedAddressParamIndex + 1]; if (!Enum.TryParse(eventsString, true, out events)) { Console.WriteLine($"Unsupported event type: {eventsString}"); return; } if (profiles.Count == 0) { Console.WriteLine("There are no profiles"); return; } Console.WriteLine("Profiles from '{0}' count: {1}", path, profiles.Count); symbols = profiles.Select(profile => profile.GetSymbol()).ToList(); Console.WriteLine(value: $"Symbols: {string.Join(", ", symbols.Take(42).ToArray())}..."); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc}"); return; } Console.WriteLine($"Connecting to {dxFeedAddress} for [{events} on [{string.Join(", ", symbols.Take(42).ToArray())}...] ..."); NativeTools.InitializeLogging("dxf_ipf_connect_sample.log", true, true); using (var connection = new NativeConnection(dxFeedAddress, DisconnectHandler, ConnectionStatusChangeHandler)) { IDxSubscription subscription = null; try { subscription = connection.CreateSubscription(events, new EventPrinter()); if (events == EventType.Candle) { subscription.AddSymbols(symbols.ConvertAll(CandleSymbol.ValueOf).ToArray()); } else { subscription.AddSymbols(symbols.ToArray()); } Console.WriteLine("Press enter to stop"); Console.ReadLine(); } catch (DxException dxException) { Console.WriteLine($"Native exception occured: {dxException.Message}"); } catch (Exception exc) { Console.WriteLine($"Exception occured: {exc.Message}"); } finally { subscription?.Dispose(); } } }