private void GetTeleSubscriptionCommand(string s, WebSocketIncomingMessage im)
 {
     Send(
         s,
         im.Data is long id ? new TeleBotSubscriptionSummary(Bot, (int)id) : null
         );
 }
        private void SubscribeToTeleSubscriptionUpdates(
            string s,
            WebSocketIncomingMessage im,
            bool subscribing
            )
        {
            if (!(im.Data is long id))
            {
                return;
            }
            var sub = Bot.Subscriptions.FirstOrDefault(x => x.Id == id);

            if (sub is null)
            {
                Send(WebSocketMessageBuilder.Error($"{id} not found is subscriptions."));
                return;
            }

            if (subscribing)
            {
                sub.Updated += SubOnUpdated;
            }
            else
            {
                sub.Updated -= SubOnUpdated;
            }
        }
        private void GetTeleSubscriptionListCommand(string s, WebSocketIncomingMessage im)
        {
            var list = Bot.Subscriptions
                       .Select(x => new TeleBotSubscriptionSummary(Bot, x.Id))
                       .ToList( );

            Send(s, list);
        }
Exemplo n.º 4
0
 protected virtual void HandleCommand(WebSocketIncomingMessage im)
 {
     if (AvailableCommands.Keys.Any(x => x == im))
     {
         var kp = AvailableCommands.First(x => x.Key == im);
         kp.Value?.Invoke(kp.Key, im);
     }
     else
     {
         Send(WebSocketMessageBuilder.Error($"{im.Name} not a valid command."));
     }
 }
        private void GetExchangeStatusesCommand(string s, WebSocketIncomingMessage im)
        {
            var list = Bot.Exchanges.Values.Select(x => new
            {
                x.Name,
                x.UpTime,
                x.LastUpdate,
                x.LastChange
            })
                       .ToList( );

            Send(s, list);
        }
Exemplo n.º 6
0
 protected virtual void HandleUnsubscribe(WebSocketIncomingMessage im)
 {
     if (AvailableSubscriptions.Keys.Any(x => x == im) &&
         Subscriptions.Remove(im))
     {
         var kp = AvailableSubscriptions.First(x => x.Key == im);
         kp.Value?.Invoke(kp.Key, im, false);
         Send(WebSocketMessageBuilder.Unsubscribe(kp.Key));
     }
     else
     {
         Send(WebSocketMessageBuilder.Error($"{im.Name} doesn't exist or not subscribed."));
     }
 }
Exemplo n.º 7
0
 private void SubscribeToCoinValueUpdates(
     string @event,
     WebSocketIncomingMessage _,
     bool subscribing
     )
 {
     foreach (var exchange in Ctb.Exchanges.Values)
     {
         if (subscribing)
         {
             exchange.Next += CoinValueOnNextHandler;
         }
         else
         {
             exchange.Next -= CoinValueOnNextHandler;
         }
     }
 }
Exemplo n.º 8
0
 private void GetBestPairCommand(string s, WebSocketIncomingMessage im)
 {
     Send(s, new BestPairSummary(Ctb.CompareTable));
 }