Esempio n. 1
0
        async Task UnsubscribeAndClose(InfoWebSocketConnection connection)
        {
            Unsubscribe(connection);
            await connection.CloseConnection();

            connection.Dispose();
        }
Esempio n. 2
0
 public async Task <BaseResponse> HandleCommand(InfoWebSocketConnection infoWebSocket, BaseCommand command)
 {
     if (!handlers.ContainsKey(command.Command))
     {
         throw new NotSupportedException($"Command {command.Command} is not supported.");
     }
     return(await handlers[command.Command].Handle(infoWebSocket, command));
 }
Esempio n. 3
0
        /// <summary>
        /// Registers new client websocket connection
        /// </summary>
        /// <param name="webSocket">New websocket connection</param>
        public async Task OnNewConnection(WebSocket webSocket, string connectionId, string ip)
        {
            var connection = new InfoWebSocketConnection(Context, webSocket, connectionId, ip);

            Subscribe(connection);
            if (!connections.TryAdd(connectionId, connection))
            {
                throw new Exception($"Connection with id {connectionId} already exists.");
            }
            await connection.Listen();
        }
        public override Task <BaseResponse> Handle(InfoWebSocketConnection infoWebSocket, UnsubscribeCommand command)
        {
            if (command.Subscriptions.Count < 0)
            {
                throw new BadRequestException("At least one subscription must be specified.");
            }

            foreach (var subs in command.Subscriptions)
            {
                var subscription = Context.SubscriptionsManager.GetOrAddSubscription(BaseSubscription.GetBySubscriptionName(subs));
                infoWebSocket.RemoveSubsctioption(subscription);
            }
            return(Task.FromResult((BaseResponse) new SuccesResponse {
                RequestId = command.RequestId
            }));
        }
        public override async Task <BaseResponse> Handle(InfoWebSocketConnection infoWebSocket, GetPriceHistoryCommand command)
        {
            var asset = Context.Constellation.Assets.FirstOrDefault(a => a.Id == command.Market);

            if (asset == null && asset.IsXlm)
            {
                throw new BadRequestException("Invalid market.");
            }

            var res = await Context.AnalyticsManager.PriceHistoryManager.GetPriceHistory(command.Cursor, command.Market, command.Period);

            return(new PriceHistoryResponse  {
                RequestId = command.RequestId,
                PriceHistory = res.frames,
                NextCursor = res.nextCursor
            });
        }
Esempio n. 6
0
 async Task SendSubscriptionUpdate(BaseSubscription subscription, SubscriptionUpdateBase update, InfoWebSocketConnection connection)
 {
     await connection.SendSubscriptionUpdate(subscription, update);
 }
Esempio n. 7
0
 void Unsubscribe(InfoWebSocketConnection connection)
 {
     connection.OnClosed -= OnClosed;
 }
Esempio n. 8
0
 void Subscribe(InfoWebSocketConnection connection)
 {
     connection.OnClosed += OnClosed;
 }
Esempio n. 9
0
 void RemoveConnection(InfoWebSocketConnection connection)
 {
     _ = UnsubscribeAndClose(connection);
     connections.TryRemove(connection.ConnectionId, out _);
 }