Beispiel #1
0
        public void ManyInstrumentsArbitrage()
        {
            _manyInstruments.Run();

            Task.Run(() =>
            {
                _manyInstruments.ThreadActivity(_log.Service,
                                                () =>
                {
                    _bittrex.DoArbitrage(_exchanges, data => _dbRepo.SaveBittrexArbitrageAsync(data));
                    _matchingEvent.WaitOne();
                },
                                                data =>
                {
                    _manyInstruments.Cancel();
                    _log.WriteError("Terminated due to error: " + data.Message);
                },
                                                () =>
                {
                    _matchingEvent.Set();
                    _stopEvent2.Set();
                });
            },
                     _manyInstruments.Token);
        }
Beispiel #2
0
        public void SingleInstrumentArbitrage()
        {
            InitTradingStates();
            _singleInstrument.Run();

            Task.Run(() =>
            {
                _singleInstrument.ThreadActivity(_log.Service,
                                                 () =>
                {
                    try
                    {
                        ArbitrageImpl();
                        ScalpingBitstamp();
                    }
                    catch (Exception ex)
                    {
                        _log.WriteError(ex.StackTrace);
                        throw ex;
                    }
                    _matchingEvent.WaitOne();
                },
                                                 data =>
                {
                    _singleInstrument.Cancel();
                    _log.WriteError("Terminated due to error: " + data.Message);
                },
                                                 () =>
                {
                    _matchingEvent.Set();
                    _stopEvent1.Set();
                });
            },
                     _singleInstrument.Token);
        }
Beispiel #3
0
 public Task StartListener(ServiceName service, Func <byte[], byte[]> onRead, Action <NetworkStream, byte[]> onWrite, Action <ServiceEventData> onException)
 {
     return(Task.Run(() =>
     {
         _cancellation.ThreadActivity(service,
                                      () =>
         {
             if (_server.Pending())
             {
                 HandleRequestAsync(onRead, onWrite);
             }
             else
             {
                 Thread.Sleep(50);
             }
         },
                                      data => onException(data),
                                      () => _server.Stop()
                                      );
     },
                     _cancellation.Token));
 }