/// <summary>
        ///
        /// </summary>
        /// <param name="eventItem"></param>
        private void ProcessEvent(Spark.Event eventItem)
        {
            //Skip over waiting logic if quote event and ignoring quotes
            if ((IgnoreQuoteEvents) && (eventItem.Type == Spark.EVENT_QUOTE))
            {
                return;
            }

            //Raise event
            DateTime sparkEventTime = ApiFunctions.DateTimeFromUnixTimestampSeconds(eventItem.Time);

            if (sparkEventTime > _latestMarketTime)
            {
                _latestMarketTime = sparkEventTime;
            }
            RaiseEvent(new EventFeedArgs(eventItem, _latestMarketTime));

            //Wait before playing next event while replay is pause
            while ((IsPaused) && (!_isSteppingForward))
            {
                System.Threading.Thread.Sleep(100);
            }
            if (_isSteppingForward)
            {
                _isSteppingForward = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// EventFeedArgs constructor
        /// </summary>
        /// <param name="eventItem">Spark event</param>
        /// <param name="timestamp">Observation timestamp</param>
        internal EventFeedArgs(Spark.Event eventItem, DateTime timestamp)
        {
            Event     = eventItem;
            TimeStamp = timestamp;
            var adjustedValues = ApiFunctions.GetSymbolExchange(eventItem.Code, eventItem.Exchange);

            Symbol   = adjustedValues.Item1;
            Exchange = adjustedValues.Item2;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Extension method for the Spark.Event struct that converts a Spark event into LimitOrder that can be submitted
        /// into the LimitOrderBook
        /// </summary>
        /// <param name="eventItem">Spark event</param>
        internal static LimitOrder ToLimitOrder(this Spark.Event eventItem)
        {
            MarketSide side      = ApiFunctions.GetMarketSide(eventItem.Flags);
            int        price     = eventItem.Price;
            int        volume    = (int)eventItem.Volume;
            DateTime   timeStamp = DateTimeFromUnixTimestampSeconds(eventItem.Time);

            return(new LimitOrder(side, price, volume, timeStamp));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Return that date that Spark considers the current day using current day request method and getting first event
        /// </summary>
        public static DateTime GetCurrentSparkDate()
        {
            DateTime result = DateTime.Today;

            ApiControl.Instance.Connect();
            Spark.Exchange exchange;
            if (ApiFunctions.GetSparkExchange("ASX", out exchange))
            {
                result = DateTimeFromUnixTimestampSeconds(exchange.Date);
            }
            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Convert Spark.Event struct into tab-separted human readable string
 /// </summary>
 /// <param name="eventItem">Spark event item</param>
 internal static string ToOutputString(this Spark.Event eventItem)
 {
     System.Text.StringBuilder result = new StringBuilder();
     result.Append(DateTimeFromUnixTimestampSeconds(eventItem.Time).ToMarketDateTime() + "\t");
     result.Append(Spark.EventTypeToStr(eventItem.Type) + "\t");
     result.Append(eventItem.Code + "\t");
     result.Append(eventItem.Exchange + "\t");
     result.Append(ApiFunctions.GetMarketSide(eventItem.Flags).ToString() + "\t");
     result.Append(eventItem.Price.ToPriceString() + "\t");
     result.Append(eventItem.Volume + "\t");
     result.Append(Spark.ConditionCodesToStr(eventItem.ConditionCodes, eventItem.Exchange) + "\t");
     result.Append(eventItem.Flags + "\t");
     result.Append(Spark.StateToStr(eventItem.State) + "\t");
     result.Append(eventItem.Position + "\t");
     result.Append(Spark.QuoteBasesToStr(eventItem.QuoteBases, eventItem.Exchange) + "\t");
     result.Append(eventItem.Reference + "\t");
     result.Append(eventItem.Count + "\t");
     return(result.ToString());
 }
Ejemplo n.º 6
0
        /// <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);
        }