Ejemplo n.º 1
0
        public override void Execute(QCAlgorithmFramework algorithm, IPortfolioTarget[] targets)
        {
            HttpWebRequest request;

            request             = (HttpWebRequest)WebRequest.Create(Config.Get("slack-hook"));
            request.Method      = "POST";
            request.ContentType = "application/json";
            string payload = "{\"text\": \"has " + targets.Length + " targets.\"}";
            Stream stream  = request.GetRequestStream();

            stream.Write(payload.GetBytes(), 0, payload.Length);
            stream.Close();

            algorithm.Log("NOTIFY_SLACK >> " + payload);

            //Get response as a stream:
            try
            {
                var response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    algorithm.Log("DEBUG ++++>>" + targets.Length);
                }
            }
            catch (Exception ex)
            {
                algorithm.Error(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event fired each time the we add/remove securities from the data feed
        /// </summary>
        /// <param name="algorithm">The algorithm instance that experienced the change in securities</param>
        /// <param name="changes">The security additions and removals from the algorithm</param>
        public override void OnSecuritiesChanged(QCAlgorithmFramework algorithm, SecurityChanges changes)
        {
            // added
            foreach (var added in changes.AddedSecurities)
            {
                SymbolData symbolData;
                if (!_symbolDataBySymbol.TryGetValue(added.Symbol, out symbolData))
                {
                    // add symbol/symbolData pair to collection
                    symbolData = new SymbolData(_rangePeriod, _consolidatorTimeSpan)
                    {
                        Symbol = added.Symbol,
                        K1     = _k1,
                        K2     = _k2
                    };

                    _symbolDataBySymbol[added.Symbol] = symbolData;

                    //register consolidator
                    algorithm.SubscriptionManager.AddConsolidator(added.Symbol, symbolData.GetConsolidator());
                }
            }

            // removed
            foreach (var removed in changes.RemovedSecurities)
            {
                SymbolData symbolData;
                if (_symbolDataBySymbol.TryGetValue(removed.Symbol, out symbolData))
                {
                    // unsibscribe consolidator from data updates
                    algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, symbolData.GetConsolidator());

                    // remove item from dictionary collection
                    if (!_symbolDataBySymbol.Remove(removed.Symbol))
                    {
                        algorithm.Error("Unable to remove data from collection: DualThrustAlphaModel");
                    }
                }
            }
        }