/// <summary> /// Creates a Spark.Stock reference for the specified security and exchange. /// </summary> /// <param name="exchangeId">Security exchange</param> /// <param name="exchange">Exchange reference generated by the method</param> /// <returns>TRUE if Spark was able to create the specified exchange reference, else FALSE</returns> internal static bool GetSparkExchange(string exchangeId, out Spark.Exchange exchange) { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Creating rreference to Spark exchange '" + exchangeId + "'..."); exchange = new Spark.Exchange(); if (!Spark.GetExchange(ref exchange, exchangeId)) { string error = Spark.DescribeError(Spark.GetLastError()); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Creating rreference to Spark exchange '" + exchangeId + "' failed: " + error); return(false); } else { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Creating rreference to Spark exchange '" + exchangeId + "' complete"); return(true); } }
/// <summary> /// Open connection to Spark API /// </summary> /// <returns></returns> internal bool Connect() { bool result = true; lock (_syncLock) { try { if (ConnectionStatus == SparkConnectionStatus.Disconnected) { //Instance Spark object Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Initiating Spark connection..."); Initialise(); //Connect to Spark server ApiCredentials credentials = ApiCredentials.LoadFromFile(); if (credentials == null) { throw new ApplicationException("Spark API security credentials not available"); } Spark.SetLogin(credentials.Username, credentials.Password); if (!Spark.Connect()) { Debug.WriteLine("Can't connect: {0}", Spark.DescribeError(Spark.GetLastError())); result = false; } Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Spark connection initiated"); //Wait to allow Spark API to data access System.Threading.Thread.Sleep(1000); } } catch (Exception ex) { Debug.WriteLine("ERROR: APIControl - ", ex.Message); result = false; } } return(result); }
/// <summary> /// Creates a Spark.Stock reference for the specified security and exchange. /// </summary> /// <param name="symbol">Security symbol</param> /// <param name="exchange">Security exchange</param> /// <param name="stock">Stock reference generated by the method</param> /// <returns>TRUE if Spark was able to create the specified stock, else FALSE</returns> internal static bool GetSparkStock(string symbol, string exchange, out Spark.Stock stock) { //Get internal spark security symbol Tuple <string, string> sparkSymbolExchange = ApiFunctions.GetSparkSymbolExchange(symbol, exchange); //Get reference to stock string identifier = sparkSymbolExchange.Item1 + "." + sparkSymbolExchange.Item2; Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + "\t" + "Initiating event feed for " + identifier); stock = new Spark.Stock(); if (!Spark.GetStock(ref stock, sparkSymbolExchange.Item1, sparkSymbolExchange.Item2)) { Console.WriteLine("Can't get {0}: {1}", identifier, Spark.DescribeError(Spark.GetLastError())); return(false); } //Wait to allow Spark API to data access System.Threading.Thread.Sleep(1000); return(true); }