public ContinuousFuturesBroker(IDataClient client, bool connectImmediately = true, IInstrumentSource instrumentRepo = null) { if (client == null) { throw new ArgumentNullException(nameof(client)); } _client = client; _instrumentRepo = instrumentRepo ?? new InstrumentRepository(new MyDBContext()); _client.HistoricalDataReceived += _client_HistoricalDataReceived; _client.Error += _client_Error; if (connectImmediately) { _client.Connect(); } _data = new Dictionary <KeyValuePair <int, BarSize>, List <OHLCBar> >(); _contracts = new Dictionary <int, List <Instrument> >(); _requestCounts = new Dictionary <int, int>(); _requests = new Dictionary <int, HistoricalDataRequest>(); _histReqIDMap = new Dictionary <int, int>(); _frontContractRequests = new BlockingCollection <FrontContractRequest>(); _requestTypes = new Dictionary <int, bool>(); _frontContractRequestMap = new Dictionary <int, FrontContractRequest>(); _dataUsesPending = new Dictionary <KeyValuePair <int, BarSize>, int>(); _reconnectTimer = new Timer(1000); _reconnectTimer.Elapsed += _reconnectTimer_Elapsed; _reconnectTimer.Start(); Name = "ContinuousFutures"; }
public ContinuousFuturesBroker(IDataClient client = null, IInstrumentSource instrumentMgr = null, string clientName = "") { if (client == null) { if (string.IsNullOrEmpty(clientName)) { clientName = "CONTFUTCLIENT"; } _client = new QDMSClient.QDMSClient( clientName, "127.0.0.1", Properties.Settings.Default.rtDBReqPort, Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.instrumentServerPort, Properties.Settings.Default.hDBPort); } else { _client = client; } _instrumentMgr = instrumentMgr ?? new InstrumentManager(); _client.HistoricalDataReceived += _client_HistoricalDataReceived; _client.Error += _client_Error; _client.Connect(); _data = new Dictionary <KeyValuePair <int, BarSize>, List <OHLCBar> >(); _contracts = new Dictionary <int, List <Instrument> >(); _requestCounts = new Dictionary <int, int>(); _requests = new Dictionary <int, HistoricalDataRequest>(); _histReqIDMap = new Dictionary <int, int>(); _frontContractRequests = new BlockingCollection <FrontContractRequest>(); _requestTypes = new Dictionary <int, bool>(); _frontContractRequestMap = new Dictionary <int, FrontContractRequest>(); _dataUsesPending = new Dictionary <KeyValuePair <int, BarSize>, int>(); _reconnectTimer = new Timer(1000); _reconnectTimer.Elapsed += _reconnectTimer_Elapsed; _reconnectTimer.Start(); Name = "ContinuousFutures"; }
private void _reconnectTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!_client.Connected) { _reconnectTimer.Stop(); Log(LogLevel.Info, "CFB: trying to reconnect."); try { _client.Connect(); } catch (Exception ex) { Log(LogLevel.Error, "CFB error when trying to connect: " + ex.Message); } } }
private void ReconnectTimerElapsed(object sender, ElapsedEventArgs e) { if (!_client.Connected) { _reconnectTimer.Stop(); _logger.Info("CFB: trying to reconnect."); try { _client.Connect(); } catch (Exception ex) { _logger.Error(ex, "CFB error when trying to connect."); } } }