Esempio n. 1
0
        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";
        }
Esempio n. 2
0
 public EarningsUpdateJob(IEarningsAnnouncementBroker broker, IEmailService emailService, UpdateJobSettings settings, IInstrumentSource instrumentManager)
 {
     _broker            = broker;
     _emailService      = emailService;
     _settings          = settings;
     _instrumentManager = instrumentManager;
 }
Esempio n. 3
0
 public DividendUpdateJob(IDividendsBroker broker, IEmailService emailService, UpdateJobSettings settings, IInstrumentSource instrumentManager)
 {
     _broker            = broker;
     _emailService      = emailService;
     _settings          = settings;
     _instrumentManager = instrumentManager;
 }
Esempio n. 4
0
        public JobFactory(IHistoricalDataBroker hdb,
            string host,
            int port,
            string username,
            string password,
            string sender,
            string email,
            UpdateJobSettings updateJobSettings,
            QDMS.IDataStorage localStorage,
            IInstrumentSource instrumentSource,
            IEconomicReleaseBroker erb) : base()
        {
            _hdb = hdb;

            _host = host;
            _port = port;
            _username = username;
            _password = password;
            _sender = sender;
            _email = email;
            _updateJobSettings = updateJobSettings;
            _localStorage = localStorage;
            _instrumentSource = instrumentSource;
            _erb = erb;
        }
Esempio n. 5
0
        public InstrumentsServer(int port, IInstrumentSource instrumentManager)
        {
            if (instrumentManager == null)
            {
                throw new ArgumentNullException(nameof(instrumentManager), $"{nameof(instrumentManager)} cannot be null");
            }

            _connectionString  = $"tcp://*:{port}";
            _instrumentManager = instrumentManager;
        }
Esempio n. 6
0
        public InstrumentsServer(int port, IInstrumentSource instrumentManager)
        {
            if (instrumentManager == null)
            {
                throw new ArgumentNullException(nameof(instrumentManager), $"{nameof(instrumentManager)} cannot be null");
            }

            _connectionString = $"tcp://*:{port}";
            _instrumentManager = instrumentManager;
        }
Esempio n. 7
0
        public DataUpdateJob(IHistoricalDataBroker broker, IEmailService emailService, UpdateJobSettings settings = null, IDataStorage localStorage = null, IInstrumentSource instrumentManager = null)
        {
            _broker = broker;
            _emailService = emailService;
            _errors = new List<string>();
            _pendingRequests = new List<HistoricalDataRequest>();

            _settings = settings ?? GetSettings();
            _localStorage = localStorage ?? DataStorageFactory.Get();
            _instrumentManager = instrumentManager ?? new InstrumentManager();
        }
Esempio n. 8
0
        public DataUpdateJob(IHistoricalDataBroker broker, IEmailService emailService, UpdateJobSettings settings = null, IDataStorage localStorage = null, IInstrumentSource instrumentManager = null)
        {
            _broker          = broker;
            _emailService    = emailService;
            _errors          = new List <string>();
            _pendingRequests = new List <HistoricalDataRequest>();

            _settings          = settings ?? GetSettings();
            _localStorage      = localStorage ?? DataStorageFactory.Get();
            _instrumentManager = instrumentManager ?? new InstrumentManager();
        }
Esempio n. 9
0
        public DataUpdateJob(IHistoricalDataBroker broker, IEmailService emailService, UpdateJobSettings settings, IDataStorage localStorage, IInstrumentSource instrumentManager)
        {
            if (settings == null) throw new ArgumentNullException("settings");
            if (localStorage == null) throw new ArgumentNullException("localStorage");
            if (instrumentManager == null) throw new ArgumentNullException("instrumentManager");

            _broker = broker;
            _emailService = emailService;
            _errors = new List<string>();
            _pendingRequests = new List<HistoricalDataRequest>();

            _settings = settings;
            _localStorage = localStorage;
            _instrumentManager = instrumentManager;
        }
Esempio n. 10
0
        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";
        }
Esempio n. 11
0
        public DataUpdateJobFactory(HistoricalDataBroker broker,
                                    string host,
                                    int port,
                                    string username,
                                    string password,
                                    string sender,
                                    string email,
                                    UpdateJobSettings updateJobSettings,
                                    QDMS.IDataStorage localStorage,
                                    IInstrumentSource instrumentSource) : base()
        {
            _hdb = broker;

            _host              = host;
            _port              = port;
            _username          = username;
            _password          = password;
            _sender            = sender;
            _email             = email;
            _updateJobSettings = updateJobSettings;
            _localStorage      = localStorage;
            _instrumentSource  = instrumentSource;
        }
Esempio n. 12
0
        /// <summary>
        /// </summary>
        /// <param name="broker"></param>
        /// <param name="emailService"></param>
        /// <param name="settings"></param>
        /// <param name="localStorage"></param>
        /// <param name="instrumentManager"></param>
        /// <exception cref="ArgumentNullException"><paramref name="instrumentManager"/> is <see langword="null" />.</exception>
        public DataUpdateJob(IHistoricalDataBroker broker, IEmailService emailService, UpdateJobSettings settings, IDataStorage localStorage, IInstrumentSource instrumentManager)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (localStorage == null)
            {
                throw new ArgumentNullException(nameof(localStorage));
            }
            if (instrumentManager == null)
            {
                throw new ArgumentNullException(nameof(instrumentManager));
            }

            _broker          = broker;
            _emailService    = emailService;
            _errors          = new List <string>();
            _pendingRequests = new List <HistoricalDataRequest>();

            _settings          = settings;
            _localStorage      = localStorage;
            _instrumentManager = instrumentManager;
        }
Esempio n. 13
0
        public InstrumentModule(IInstrumentSource instrumentRepo, IDataStorage dataStorage) : base("/instruments")
        {
            this.RequiresAuthentication();

            Get["/", true] = async(_, token) => await instrumentRepo.FindInstruments().ConfigureAwait(false);

            Get["/{Id:int}", true] = async(parameters, token) =>
            {
                //Instrument by ID
                var id         = (int)parameters.Id;
                var instrument = (await instrumentRepo.FindInstruments(x => x.ID == id).ConfigureAwait(false)).FirstOrDefault();

                if (instrument == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                return(instrument);
            };

            Get["/search", true] = async(_, token) =>
            {
                //Search using an instrument object
                var inst = this.Bind <Instrument>();
                if (inst == null)
                {
                    return(HttpStatusCode.BadRequest);
                }

                return(await instrumentRepo.FindInstruments(inst).ConfigureAwait(false));
            };

            Get["/predsearch", true] = async(parameters, token) =>
            {
                //Search using a predicate
                var predReq = this.Bind <PredicateSearchRequest>();
                if (predReq == null)
                {
                    return(HttpStatusCode.BadRequest);
                }

                //Deserialize LINQ expression and pass it to the instrument manager
                Expression <Func <Instrument, bool> > expression;
                try
                {
                    expression = predReq.Filter;
                }
                catch (Exception ex)
                {
                    return(Negotiate
                           .WithModel(new ValidationErrorResponse("Malformed predicate: " + ex.Message))
                           .WithStatusCode(HttpStatusCode.BadRequest));
                }
                var instruments = await instrumentRepo.FindInstruments(expression).ConfigureAwait(false);

                return(instruments);
            };

            Post["/", true] = async(parameters, token) =>
            {
                Instrument instrument = this.BindAndValidate <Instrument>();
                if (ModelValidationResult.IsValid == false)
                {
                    return(this.ValidationFailure());
                }

                var addedInstrument = await instrumentRepo.AddInstrument(instrument);

                return(addedInstrument);
            };

            Put["/", true] = async(parameters, token) =>
            {
                var instrument = this.BindAndValidate <Instrument>();
                if (ModelValidationResult.IsValid == false)
                {
                    return(this.ValidationFailure());
                }

                //find it
                Instrument instrumentFromDB = (await instrumentRepo.FindInstruments(x => x.ID == instrument.ID).ConfigureAwait(false)).FirstOrDefault();
                if (instrumentFromDB == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                //update it
                await instrumentRepo.UpdateInstrument(instrumentFromDB, instrument).ConfigureAwait(false);

                return(instrumentFromDB);
            };

            Delete["/{Id:int}", true] = async(parameters, token) =>
            {
                int id         = parameters.Id;
                var instrument = (await instrumentRepo.FindInstruments(x => x.ID == id).ConfigureAwait(false)).FirstOrDefault();

                if (instrument == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                await instrumentRepo.RemoveInstrument(instrument, dataStorage).ConfigureAwait(false);

                return(instrument);
            };
        }
Esempio n. 14
0
        public InstrumentsServer(int port, IInstrumentSource instrumentManager = null)
        {
            _socketPort = port;

            _instrumentManager = instrumentManager ?? new InstrumentManager();
        }
Esempio n. 15
0
        public InstrumentsServer(int port, IInstrumentSource instrumentManager = null)
        {
            _socketPort = port;

            _instrumentManager = instrumentManager ?? new InstrumentManager();
        }