protected override void RunStreamingRatesTest()
        {
            _dataCount = 0;

            RatesSession session = new RatesSession(_accountId, _instruments);

            _tickReceived         = new Semaphore(0, 100); // 100 threads max
            session.DataReceived += SessionOnDataReceived;
            session.StartSession();
            _results.Add("Starting rate stream test");

            // bespoke ///////////////////////////////////////////////////////////////////////
            while (_dataCount < 10)
            {
                // this keeps the request stream active until 10 responses are received
                // if things hang, add a timeout .. or does a WaitOne() timeout trigger SessionDataReceived()?
            }
            //////////////////////////////////////////////////////////////////////////////////

            // allow 10 seconds for response then recycle the thread
            bool success = _tickReceived.WaitOne(10000);

            session.StopSession();
            _results.Verify(success, "Streaming rates successfully received");
        }
        private async void Refresh()
        {
            if (_currentSession == null)
            {
                Items.Clear();
                var instruments = await Rest.GetInstrumentsAsync(_source.Id);

                _currentSession = new RatesSession(_source.Id, instruments);
                _currentSession.DataReceived += CurrentSessionOnTickReceived;
                _currentSession.StartSession();
            }
        }
Beispiel #3
0
        protected virtual void RunStreamingRatesTest()
        {
            RatesSession session = new RatesSession(_accountId, _instruments);

            _tickReceived         = new Semaphore(0, 100);
            session.DataReceived += SessionOnDataReceived;
            session.StartSession();
            _results.Add("Starting rate stream test");
            bool success = _tickReceived.WaitOne(10000);

            session.StopSession();
            _results.Verify(success, "Streaming rates successfully received");
        }
Beispiel #4
0
        /// <summary>
        /// Subscribes to the requested symbols (using a single streaming session)
        /// </summary>
        /// <param name="symbolsToSubscribe">The list of symbols to subscribe</param>
        private void SubscribeSymbols(List <Symbol> symbolsToSubscribe)
        {
            var instruments = symbolsToSubscribe
                              .Select(symbol => new Instrument {
                instrument = _symbolMapper.GetBrokerageSymbol(symbol)
            })
                              .ToList();

            if (_ratesSession != null)
            {
                _ratesSession.DataReceived -= OnDataReceived;
                _ratesSession.StopSession();
            }

            if (instruments.Count > 0)
            {
                _ratesSession = new RatesSession(this, _accountId, instruments);
                _ratesSession.DataReceived += OnDataReceived;
                _ratesSession.StartSession();
            }
        }
Beispiel #5
0
 /// <summary>
 /// Starts streaming prices for a list of instruments
 /// </summary>
 public override void StartPricingStream(List <string> instruments)
 {
     _ratesSession = new RatesSession(this, AccountId, instruments);
     _ratesSession.DataReceived += OnDataReceived;
     _ratesSession.StartSession();
 }
        /// <summary>
        /// Subscribes to the requested symbols (using a single streaming session)
        /// </summary>
        /// <param name="symbolsToSubscribe"></param>
        private void SubscribeSymbols(List<Symbol> symbolsToSubscribe)
        {
            var instruments = symbolsToSubscribe
                .Select(symbol => new Instrument { instrument = _symbolMapper.GetBrokerageSymbol(symbol) })
                .ToList();

            if (_ratesSession != null)
            {
                _ratesSession.StopSession();
                _ratesSession.DataReceived -= OnDataReceived;
            }

            if (instruments.Count > 0)
            {
                _ratesSession = new RatesSession(this, _accountId, instruments);
                _ratesSession.DataReceived += OnDataReceived;
                _ratesSession.StartSession();
            }
        }
Beispiel #7
0
    static void Main(string[] args)
    {
        List <Instrument> instruments = null;
        var task = Task.Run(async() => instruments = await Rest.GetInstrumentsAsync(AccountId, null, new List <string>(_majors)));

        task.Wait();

        var          selectedMajors = instruments.Where(s => Array.Exists <string>(_majors, y => y == s.instrument));
        RatesSession session        = new RatesSession(AccountId, new List <Instrument>(selectedMajors));

        _tickReceived         = new Semaphore(0, 100);
        session.DataReceived += SessionOnDataReceived;
        session.StartSession();
        Console.WriteLine("Starting rate stream test");
        bool success = _tickReceived.WaitOne(10000);

        session.StopSession();


        EventsSession eventSession = new EventsSession(AccountId);

        _eventReceived             = new Semaphore(0, 100);
        eventSession.DataReceived += OnEventReceived;
        eventSession.StartSession();
        Console.WriteLine("Starting event stream test");
        Task.Run(() =>
        {
            success = _eventReceived.WaitOne(10000);
            eventSession.StopSession();
        }
                 );

        List <Price> prices;

        var task2 = Task.Run(async() => prices = await Rest.GetRatesAsync(instruments));

        task2.Wait();


        List <Position> positions = null;

        var task3 = Task.Run(async() => positions = await Rest.GetPositionsAsync(AccountId));

        task3.Wait();

        var request = new Dictionary <string, string>
        {
            { "instrument", TestInstrument },
            { "units", "10000" },
            { "side", "sell" },
            { "type", "market" },
            { "price", "1.0" }
        };

        if (positions.Count == 0)
        {
            //Open a position
            PostOrderResponse response = null;
            var task4 = Task.Run(async() => response = await Rest.PostOrderAsync(AccountId, request));
            task4.Wait();

            if (response.tradeOpened != null && response.tradeOpened.id > 0)
            {
                Console.WriteLine("Post order success");
            }
        }
        else
        {
            //Close all positions
            foreach (var position in positions)
            {
                DeletePositionResponse closePositionResponse = null;
                var task5 = Task.Run(async() => closePositionResponse = await Rest.DeletePositionAsync(AccountId, TestInstrument));
                task5.Wait();

                if (closePositionResponse.ids.Count > 0 && closePositionResponse.instrument == TestInstrument)
                {
                    Console.WriteLine("Position closed");
                }

                if (closePositionResponse.totalUnits > 0 && closePositionResponse.price > 0)
                {
                    Console.WriteLine("Position close response seems valid");
                }

                foreach (var id in closePositionResponse.ids)
                {
                    Transaction transaction = null;
                    var         task6       = Task.Run(async() => transaction = await Rest.GetTransactionDetailsAsync(AccountId, id));
                    task6.Wait();
                }
            }
        }

        Console.ReadLine();
    }