Пример #1
0
        public Task <InstrumentResultSet> SendInstrumentsRequestAsync()
        {
            var tcs = new TaskCompletionSource <InstrumentResultSet>();

            try
            {
                _logger.Verbose(nameof(SendInstrumentsRequestAsync));

                //subscribe for the lastest result
                InstrumentResultSetObservable
                .Subscribe(x => { tcs.TrySetResult(x); });

                //clear before query new
                _instrumentResultSet = new InstrumentResultSet();

                //execute them all
                Task.WhenAll(
                    //SendMessageAsync(GetInstrumentWsMessageBase.CreateRequest(InstrumentType.Forex)),
                    //SendMessageAsync(GetInstrumentWsMessageBase.CreateRequest(InstrumentType.CFD)),
                    //SendMessageAsync(GetInstrumentWsMessageBase.CreateRequest(InstrumentType.Crypto))
                    );
            }

            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }
Пример #2
0
        public Task <InstrumentResultSet> SendInstrumentsRequestAsync(params InstrumentType[] instrumentTypes)
        {
            var tcs = new TaskCompletionSource <InstrumentResultSet>();

            try
            {
                //subscribe for the lastest result
                var obs = InstrumentResultSetObservable
                          .Subscribe(x => { tcs.TrySetResult(x); });

                //clear before query new
                _instrumentResultSet = new InstrumentResultSet();

                Task.WhenAll(
                    SendMessageAsync(new GetInstrumentWsRequest(InstrumentType.Forex)),
                    SendMessageAsync(new GetInstrumentWsRequest(InstrumentType.CFD)),
                    SendMessageAsync(new GetInstrumentWsRequest(InstrumentType.Crypto))
                    );
            }

            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }