Exemple #1
0
 public Subscription SubscribeToTradeSubscription(string accountId, SubscriptionListener tableListener)
 {
     return(SubscribeToTradeSubscription(accountId, tableListener,
                                         new[]
     {
         "CONFIRMS", "OPU", "WOU"
     }));
 }
Exemple #2
0
        internal RedisSentinelClient(IRedisConnector connector)
        {
            _connector    = connector;
            _subscription = new SubscriptionListener(_connector);

            _subscription.MessageReceived += OnSubscriptionReceived;
            _subscription.Changed         += OnSubscriptionChanged;
            _connector.Connected          += OnConnectionReconnected;
        }
        internal RedisSentinelClient(IRedisSocket socket, EndPoint endpoint, int concurrency, int bufferSize)
        {
            _connector    = new RedisConnector(endpoint, socket, concurrency, bufferSize);
            _subscription = new SubscriptionListener(_connector);

            _subscription.MessageReceived += OnSubscriptionReceived;
            _subscription.Changed         += OnSubscriptionChanged;
            _connector.Connected          += OnConnectionReconnected;
        }
Exemple #4
0
 public Subscription SubscribeToChartTicks(IEnumerable <string> epics, SubscriptionListener tableListener)
 {
     return(SubscribeToChartTicks(epics, tableListener,
                                  new[]
     {
         "BID", "OFR", "LTP", "LTV", "TTV", "UTM",
         "DAY_OPEN_MID", "DAY_NET_CHG_MID", "DAY_PERC_CHG_MID", "DAY_HIGH", "DAY_LOW"
     }));
 }
Exemple #5
0
        /// <summary>
        /// L1 Prices subscription
        /// </summary>
        public Subscription SubscribeToMarketDetails(IEnumerable <string> epics, SubscriptionListener tableListener)
        {
            return(SubscribeToMarketDetails(epics, tableListener,
                                            new[]
            {
                "MID_OPEN", "HIGH", "LOW", "CHANGE", "CHANGE_PCT", "UPDATE_TIME",
                "MARKET_DELAY", "MARKET_STATE", "BID", "OFFER"

                /*, "BID_QUOTE_ID", "OFR_QUOTE_ID"*/
            }));
        }
        public RedisClient(IRedisSocket socket, EndPoint endpoint, int asyncConcurrency, int asyncBufferSize)
        {
            _connector    = new RedisConnector(endpoint, socket, asyncConcurrency, asyncBufferSize);
            _transaction  = new RedisTransaction(_connector);
            _subscription = new SubscriptionListener(_connector);
            _monitor      = new MonitorListener(_connector);

            _subscription.MessageReceived  += OnSubscriptionReceived;
            _subscription.Changed          += OnSubscriptionChanged;
            _monitor.MonitorReceived       += OnMonitorReceived;
            _connector.Connected           += OnConnectionConnected;
            _transaction.TransactionQueued += OnTransactionQueued;
        }
Exemple #7
0
        public Subscription SubscribeToTradeSubscription(string accountId, SubscriptionListener tableListener,
                                                         IEnumerable <string> fields)
        {
            var subscription = new Subscription("DISTINCT", "TRADE:" + accountId, fields.ToArray());

            if (tableListener != null)
            {
                subscription.addListener(tableListener);
            }

            _client.subscribe(subscription);

            return(subscription);
        }
Exemple #8
0
        public Subscription SubscribeToChartCandleData(IEnumerable <string> epics, ChartScale scale,
                                                       SubscriptionListener tableListener, string[] fields)
        {
            var subscription = new Subscription("MERGE", epics.Select(e => $"CHART:{e}:{GetScale(scale)}").ToArray(), fields.ToArray());

            if (tableListener != null)
            {
                subscription.addListener(tableListener);
            }

            _client.subscribe(subscription);

            return(subscription);
        }
Exemple #9
0
 public Subscription SubscribeToChartCandleData(IEnumerable <string> epics, ChartScale scale,
                                                SubscriptionListener tableListener)
 {
     return(SubscribeToChartCandleData(epics, scale, tableListener,
                                       new[]
     {
         "LTV", "TTV", "UTM",
         "DAY_OPEN_MID", "DAY_NET_CHG_MID", "DAY_PERC_CHG_MID", "DAY_HIGH", "DAY_LOW",
         "OFR_OPEN", "OFR_HIGH", "OFR_LOW", "OFR_CLOSE",
         "BID_OPEN", "BID_HIGH", "BID_LOW", "BID_CLOSE",
         "LTP_OPEN", "LTP_HIGH", "LTP_LOW", "LTP_CLOSE",
         "CONS_END", "CONS_TICK_COUNT",
     }));
 }
Exemple #10
0
        public Subscription SubscribeToChartTicks(IEnumerable <string> epics, SubscriptionListener tableListener,
                                                  string[] fields)
        {
            var subscription = new Subscription("DISTINCT", epics.Select(e => $"CHART:{e}:TICK").ToArray(), fields.ToArray());

            if (tableListener != null)
            {
                subscription.addListener(tableListener);
            }

            _client.subscribe(subscription);

            return(subscription);
        }
Exemple #11
0
        public Subscription SubscribeToMarketDetails(IEnumerable <string> epics, SubscriptionListener tableListener,
                                                     IEnumerable <string> fields)
        {
            var subscription = new Subscription("MERGE", epics.Select(e => $"L1:{e}").ToArray(), fields.ToArray());

            if (tableListener != null)
            {
                subscription.addListener(tableListener);
            }

            _client.subscribe(subscription);

            return(subscription);
        }
Exemple #12
0
        public Subscription SubscribeToAccountDetails(string accountId, SubscriptionListener tableListener,
                                                      IEnumerable <string> fields)
        {
            var subscription = new Subscription("MERGE", "ACCOUNT:" + accountId, fields.ToArray());

            if (tableListener != null)
            {
                subscription.addListener(tableListener);
            }

            _client.subscribe(subscription);

            return(subscription);
        }
Exemple #13
0
        internal RedisClient(IRedisSocket socket, EndPoint endpoint, int asyncConcurrency, int asyncBufferSize)
        {
            // use invariant culture - we have to set it explicitly for every thread we create to
            // prevent any floating-point problems (mostly because of number formats in non en-US cultures).
            //CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 这行会影响 string.Compare 结果

            _connector    = new RedisConnector(endpoint, socket, asyncConcurrency, asyncBufferSize);
            _transaction  = new RedisTransaction(_connector);
            _subscription = new SubscriptionListener(_connector);
            _monitor      = new MonitorListener(_connector);

            _subscription.MessageReceived  += OnSubscriptionReceived;
            _subscription.Changed          += OnSubscriptionChanged;
            _monitor.MonitorReceived       += OnMonitorReceived;
            _connector.Connected           += OnConnectionConnected;
            _transaction.TransactionQueued += OnTransactionQueued;
        }
Exemple #14
0
        internal RedisClient(IRedisConnector connector)
        {
            // use invariant culture - we have to set it explicitly for every thread we create to
            // prevent any floating-point problems (mostly because of number formats in non en-US cultures).
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            _connector    = connector;
            _transaction  = new RedisTransaction(_connector);
            _subscription = new SubscriptionListener(_connector);
            _monitor      = new MonitorListener(_connector);

            _subscription.MessageReceived  += OnSubscriptionReceived;
            _subscription.Changed          += OnSubscriptionChanged;
            _monitor.MonitorReceived       += OnMonitorReceived;
            _connector.Connected           += OnConnectionConnected;
            _transaction.TransactionQueued += OnTransactionQueued;
        }
        public async Task rethrow_exception_when_listening()
        {
            var cts = new CancellationTokenSource(10000);
            var ex  = new TestException();
            var mockStreamClientFactory = new Mock <IStreamClientFactory>();
            var mockStreamClient        = new Mock <IStreamClient>();
            var listener              = new SubscriptionListener(NullStandardLogger.Instance, mockStreamClientFactory.Object, null);
            var regionId              = "x";
            var subscriptionStreamId  = "s";
            var firstPositionInStream = 1;

            mockStreamClientFactory.Setup(x => x.Create(regionId)).Returns(mockStreamClient.Object);
            mockStreamClient.Setup(x => x.FirstPositionInStream).Returns(firstPositionInStream);
            mockStreamClient
            .Setup(x => x.SubscribeToStreamAsync(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <Func <StreamEvent, Task> >(), It.IsAny <CancellationToken>()))
            .Throws(new TestException());

            await Assert.ThrowsAsync <TestException>(() => listener.ListenAsync(regionId, subscriptionStreamId, cts.Token));
        }
        public async Task listen_with_correct_params_until_cancelled()
        {
            var cts = new CancellationTokenSource();
            var mockStreamClientFactory = new Mock <IStreamClientFactory>();
            var mockStreamClient        = new Mock <IStreamClient>();
            var listener              = new SubscriptionListener(NullStandardLogger.Instance, mockStreamClientFactory.Object, null);
            var regionId              = "x";
            var subscriptionStreamId  = "s";
            var firstPositionInStream = 1;
            var awaitingEnqueueSignal = new ManualResetEventSlim(false);
            var mockEnqueueSignal     = new ManualResetEventSlim(false);

            mockStreamClientFactory.Setup(x => x.Create(regionId)).Returns(mockStreamClient.Object);
            mockStreamClient.Setup(x => x.FirstPositionInStream).Returns(firstPositionInStream);
            mockStreamClient
            .Setup(x => x.SubscribeToStreamAsync(subscriptionStreamId, firstPositionInStream, It.IsAny <Func <StreamEvent, Task> >(), cts.Token))
            .Callback(() => awaitingEnqueueSignal.Set())
            .Returns(mockEnqueueSignal.WaitHandle.AsTask());

            var listenTask = listener.ListenAsync(regionId, subscriptionStreamId, cts.Token);

            var timeoutToken1 = new CancellationTokenSource(10000).Token;
            await Task.WhenAny(new[] { awaitingEnqueueSignal.WaitHandle.AsTask(), timeoutToken1.WaitHandle.AsTask() });

            if (timeoutToken1.IsCancellationRequested)
            {
                throw new TimeoutException();
            }

            cts.Cancel();

            var timeoutToken2 = new CancellationTokenSource(10000).Token;
            await Task.WhenAny(new[] { listenTask, timeoutToken2.WaitHandle.AsTask() });

            if (timeoutToken2.IsCancellationRequested)
            {
                throw new TimeoutException();
            }
        }
        internal RedisSentinelClient(IRedisSocket socket, EndPoint endpoint, int concurrency, int bufferSize)
        {
            _connector = new RedisConnector(endpoint, socket, concurrency, bufferSize);
            _subscription = new SubscriptionListener(_connector);

            _subscription.MessageReceived += OnSubscriptionReceived;
            _subscription.Changed += OnSubscriptionChanged;
            _connector.Connected += OnConnectionReconnected;
        }
Exemple #18
0
 public Subscription SubscribeToAccountDetails(string accountId, SubscriptionListener tableListener)
 {
     return(SubscribeToAccountDetails(accountId, tableListener,
                                      new[] { "PNL", "DEPOSIT", "USED_MARGIN", "AMOUNT_DUE", "AVAILABLE_CASH" }));
 }