Пример #1
0
        private void UpdateReaction(Update update)
        {
            if (!requestResponseMode)
            {
                if (update?.Message?.Chat != null && !chats.Exists(x => x.Id == update.Message.Chat.Id))
                {
                    chats.Add(update.Message.Chat);
                }
            }

            //обработка команд
            var commEntity = update?.Message?.Entities?.FirstOrDefault(x => x.Type == MessageEntity.EntityType.bot_command);

            if (!useOnlyBehavior)
            {
                if (commEntity != null)
                {
                    var commText = update.Message.Text.Split(' ');
                    var comm     = commText[0].Trim().Remove(0, 1);
                    if (commands.ContainsKey(comm))
                    {
                        var bag = new CommandArgs(commText.Length > 1 ? commText[1].Trim() : null, API, update.Message.Chat.Id.ToString());
                        commands[comm](bag);
                    }
                }
            }

            if (behavior != null && !requestResponseMode)
            {
                behavior.Run(update);
            }
            //если класс не используется только через поведение производим события
            if (!useOnlyBehavior)
            {
                NewUpdate?.Invoke(update, API);
                foreach (var item in ConditinalEvent)
                {
                    if (item.Key(update))
                    {
                        item.Value(update, API);
                    }
                }
                if (commEntity == null && update.Message != null)
                {
                    NewMessage?.Invoke(update.Message, API);
                }
            }
        }
Пример #2
0
        private async Task RunCupItem(CupEventArgs e)
        {
            var manager = CupClient.Instance?.GetAssociatedManager(e.Key.Type);

            if (manager == null)
            {
                return;
            }
            if (await manager.GetObjectByIdAsync(e.Key.Id) is ICupSupportedObject obj && !CupSupportedObjects.Contains(obj))
            {
                CupSupportedObjects.Add(obj);
                if (obj.IsCupUpdateAvailable)
                {
                    NewUpdate?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Пример #3
0
        public void BAllPairsData_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                var receiveddata = (BinanceStreamTick[])e.NewItems[0];
                try
                {
                    //Data Extract
                    var filteredByGroupBTC  = receiveddata.Where(y => y.Symbol.EndsWith("BTC")).ToList();
                    var filteredByGroupETH  = receiveddata.Where(y => y.Symbol.EndsWith("ETH")).ToList();
                    var filteredByGroupUSDT = receiveddata.Where(y => y.Symbol.EndsWith("USDT")).ToList();
                    var filteredByGroupBNB  = receiveddata.Where(y => y.Symbol.EndsWith("BNB")).ToList();

                    this.binance_mostliquid_btc  = filteredByGroupBTC.OrderBy(y => y.TotalTrades).ToList().GetRange(0, 5).Select(y => y.Symbol).ToList();
                    this.binance_mostliquid_eth  = filteredByGroupETH.OrderBy(y => y.TotalTrades).ToList().GetRange(0, 5).Select(y => y.Symbol).ToList();
                    this.binance_mostliquid_usdt = filteredByGroupUSDT.OrderBy(y => y.TotalTrades).ToList().GetRange(0, 5).Select(y => y.Symbol).ToList();
                    this.binance_mostliquid_bnb  = filteredByGroupBNB.OrderBy(y => y.TotalTrades).ToList().GetRange(0, 5).Select(y => y.Symbol).ToList();


                    //Median of market move
                    var liftedBTCMarketMove  = filteredByGroupBTC.Select(y => y.PriceChangePercentage).ToList().Mean();
                    var liftedETHMarketMove  = filteredByGroupETH.Select(y => y.PriceChangePercentage).ToList().Mean();
                    var liftedUSDTMarketMove = filteredByGroupUSDT.Select(y => y.PriceChangePercentage).ToList().Mean();
                    var liftedBNBMarketMove  = filteredByGroupBNB.Select(y => y.PriceChangePercentage).ToList().Mean();

                    //Market liquid

                    this.binancebtcpairmove  = liftedBTCMarketMove;
                    this.binanceethpairmove  = liftedETHMarketMove;
                    this.binanceusdtpairmove = liftedUSDTMarketMove;
                    this.binancebnbpairmove  = liftedBNBMarketMove;


                    Dictionary <string, List <BinanceStreamTick> > PairMultiValue = new Dictionary <string, List <BinanceStreamTick> >();
                    foreach (var onepair in receiveddata)
                    {
                        var    IsBTC        = onepair.Symbol.EndsWith("BTC");
                        var    IsETH        = onepair.Symbol.EndsWith("ETH");
                        var    IsUSDT       = onepair.Symbol.EndsWith("USDT");
                        var    IsXLM        = onepair.Symbol.EndsWith("BNB");
                        string BasePairName = "";
                        if (IsBTC)
                        {
                            BasePairName = onepair.Symbol.Replace("BTC", "");
                        }
                        if (IsETH)
                        {
                            BasePairName = onepair.Symbol.Replace("ETH", "");
                        }
                        if (IsUSDT)
                        {
                            BasePairName = onepair.Symbol.Replace("USDT", "");
                        }
                        if (IsXLM)
                        {
                            BasePairName = onepair.Symbol.Replace("BNB", "");
                        }

                        if (PairMultiValue.ContainsKey(BasePairName))
                        {
                        }
                        else
                        {
                            PairMultiValue.Add(BasePairName, receiveddata.Where(y => y.Symbol.StartsWith(BasePairName)).ToList());
                        }
                    }

                    NewUpdate?.Invoke(this, new MarketEventArg(this, MarketAssetUpdateType.All, MarketAssetClass.All));
                }
                catch
                {
                }
            }
        }
Пример #4
0
 protected virtual void OnNewUpdate()
 {
     NewUpdate?.Invoke(this, EventArgs.Empty);
 }