예제 #1
0
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (nameof(StartOrchestratingAccount).Equals(reminderName))
     {
         await StartOrchestratingAccount();
     }
 }
예제 #2
0
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (reminderName == PreviewReminder)
     {
         await UpdatePreviewImageAsync();
     }
 }
        public override void OnUpdate(TickStatus args)
        {
            /*if (HistoryDataSeries.Count - 1 < period)
             *  return;*/

            a1 = Mov(PriceType.Close, period, MAMode.EMA);

            a2 = a1.GetValueByIndex(0) - (a1.GetValueByIndex(0) * percentage / 100);

            a3 = a1.GetValueByIndex(0) + (a1.GetValueByIndex(0) * percentage / 100);

            // Both custom series is required to be supplied by value for the algorithm
            b1.GetValue(a1.GetValueByIndex(0));

            b2.GetValue(a1.GetValueByIndex(0));

            var k1 = Cross(a1, Ref(b2, 1));

            var k2 = Cross(Ref(b1, 1), a1);

            //Search index example of a logical cross over condition based on operation input and variable relations

            //BarsSince(a1, InstrumentsManager.Current.DayInfo.PrevClose, Operation.Less<double>());

            var s1 = BarsSince(k1) < BarsSince(k2);
            var s2 = s1 ? b1 : b2;

            Lines["a1"].SetValue(a1.GetValueByIndex(0));

            Lines["s2"].SetValue(s2.GetValueByIndex(0));
        }
        public override void Update(TickStatus args)
        {
            if (args != TickStatus.IsQuote && HistoryDataSeries.Count - 1 > 0)
            {
                var message         = "";
                var _isInside       = isInside();
                var isInsideBarMade = _isInside == bullishBar || _isInside == bearishBar;

                if (isInsideBarMade)
                {
                    message = "Inside Bar came up!";
                }

                if (_isInside == bullishBar)
                {
                    DrawBarStamp(Lines["bullish bar"].Color, PrimitiveFigure.TriangleUp, false, 20);
                }

                if (_isInside == bearishBar)
                {
                    DrawBarStamp(Lines["bearish bar"].Color, PrimitiveFigure.TriangleDown, true, 20);
                }

                Notification.Print(message);
            }
        }
예제 #5
0
        public async Task ReceiveReminder(string reminderName, TickStatus status)
        {
            var data     = reminderName.Split('|');
            var id       = data[0];
            var type     = data[1];
            var fullName = this.GetPrimaryKeyString();

            if (type.Equals(CompensateType.Clear.ToString()))
            {
                if (!await this.ServiceProvider.GetRequiredServiceByName <IElasticsearchStorage>(fullName).ClearAsync(id))
                {
                    this._logger.LogInformation($"{fullName} {reminderName} Compensate clear filed");
                    return;
                }
            }
            else
            {
                if (!await this.ServiceProvider.GetRequiredServiceByName <IElasticsearchStorage>(fullName).RefreshAsync(id))
                {
                    this._logger.LogInformation($"{fullName} {reminderName} Compensate refresh filed");
                    return;
                }
            }
            if (reminder == null)
            {
                reminder = await this.GetReminder(reminderName);
            }
            if (reminder != null)
            {
                await this.UnregisterReminder(reminder);
            }
            return;
        }
예제 #6
0
        async Task IRemindable.ReceiveReminder(string reminderName, TickStatus status)
        {
            _logger.Info($"Reminder {reminderName} received a reminder");

            var tasks = new List <Task <decimal> >();
            // TODO: maybe inventory can just expose a list of products that need to be replenished
            var inventories = await GrainFactory.GetGrain <IInventories>(Guid.Empty).GetAll();

            foreach (var inventory in inventories)
            {
                IInventory gi = null;

                foreach (var stock in inventory.ProductsStocks)
                {
                    var qty = stock.Value.SupplyingRequiredQuantity;
                    if (qty > 0)
                    {
                        var productGuid = stock.Key;

                        _logger.Info($"Inventory increase required for product {productGuid} for {qty} (safety stock {stock.Value.SafetyStockQuantity} + already booked {stock.Value.BookedQuantity} - currently in stock {stock.Value.CurrentStockQuantity})");

                        if (gi == null)
                        {
                            gi = GrainFactory.GetGrain <IInventory>(inventory.Id);
                        }
                        var increaseTask = gi.Increase(productGuid, qty);
                        tasks.Add(increaseTask);
                    }
                }
            }
            await Task.WhenAll(tasks);

            _logger.Info($"Reminder {reminderName} completed");
        }
예제 #7
0
            protected override TickStatus OnTick()
            {
                TickStatus tickStatus = TickStatus.Finish;

                if (CheckIndexValid(0))
                {
                    NodeBase child = m_children[0];
                    tickStatus = child.Tick();

                    if (tickStatus == TickStatus.Finish)
                    {
                        if (m_loopCount != m_infiniteLoop)
                        {
                            // 有限循环
                            ++m_currentCount;
                            if (m_currentCount < m_loopCount) // AI分享站 C++版是 ==
                            {
                                tickStatus = TickStatus.Executing;
                            }
                        }
                        else
                        {
                            // 无限循环
                            tickStatus = TickStatus.Executing;
                        }
                    }
                }

                if (tickStatus != TickStatus.Executing)
                {
                    m_currentCount = 0;
                }

                return(tickStatus);
            }
예제 #8
0
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (nameof(StartImportAsync).Equals(reminderName))
     {
         await StartImportAsync();
     }
 }
        async Task IRemindable.ReceiveReminder(string reminderName, TickStatus status)
        {
            _logger.Info($"Reminder {reminderName} received a reminder");

            // TODO: maybe inventory can just expose a list of products that need to be replenished
            var inventories = await GrainFactory.GetGrain <IInventories>(Guid.Empty).GetAll();

            foreach (var inventoryGuid in inventories)
            {
                IInventory gi    = GrainFactory.GetGrain <IInventory>(inventoryGuid);
                var        state = await gi.GetState();

                foreach (var stock in state.ProductsStocks)
                {
                    var qty = stock.Value.SupplyingRequiredQuantity;
                    if (qty > 0)
                    {
                        var productGuid = stock.Key;

                        _logger.Info($"Inventory increase required for product {productGuid} for {qty} (safety stock {stock.Value.SafetyStockQuantity} + already booked {stock.Value.BookedQuantity} - currently in stock {stock.Value.CurrentStockQuantity})");

                        await gi.Increase(productGuid, qty);

                        var currentStockRemaining = (await gi.GetProductState(productGuid)).CurrentStockQuantity;
                    }
                }
            }

            _logger.Info($"Reminder {reminderName} completed");
        }
예제 #10
0
        public override void Update(TickStatus args)
        {
            if (args != TickStatus.IsQuote)
            {
                ci.Insert(0, 0);
                hlc3.Insert(0, 0);
                absD.Insert(0, 0);

                hlc3[0] = HLC3(0);

                absD[0] = Math.Abs(HLC3(0) - esa.GetValue(0));
                ci[0]   = CI(0);
                EMA(0, ci, AveragePeriod);
                Lines[0].SetValue(ci[0]);
                Lines[1].SetValue(wt2.GetValue());
                Clouds[0].Set(ci[0] - wt2.GetValue(), 0.0001);

                if (Lines[0].GetValue() < Lines[1].GetValue() && Lines[0].GetValue(1) >= Lines[1].GetValue(1) && Lines[0].GetValue() > Thresholds[0].Level)
                {
                    BarStamps.Set(new BarStampPrimitiveFigure(Color.Red, 0, Lines[0].GetValue(), PrimitiveFigure.TriangleDown));
                }

                if (Lines[0].GetValue() > Lines[1].GetValue() && Lines[0].GetValue(1) <= Lines[1].GetValue(1) && Lines[0].GetValue() < Thresholds[2].Level)
                {
                    BarStamps.Set(new BarStampPrimitiveFigure(Color.LimeGreen, 0, Lines[0].GetValue(), PrimitiveFigure.TriangleUp));
                }
            }
        }
 public async Task FireAllReminders(TickStatus tickStatus)
 {
     foreach (var reminderName in _reminders.Keys)
     {
         await _grain.ReceiveReminder(reminderName, tickStatus);
     }
 }
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (reminderName == "cleanup")
     {
         await Cleanup();
     }
 }
예제 #13
0
        /// <summary>
        /// Entry point. This function is called when new quote comes or new bar created
        /// </summary>
        public override void Update(TickStatus args)
        {
            if (HistoryDataSeries.Count < 80)
            {
                return;
            }

            if (args != TickStatus.IsQuote)
            {
                patternFormation = new List <PatternFormation>();

                patternFormation.Add(new PatternFormation(cdlKeyReversal(), Lines["cdlKeyReversalDown"].Color));
                patternFormation.Add(new PatternFormation(cdl3DayCompression(), Lines["cdl3DayCompression"].Color));
                patternFormation.Add(new PatternFormation(cdlIslandReversal(), Lines["cdlIslandReversal"].Color));
                patternFormation.Add(new PatternFormation(cdlOutsideDay(), Lines["cdlOutsideDay"].Color));
                patternFormation.Add(new PatternFormation(cdlWideRangeDays(), Lines["cdlWideRangeDays"].Color));
                patternFormation.Add(new PatternFormation(cdlGapOpening(), Lines["cdlGapOpening"].Color));

                var lastFormation = patternFormation.Where(x => x.Direction != TradeDirection.None).LastOrDefault();

                var value = lastFormation.Direction == TradeDirection.Buy ? GetLow(1) - HistoryDataSeries.HistoricalRequest.Instrument.MinimalTickSize * 100D : GetHigh(1) + HistoryDataSeries.HistoricalRequest.Instrument.MinimalTickSize * 100D;

                var figure = lastFormation.Direction == TradeDirection.Buy ? PrimitiveFigure.TriangleUp : PrimitiveFigure.TriangleDown;

                BarStamps.Set(new BarStampPrimitiveFigure(lastFormation.Color, 1, value, figure));
            }
        }
예제 #14
0
 public void Update(GameTime gameTime)
 {
     foreach (BehaviorTree bt in this.behaviorTrees)
     {
         if (bt.Enabled && bt.Blackboard.Owner.Enabled)
         {
             if (bt.MilisecondsTillLastTick >= this.btTickFrequency)
             {
                 bt.Tick(gameTime);
                 bt.MilisecondsTillLastTick = 0;
             }
             else
             {
                 if (bt.CurrentRunning != null)
                 {
                     TickStatus ts = bt.CurrentRunning.Tick(gameTime, out bt.CurrentRunning);
                     if (ts != TickStatus.RUNNING)
                     {
                         bt.MilisecondsTillLastTick = this.btTickFrequency;
                     }
                 }
                 else
                 {
                     bt.MilisecondsTillLastTick = this.btTickFrequency;
                 }
             }
             bt.MilisecondsTillLastTick += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
         }
     }
 }
        public override void OnUpdate(TickStatus args)
        {
            if (args != TickStatus.IsQuote)
            {
                C.GetValue(HistoryDataSeries.GetValue(PriceType.Close));
                H.GetValue(HistoryDataSeries.GetValue(PriceType.High));
                L.GetValue(HistoryDataSeries.GetValue(PriceType.Low));;

                var WH = ValueWhen(1, NW, Ref(HighestSince(1, NW, H), -1));

                var WL  = ValueWhen(1, NW, Ref(LowestSince(1, NW, L), -1));
                var WCL = ValueWhen(1, NW, Ref(C, -1));
                var BP  = (WH + WL + WCL) / 3;
                var D   = ((WH - WL) / 2) + BP;
                var B   = BP - ((WH - WL) / 2);
                var D1  = (WH - WL) + BP;
                var B1  = BP - (WH - WL);
                var SB1 = BP - ((WH - WL) * 1.0618);
                var SB2 = BP - ((WH - WL) * 0.98382);
                var RB1 = ((WH - WL) * 1.0618) + BP;
                var RB2 = ((WH - WL) * 0.98382) + BP;

                Lines["RB2"].SetValue(RB2);
                Lines["RB1"].SetValue(RB1);
                Lines["D1"].SetValue(D1);
                Lines["D"].SetValue(D);
                Lines["BP"].SetValue(BP);
                Lines["B"].SetValue(B);
                Lines["B1"].SetValue(B1);
                Lines["SB1"].SetValue(SB1);
                Lines["SB2"].SetValue(SB2);
            }
        }
예제 #16
0
            protected override TickStatus OnTick()
            {
                TickStatus status = TickStatus.Finish;

                // 从curIndex和lastIndex中选出可用的,赋值给lastIndex
                if (m_selectIndex != m_newSelectIndex)
                {
                    if (CheckIndexValid(m_selectIndex))
                    {
                        NodeBase child = m_children[m_selectIndex];
                        child.Transition();
                    }

                    m_selectIndex = m_newSelectIndex;
                }

                if (CheckIndexValid(m_selectIndex))
                {
                    NodeBase child = m_children[m_selectIndex];
                    status = child.Tick();

                    if (status == TickStatus.Finish)
                    {
                        m_selectIndex = Global.InvalidNodeIndex;
                    }
                }

                return(status);
            }
예제 #17
0
        public async Task ReceiveReminder(string reminderName, TickStatus status)
        {
            Print("Reminder received I have: {0}", BallListToString(State.BallIds));
            switch (reminderName)
            {
            case Statics.Values.PassReminderName:
                if (State.BallIds.Count == 1)
                {
                    await HoldOrPassBall();
                }
                else if (State.BallIds.Count > 1)
                {
                    await PassOtherBalls();
                    await HoldOrPassBall();
                }
                StartOrRestartPass();
                break;

            default:
                break;
            }
            if (State.BallIds.Count == 0)
            {
                await OnDeactivateAsync();
            }
        }
 public override void Update(TickStatus args)
 {
     if (!loadData)
     {
         HistoricalDataManager.Get(HistoryDataSeries.HistoricalRequest, new Interval(barData.GetTimeUtc(), DateTime.UtcNow));
         loadData = true;
     }
 }
 public Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (_timer == null)
     {
         _timer = this.RegisterTimer(RunOptimizer, null, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(20));
     }
     return TaskDone.Done;
 }
예제 #20
0
 public Task ReceiveReminder(string reminderName, TickStatus status)
 {
     Console.WriteLine("-------------------------");
     Console.WriteLine("5 min Reminder triggered!");
     Console.WriteLine("-------------------------");
     WriteStateAsync();
     return(Task.CompletedTask);
 }
 public Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (_timer == null)
     {
         _timer = this.RegisterTimer(RunOptimizer, null, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(20));
     }
     return(TaskDone.Done);
 }
예제 #22
0
        public override void Update(TickStatus args)
        {
            if (args != TickStatus.IsQuote)
            {
                DataSeriesManager.AutoUpdate();
            }

            this.OnUpdate(args);
        }
        public Task FireReminder(string reminderName, TickStatus tickStatus)
        {
            if (!_reminders.ContainsKey(reminderName))
            {
                throw new ArgumentException($"No reminder named {reminderName} found");
            }

            return(_grain.ReceiveReminder(reminderName, tickStatus));
        }
예제 #24
0
        public Task ReceiveReminder(string reminderName, TickStatus status)
        {
            if ("GrainReminder".Equals(reminderName))
            {
                Console.WriteLine("Hello Reminder");
            }

            return(Task.CompletedTask);
        }
예제 #25
0
        public static Task FireAllReminders(this TestKitSilo silo, TickStatus tickStatus = default)
        {
            if (silo == null)
            {
                throw new ArgumentNullException(nameof(silo));
            }

            return(silo.ReminderRegistry.FireAllReminders(tickStatus));
        }
예제 #26
0
        async Task IRemindable.ReceiveReminder(string reminderName, TickStatus status)
        {
            if (actor == null)
            {
                await Activate(ActorPath.From(IdentityOf(this)));
            }

            Debug.Assert(actor != null);
            await actor.OnReminder(reminderName);
        }
예제 #27
0
        async Task IRemindable.ReceiveReminder(string reminderName, TickStatus status)
        {
            if (actor == null)
                await Activate(ActorPath.Deserialize(IdentityOf(this)));

            Debug.Assert(actor != null);
            KeepAlive();

            await actor.OnReminder(reminderName);
        }
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (string.Equals(ReminderName, reminderName, StringComparison.Ordinal))
     {
         if (!string.IsNullOrEmpty(this.reminder))
         {
             await this.PublishReminderAsync(this.reminder).ConfigureAwait(true);
         }
     }
 }
예제 #29
0
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (string.Equals(ReminderName, reminderName, StringComparison.Ordinal))
     {
         if (!string.IsNullOrEmpty(_reminder))
         {
             await PublishReminder(_reminder);
         }
     }
 }
예제 #30
0
            protected virtual TickStatus OnExecute()
            {
                TickStatus tickStatus = TickStatus.Finish;

                if (m_dyOnExecute != null)
                {
                    tickStatus = m_dyOnExecute();
                }

                return(tickStatus);
            }
예제 #31
0
 public async Task ReceiveReminder(string reminderName, TickStatus status)
 {
     if (reminderName == "reminder1")
     {
         await Task.Factory.StartNew(() =>
         {
             _value++;
             Console.WriteLine($"{status.CurrentTickTime:HH:mm:ss.ffff} - New value is {_value}");
         });
     }
 }
예제 #32
0
        async Task IRemindable.ReceiveReminder(string name, TickStatus status)
        {
            KeepAlive();

            if (name == StickyReminderName)
            {
                return;
            }

            await invoker.OnReminder(instance, name);
        }
예제 #33
0
        public Task ReceiveReminder(string reminderName, TickStatus status)
        {
            // it can happen that due to failure, when a new activation is created, 
            // it doesn't know which reminders were registered against the grain
            // hence, this activation may receive a reminder that it didn't register itself, but
            // the previous activation (incarnation of the grain) registered... so, play it safe
            if (!sequence.ContainsKey(reminderName))
            {
                // allReminders.Add(reminderName, r); // not using allReminders at the moment
                //counters.Add(reminderName, 0);
                sequence.Add(reminderName, 0); // we'll get upto date to the latest sequence number while processing this tick
            }

            // calculating tick sequence number

            // we do all arithmetics on DateTime by converting into long because we dont have divide operation on DateTime
            // using dateTime.Ticks is not accurate as between two invocations of ReceiveReminder(), there maybe < period.Ticks
            // if # of ticks between two consecutive ReceiveReminder() is larger than period.Ticks, everything is fine... the problem is when its less
            // thus, we reduce our accuracy by ACCURACY ... here, we are preparing all used variables for the given accuracy
            long now = status.CurrentTickTime.Ticks / ACCURACY; //DateTime.UtcNow.Ticks / ACCURACY;
            long first = status.FirstTickTime.Ticks / ACCURACY;
            long per = status.Period.Ticks / ACCURACY;
            long sequenceNumber = 1 + ((now - first) / per);

            // end of calculating tick sequence number

            // do switch-ing here
            if (sequenceNumber < sequence[reminderName])
            {
                logger.Info("ReceiveReminder: {0} Incorrect tick {1} vs. {2} with status {3}.", reminderName, sequence[reminderName], sequenceNumber, status);
                return TaskDone.Done;
            }

            sequence[reminderName] = sequenceNumber;
            logger.Info("ReceiveReminder: {0} Sequence # {1} with status {2}.", reminderName, sequence[reminderName], status);

            string fileName = GetFileName(reminderName);
            string counterValue = sequence[reminderName].ToString(CultureInfo.InvariantCulture);
            File.WriteAllText(fileName, counterValue);

            return TaskDone.Done;
        }
예제 #34
0
        async Task IRemindable.ReceiveReminder(string reminderName, TickStatus status)
        {
            KeepAlive();

            await actor.OnReminder(reminderName);
        }