Exemplo n.º 1
0
 public void Online()
 {
     foreach (KeyValuePair <IMarketDataProvider, Dictionary <Instrument, List <string> > > current in this.requests)
     {
         IMarketDataProvider key = current.Key;
         foreach (KeyValuePair <Instrument, List <string> > current2 in current.Value)
         {
             Instrument key2 = current2.Key;
             foreach (string current3 in current2.Value)
             {
                 if (current3 == null)
                 {
                     key2.RequestMarketData(key, (MarketDataType)3);
                 }
                 else
                 {
                     key2.RequestMarketData(key, (MarketDataType)3, current3);
                 }
             }
         }
     }
     ProviderManager.NewBar             += new BarEventHandler(this.OnNewBar);
     ProviderManager.NewBarOpen         += new BarEventHandler(this.OnNewBarOpen);
     ProviderManager.NewTrade           += new TradeEventHandler(this.OnNewTrade);
     ProviderManager.NewQuote           += new QuoteEventHandler(this.OnNewQuote);
     ProviderManager.NewMarketDepth     += new MarketDepthEventHandler(this.OnNewMarketDepth);
     ProviderManager.NewFundamental     += new FundamentalEventHandler(this.OnNewFundamental);
     ProviderManager.NewCorporateAction += new CorporateActionEventHandler(this.OnNewCorporateAction);
     ProviderManager.NewBarSlice        += new BarSliceEventHandler(this.OnNewBarSlice);
 }
Exemplo n.º 2
0
 public DBInit(IMarketDataProvider marketProvider,
               ITickerRepo tickerRepo,
               IBaseRepo <Portfolio> portfolioRepo,
               IBaseRepo <Trade> tradeRepo)
 {
     this.tickerRepo = tickerRepo;
 }
Exemplo n.º 3
0
 protected void Init(IMarketDataProvider marketDataProvider, IExecutionProvider executionProvider, Portfolio portfolio, bool asyncEventProcessing)
 {
     this.marketDataProvider = marketDataProvider;
     this.executionProvider  = executionProvider;
     this.portfolio          = portfolio;
     this.eventQueue.Enabled = asyncEventProcessing;
 }
Exemplo n.º 4
0
 private static void LogRequestMessage(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType, string obj3)
 {
     if (Trace.IsLevelEnabled(TraceLevel.Warning))
     {
         Trace.WriteLine("" + Environment.NewLine + "" + provider.Name + Environment.NewLine + "Symbol" + instrument.Symbol + Environment.NewLine + "Type:" + mdType.ToString() + Environment.NewLine + "" + obj3);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BasketBlackScholes"/>.
 /// </summary>
 /// <param name="underlyingAsset">Underlying asset.</param>
 /// <param name="dataProvider">The market data provider.</param>
 /// <param name="positionProvider">The position provider.</param>
 /// <param name="exchangeInfoProvider">Exchanges and trading boards provider.</param>
 public BasketBlackScholes(Security underlyingAsset, IMarketDataProvider dataProvider, IExchangeInfoProvider exchangeInfoProvider, IPositionProvider positionProvider)
     : base(underlyingAsset, dataProvider, exchangeInfoProvider)
 {
     _innerModels     = new InnerModelList(this);
     UnderlyingAsset  = underlyingAsset;
     PositionProvider = positionProvider ?? throw new ArgumentNullException(nameof(positionProvider));
 }
Exemplo n.º 6
0
 protected StrategyBase(string name, string description)
 {
     this.metaStrategyBase = null;
     this.name             = name;
     this.description      = description;
     this.isEnabled        = true;
     this.isActive         = true;
     this.ReportManager    = (StrategyComponentManager.GetComponent("{5E7810DC-C9C1-427f-8CD9-1DFFE26E59B5}", this) as ReportManager);
     this.MarketManager    = (StrategyComponentManager.GetComponent("{849E4CFE-C19E-4d1e-899D-0BB26DB12AAD}", this) as MarketManager);
     this.portfolio        = PortfolioManager.Portfolios[name];
     if (this.portfolio == null)
     {
         this.portfolio = new Portfolio(name);
     }
     this.tester             = new LiveTester(this.portfolio);
     this.stops              = new StopList();
     this.triggers           = new TriggerList();
     this.marketDataProvider = null;
     this.executionProvider  = null;
     this.newsProvider       = null;
     this.executionService   = null;
     this.orders             = new OrderTable();
     this.global             = new Hashtable();
     this.activeInstruments  = new InstrumentList();
     this.barSliceManager    = new BarSliceManager();
     this.componentTypeList  = new List <ComponentType>();
     this.componentTypeList.Add(ComponentType.MarketManager);
     this.componentTypeList.Add(ComponentType.ReportManager);
     this.activeStops = new Dictionary <Instrument, List <StopBase> >();
     this.portfolios  = new Dictionary <Instrument, Portfolio>();
     this.testers     = new Dictionary <Instrument, LiveTester>();
     this.statisticsPerInstrumentEnabled = false;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Instantiates a <see cref="MarketDataSubscription"/>
        /// </summary>
        /// <param name="logger">The logger</param>
        /// <param name="repositoryFactory">The repository to store and retrieve market data</param>
        /// <param name="marketDataProvider">The provider for refreshing market data</param>
        /// <param name="stockListProvider">The provider for lists of stocks for which to retrieve data</param>
        /// <param name="quotesPublisher"></param>
        /// <param name="subscriptionData">The subscriptionData data for determining</param>
        public MarketDataSubscription(ILog logger,
            IMarketDataRepositoryFactory repositoryFactory,
            IMarketDataProvider marketDataProvider,
            IStockListProvider stockListProvider,
            IPublisher<NewQuotesData> quotesPublisher,
            Subscription subscriptionData)
        {
            // perform null checks
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (repositoryFactory == null)
                throw new ArgumentNullException("repositoryFactory");
            if (marketDataProvider == null)
                throw new ArgumentNullException("marketDataProvider");
            if (subscriptionData == null)
                throw new ArgumentNullException("subscriptionData");

            // set dependencies
            _logger = logger;
            _repositoryFactory = repositoryFactory;
            _marketDataProvider = marketDataProvider;
            _stockListProvider = stockListProvider;
            _quotesPublisher = quotesPublisher;
            _subscriptionData = subscriptionData;

            // set up timer
            _timer = new Timer(obj => GetLatestQuotes());

            // status initialized to idle
            Status = SubscriptionStatus.Idle;
        }
 public void AddInstrument(Instrument instrument, IMarketDataProvider marketDataProvider, IExecutionProvider executionProvider)
 {
     /*-------不开市的时候无法加入证券------*/
     if (!this.marketOpen)
     {
         return;
     }
     /*-------------*/
     if (!this.instruments.Contains(instrument))
     {
         this.instruments.Add(instrument);
     }
     if (marketDataProvider != null)
     {
         this.marketDataProviderTable[instrument] = marketDataProvider;
     }
     else
     {
         this.marketDataProviderTable[instrument] = this.strategyMarketDataProvider;
     }
     if (executionProvider != null)
     {
         this.executionProviderTable[instrument] = executionProvider;
         return;
     }
     this.executionProviderTable[instrument] = this.strategyExecutionProvider;
 }
Exemplo n.º 9
0
		internal MarketDataSubscription(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType, int count)
		{
			this.Provider = provider;
			this.Instrument = instrument;
			this.MDType = mdType;
			this.Count = count;
		}
        /// <summary>
        /// Provides the Market Data Provider instance depending on the specified provider
        /// </summary>
        public static IMarketDataProvider GetMarketDataProviderInstance(string providerName)
        {
            try
            {
                var doc = new XmlDocument();

                // Read RabbitMQ configuration file
                doc.Load(AppDomain.CurrentDomain.BaseDirectory + @"\Config\AvailableProviders.xml");

                // Read the specified Node value
                XmlNode providerInfo = doc.SelectSingleNode(xpath: "Providers/" + providerName);

                // Check if the Requested Provider info is available
                if (providerInfo == null)
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info("Requested Market Data Provider not available.", _type.FullName, "GetMarketDataProviderInstance");
                    }
                    return(null);
                }

                IMarketDataProvider marketDataProvider = ContextRegistry.GetContext()[providerName + "MarketDataProvider"] as IMarketDataProvider;

                return(marketDataProvider);
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "GetMarketDataProviderInstance");
                return(null);
            }
        }
Exemplo n.º 11
0
 internal MarketDataSubscription(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType, int count)
 {
     this.Provider   = provider;
     this.Instrument = instrument;
     this.MDType     = mdType;
     this.Count      = count;
 }
Exemplo n.º 12
0
 protected StrategyBase(string name, string description)
 {
     this.metaStrategyBase = (MetaStrategyBase)null;
     this.name             = name;
     this.description      = description;
     this.isEnabled        = true;
     this.isActive         = true;
     this.ReportManager    = StrategyComponentManager.GetComponent("getcom", (object)this) as ReportManager;
     this.MarketManager    = StrategyComponentManager.GetComponent("getcom", (object)this) as MarketManager;
     this.portfolio        = PortfolioManager.Portfolios[name];
     if (this.portfolio == null)
     {
         this.portfolio = new Portfolio(name);
     }
     this.tester             = new LiveTester(this.portfolio);
     this.stops              = new StopList();
     this.triggers           = new TriggerList();
     this.marketDataProvider = (IMarketDataProvider)null;
     this.executionProvider  = (IExecutionProvider)null;
     this.newsProvider       = (INewsProvider)null;
     this.executionService   = (IExecutionService)null;
     this.orders             = new OrderTable();
     this.global             = new Hashtable();
     this.activeInstruments  = new InstrumentList();
     this.barSliceManager    = new BarSliceManager();
     this.componentTypeList  = new List <ComponentType>();
     this.componentTypeList.Add(ComponentType.MarketManager);
     this.componentTypeList.Add(ComponentType.ReportManager);
     this.activeStops = new Dictionary <Instrument, List <StopBase> >();
     this.portfolios  = new Dictionary <Instrument, Portfolio>();
     this.testers     = new Dictionary <Instrument, LiveTester>();
     this.statisticsPerInstrumentEnabled = false;
 }
Exemplo n.º 13
0
 public void Offline()
 {
     ProviderManager.NewBar             -= new BarEventHandler(this.OnNewBar);
     ProviderManager.NewBarOpen         -= new BarEventHandler(this.OnNewBarOpen);
     ProviderManager.NewTrade           -= new TradeEventHandler(this.OnNewTrade);
     ProviderManager.NewQuote           -= new QuoteEventHandler(this.OnNewQuote);
     ProviderManager.NewMarketDepth     -= new MarketDepthEventHandler(this.OnNewMarketDepth);
     ProviderManager.NewFundamental     -= new FundamentalEventHandler(this.OnNewFundamental);
     ProviderManager.NewCorporateAction -= new CorporateActionEventHandler(this.OnNewCorporateAction);
     ProviderManager.NewBarSlice        -= new BarSliceEventHandler(this.OnNewBarSlice);
     foreach (KeyValuePair <IMarketDataProvider, Dictionary <Instrument, List <string> > > current in this.requests)
     {
         IMarketDataProvider key = current.Key;
         if (key.BarFactory != null)
         {
             key.BarFactory.Reset();
         }
         foreach (KeyValuePair <Instrument, List <string> > current2 in current.Value)
         {
             Instrument key2 = current2.Key;
             foreach (string current3 in current2.Value)
             {
                 if (current3 == null)
                 {
                     key2.CancelMarketData(key, (MarketDataType)3);
                 }
                 else
                 {
                     key2.CancelMarketData(key, (MarketDataType)3, current3);
                 }
             }
         }
     }
 }
Exemplo n.º 14
0
            public BasketSecurityMarketDepthChangedRule(BasketSecurity security, IMarketDataProvider provider)
                : base(security, provider)
            {
                Name = LocalizedStrings.Str1050 + " " + security;
#pragma warning disable CS0618 // Type or member is obsolete
                Provider.MarketDepthChanged += OnMarketDepthChanged;
#pragma warning restore CS0618 // Type or member is obsolete
            }
Exemplo n.º 15
0
            public SecurityNewTradeRule(Security security, IMarketDataProvider provider)
                : base(security, provider)
            {
                Name = LocalizedStrings.Str1047 + " " + security;
#pragma warning disable CS0618 // Type or member is obsolete
                Provider.NewTrade += OnNewTrade;
#pragma warning restore CS0618 // Type or member is obsolete
            }
Exemplo n.º 16
0
 public PastaPricerEngine(IUnitOfExecution unitOfExecution, IEnumerable <string> pastasConfiguration, IMarketDataProvider marketDataProvider, IPastaPricerPublisher pastaPricerPublisher, bool conflationEnabled = false)
 {
     this.unitOfExecution      = unitOfExecution;
     this.pastasConfiguration  = pastasConfiguration;
     this.marketDataProvider   = marketDataProvider;
     this.pastaPricerPublisher = pastaPricerPublisher;
     this.conflationEnabled    = conflationEnabled;
 }
Exemplo n.º 17
0
 public PastaPricerEngine(IUnitOfExecution unitOfExecution, IEnumerable<string> pastasConfiguration, IMarketDataProvider marketDataProvider, IPastaPricerPublisher pastaPricerPublisher, bool conflationEnabled = false)
 {
     this.unitOfExecution = unitOfExecution;
     this.pastasConfiguration = pastasConfiguration;
     this.marketDataProvider = marketDataProvider;
     this.pastaPricerPublisher = pastaPricerPublisher;
     this.conflationEnabled = conflationEnabled;
 }
Exemplo n.º 18
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BlackScholes"/>.
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		public BlackScholes(Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
			: this(securityProvider, dataProvider)
		{
			if (option == null)
				throw new ArgumentNullException(nameof(option));

			Option = option;
		}
Exemplo n.º 19
0
        /// <summary>
        /// To get the main strike.
        /// </summary>
        /// <param name="underlyingAsset">Underlying asset.</param>
        /// <param name="provider">The market data provider.</param>
        /// <param name="allStrikes">All strikes.</param>
        /// <returns>The main strike. If it is impossible to get the current market price of the asset then the <see langword="null" /> will be returned.</returns>
        public static Security GetCentralStrike(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable <Security> allStrikes)
        {
            var assetPrice = underlyingAsset.GetCurrentPrice(provider);

            return(assetPrice == null
                                ? null
                                : allStrikes.OrderBy(s => Math.Abs((decimal)(s.Strike - assetPrice))).FirstOrDefault());
        }
Exemplo n.º 20
0
        public AlphaVantageTest()
        {
            session.Initialise("Ivan", "*****@*****.**");
            //this.mTickerRepo = new Mock<ITickerRepo>();
            ITickerRepo tickerRepo = new TickerRepo(session, Utils.Logger);
            IBaseRepo <PriceHistory> priceHistoryRepo = new BaseXMLRepo <PriceHistory>(session, Utils.Logger);

            this._alphaVantage = new AlphaVantage(tickerRepo, priceHistoryRepo);
        }
Exemplo n.º 21
0
		public void AddInstrument(Instrument instrument, IMarketDataProvider marketDataProvider, IExecutionProvider executionProvider)
		{
			if (!this.cYRAR9UWJy.Contains(instrument))
				this.cYRAR9UWJy.Add(instrument);
			this.nxTAjlViDK[instrument] = marketDataProvider == null ? this.strategyMarketDataProvider : marketDataProvider;
			if (executionProvider != null)
				this.utDAWNS3ic[instrument] = executionProvider;
			else
				this.utDAWNS3ic[instrument] = this.strategyExecutionProvider;
		}
Exemplo n.º 22
0
 public GMBarFactory(bool enabled, IMarketDataProvider provider)
 {
     this.enabled  = enabled;
     this.provider = provider;
     this.input    = BarFactoryInput.Trade;
     this.items    = new BarFactoryItemList();
     this.items.Add(new BarFactoryItem(BarType.Time, 60, true));
     this.barStore = new Dictionary <IFIXInstrument, Dictionary <BarType, Dictionary <long, object> > >();
     this.times    = new ArrayList();
 }
Exemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlackScholes"/>.
        /// </summary>
        /// <param name="option">Options contract.</param>
        /// <param name="underlyingAsset">Underlying asset.</param>
        /// <param name="dataProvider">The market data provider.</param>
        public BlackScholes(Security option, Security underlyingAsset, IMarketDataProvider dataProvider)
            : this(underlyingAsset, dataProvider)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            Option = option;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlackScholes"/>.
        /// </summary>
        /// <param name="option">Options contract.</param>
        /// <param name="securityProvider">The provider of information about instruments.</param>
        /// <param name="dataProvider">The market data provider.</param>
        public BlackScholes(Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
            : this(securityProvider, dataProvider)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            Option = option;
        }
Exemplo n.º 25
0
		public ConfigurationInfo(string portfolioName, byte marketDataProviderId, byte executionProviderId)
		{
			this.portfolio = PortfolioManager.Portfolios[portfolioName];
			if (this.portfolio == null)
				this.portfolio = new Portfolio(portfolioName);
			this.marketDataProvider = ProviderManager.MarketDataProviders[marketDataProviderId];
			this.executionProvider = ProviderManager.ExecutionProviders[executionProviderId];
			this.marketDataProviderId = this.marketDataProvider == null ? marketDataProviderId : (byte)0;
			this.executionProviderId = this.executionProvider == null ? executionProviderId : (byte)0;
		}
Exemplo n.º 26
0
 protected override void OnInit()
 {
   InstrumentProviderKey instrumentProviderKey = (InstrumentProviderKey) this.Key;
   this.instrument = instrumentProviderKey.Instrument;
   this.marketDataProvider = (IMarketDataProvider) instrumentProviderKey.Provider;
   if ((int) ((IProvider) this.marketDataProvider).Id != 1)
     ThreadPool.QueueUserWorkItem((WaitCallback) (state => Global.ProviderHelper.RequestMarketData(this.marketDataProvider, this.instrument, (MarketDataType) 4)));
   Global.TimerManager.Start((ITimerItem) this);
   this.Text = string.Format("Order Book [{0}]", (object) ((FIXInstrument) this.instrument).Symbol);
 }
Exemplo n.º 27
0
            public SecurityChangedRule(Security security, IMarketDataProvider provider, Func <Security, bool> condition)
                : base(security, provider)
            {
                _condition = condition ?? throw new ArgumentNullException(nameof(condition));

                Name = LocalizedStrings.Str1046 + " " + security;
#pragma warning disable CS0618 // Type or member is obsolete
                Provider.SecurityChanged += OnSecurityChanged;
#pragma warning restore CS0618 // Type or member is obsolete
            }
Exemplo n.º 28
0
 public void CancelMarketData(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType, string suffix)
 {
     if (this.useMessageLoop)
     {
         this.form.Invoke((Action)(() => instrument.CancelMarketData(provider, mdType, suffix)));
     }
     else
     {
         instrument.CancelMarketData(provider, mdType, suffix);
     }
 }
Exemplo n.º 29
0
		/// <summary>
		/// Initialize <see cref="BlackScholes"/>.
		/// </summary>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		protected BlackScholes(ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			if (securityProvider == null)
				throw new ArgumentNullException(nameof(securityProvider));

			if (dataProvider == null)
				throw new ArgumentNullException(nameof(dataProvider));

			SecurityProvider = securityProvider;
			DataProvider = dataProvider;
		}
Exemplo n.º 30
0
 static ProviderManager()
 {
     ProviderManager.dataLock = new object();
     ProviderManager.executionProviders = new ExecutionProviderList();
     ProviderManager.marketDataProviders = new MarketDataProviderList();
     ProviderManager.instrumentProviders = new InstrumentProviderList();
     ProviderManager.historicalDataProviders = new HistoricalDataProviderList();
     ProviderManager.marketDataProvider = null;
     ProviderManager.executionProvider = null;
     ProviderManager.errors = new ProviderErrorCollection();
 }
Exemplo n.º 31
0
 public void RequestMarketData(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType)
 {
     if (this.useMessageLoop)
     {
         this.form.Invoke((Action)(() => instrument.RequestMarketData(provider, mdType)));
     }
     else
     {
         instrument.RequestMarketData(provider, mdType);
     }
 }
Exemplo n.º 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasketBlackScholes"/>.
        /// </summary>
        /// <param name="securityProvider">The provider of information about instruments.</param>
        /// <param name="dataProvider">The market data provider.</param>
        /// <param name="positionProvider">The position provider.</param>
        public BasketBlackScholes(ISecurityProvider securityProvider, IMarketDataProvider dataProvider, IPositionProvider positionProvider)
            : base(securityProvider, dataProvider)
        {
            if (positionProvider == null)
            {
                throw new ArgumentNullException(nameof(positionProvider));
            }

            _innerModels     = new InnerModelList(this);
            PositionProvider = positionProvider;
        }
Exemplo n.º 33
0
 static ProviderManager()
 {
     ProviderManager.dataLock                = new object();
     ProviderManager.executionProviders      = new ExecutionProviderList();
     ProviderManager.marketDataProviders     = new MarketDataProviderList();
     ProviderManager.instrumentProviders     = new InstrumentProviderList();
     ProviderManager.historicalDataProviders = new HistoricalDataProviderList();
     ProviderManager.marketDataProvider      = null;
     ProviderManager.executionProvider       = null;
     ProviderManager.errors = new ProviderErrorCollection();
 }
Exemplo n.º 34
0
 internal void Refresh()
 {
     if (this.marketDataProvider == null)
     {
         this.marketDataProvider = ProviderManager.MarketDataProviders[this.marketDataProviderId];
     }
     if (this.executionProvider != null)
     {
         return;
     }
     this.executionProvider = ProviderManager.ExecutionProviders[this.executionProviderId];
 }
Exemplo n.º 35
0
 public ConfigurationInfo(string portfolioName, byte marketDataProviderId, byte executionProviderId)
 {
     this.portfolio = PortfolioManager.Portfolios[portfolioName];
     if (this.portfolio == null)
     {
         this.portfolio = new Portfolio(portfolioName);
     }
     this.marketDataProvider   = ProviderManager.MarketDataProviders[marketDataProviderId];
     this.executionProvider    = ProviderManager.ExecutionProviders[executionProviderId];
     this.marketDataProviderId = this.marketDataProvider == null ? marketDataProviderId : (byte)0;
     this.executionProviderId  = this.executionProvider == null ? executionProviderId : (byte)0;
 }
Exemplo n.º 36
0
 public SZKingdomTestController(
     IMarketDataProvider marketDataProvider,
     IOrderManager orderManager,
     IPortfolioManager portfolioManager,
     IAccountManager accountManager,
     IMarketDataService marketDataService)
 {
     _marketDataProvider = marketDataProvider;
     _orderManager       = orderManager;
     _portfolioManager   = portfolioManager;
     _accountManager     = accountManager;
     _marketDataService  = marketDataService;
 }
Exemplo n.º 37
0
 public TradeFactory(IDataContext dataContext, IMarketDataProvider marketDataProvider, ITradeRepository tradeRepository)
 {
     this._portfolioIds = dataContext.Portfolios.Select(portfolio => portfolio.Id).ToArray();
     foreach (Security security in dataContext.Securities.OrderBy(security => security.Ticker))
     {
         this._securities.Add(security);
         this._prices.Add(security.Id, security.OpeningPrice);
     }
     this._marketDataProvider = marketDataProvider;
     this._tradeRepository    = tradeRepository;
     this._timer = new Timer(this.Timer_Elapsed, null, TradeFactory.Interval, TradeFactory.Interval);
     this._marketDataProvider.PricesChanged += this.MarketDataProvider_PricesChanged;
 }
Exemplo n.º 38
0
        protected override void OnInit()
        {
            InstrumentProviderKey instrumentProviderKey = (InstrumentProviderKey)this.Key;

            this.instrument         = instrumentProviderKey.Instrument;
            this.marketDataProvider = (IMarketDataProvider)instrumentProviderKey.Provider;
            if ((int)((IProvider)this.marketDataProvider).Id != 1)
            {
                ThreadPool.QueueUserWorkItem((WaitCallback)(state => Global.ProviderHelper.RequestMarketData(this.marketDataProvider, this.instrument, (MarketDataType)4)));
            }
            Global.TimerManager.Start((ITimerItem)this);
            this.Text = string.Format("Order Book [{0}]", (object)((FIXInstrument)this.instrument).Symbol);
        }
 public MarketDataService(
     IMarketDataProvider marketDataProvider,
     ScannerController scannerController,
     Level1Controller level1Controller,
     OwinStartup owinStartup,
     IAppConfig appConfig)
 {
     _appConfig          = appConfig;
     _level1Controller   = level1Controller;
     _marketDataProvider = marketDataProvider;
     _scannerController  = scannerController;
     _owinStartup        = owinStartup;
 }
Exemplo n.º 40
0
		/// <summary>
		/// Инициализировать <see cref="BasketStrike"/>.
		/// </summary>
		/// <param name="underlyingAsset">Базовый актив.</param>
		/// <param name="securityProvider">Поставщик информации об инструментах.</param>
		/// <param name="dataProvider">Поставщик маркет-данных.</param>
		protected BasketStrike(Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			if (underlyingAsset == null)
				throw new ArgumentNullException("underlyingAsset");

			if (securityProvider == null)
				throw new ArgumentNullException("securityProvider");

			if (dataProvider == null)
				throw new ArgumentNullException("dataProvider");

			UnderlyingAsset = underlyingAsset;
			SecurityProvider = securityProvider;
			DataProvider = dataProvider;
		}
Exemplo n.º 41
0
        private void Init(MarketDataProvider provider, string NewBarOpen, string NewBar, string NewMarketBar)
        {
            _NewBar = NewBar;
            _NewBarOpen = NewBarOpen;
            _NewMarketBar = NewMarketBar;

            //得到OpenQuant.API.MarketDataProvider内的SmartQuant.Providers.IMarketDataProvider接口
            marketDataProvider = (IMarketDataProvider)provider.GetType().GetField("provider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(provider);
            factory = marketDataProvider.BarFactory;

            // 遍历,得到对应的事件
            foreach (var e in marketDataProvider.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                switch (e.FieldType.ToString())
                {
                    case "SmartQuant.Providers.QuoteEventHandler":
                        NewQuoteField = e;
                        // 很遗憾,不能提前在保存下来
                        //(MulticastDelegate)NewQuoteField.GetValue(marketDataProvider);
                        break;
                    case "SmartQuant.Providers.TradeEventHandler":
                        NewTradeField = e;
                        break;
                    case "SmartQuant.Providers.BarEventHandler":
                        // 有三个这样的事件,怎么识别呢?
                        // 由于混淆了代码,没法识别,只能人工先判断
                        // 判断的方法,1.断点,
                        // 2.模拟下的 v8UpctWIWM(SeriesObjectEventArgs args1)
                        if (e.Name == _NewBarOpen)
                        {
                            NewBarOpenField = e;
                        }
                        else if (e.Name == _NewBar)
                        {
                            NewBarField = e;
                        }
                        else if (e.Name == _NewMarketBar)
                        {
                            NewMarketBarField = e;
                        }
                        else
                        {
                            Console.WriteLine("{0} 没有识别出来,需人工处理!", e.Name);
                        }
                        break;
                }
            }
        }
Exemplo n.º 42
0
        public ExtMarketDataFilter(MarketDataProvider provider)
        {
            //得到OpenQuant.API.MarketDataProvider内的SmartQuant.Providers.IMarketDataProvider接口
            marketDataProvider = (IMarketDataProvider)provider.GetType().GetField("provider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(provider);
            factory = marketDataProvider.BarFactory;

            // 遍历,得到对应的两个事件
            foreach (var e in marketDataProvider.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                //Console.WriteLine(e);
                switch (e.FieldType.ToString())
                {
                    case "SmartQuant.Providers.QuoteEventHandler":
                        NewQuoteField = e;
                        // 很遗憾,不能提前在保存下来
                        //(MulticastDelegate)NewQuoteField.GetValue(marketDataProvider);
                        break;
                    case "SmartQuant.Providers.TradeEventHandler":
                        NewTradeField = e;
                        break;
                }
            }
        }
Exemplo n.º 43
0
 private static void DoRequest(IMarketDataProvider provider, Instrument instrument, MarketDataType type, char subCh, string suffix)
 {
     if ((type & MarketDataType.Trade) == MarketDataType.Trade)
         DataManager.DoFixRequest(provider, instrument, MarketDataType.Trade, subCh, suffix);
     if ((type & MarketDataType.Quote) == MarketDataType.Quote)
         DataManager.DoFixRequest(provider, instrument, MarketDataType.Quote, subCh, suffix);
     if ((type & MarketDataType.MarketDepth) != MarketDataType.MarketDepth)
         return;
     DataManager.DoFixRequest(provider, instrument, MarketDataType.MarketDepth, subCh, suffix);
 }
Exemplo n.º 44
0
		// http://riskencyclopedia.com/articles/black_1976/

		/// <summary>
		/// Initializes a new instance of the <see cref="Black"/>.
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		public Black(Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
			: base(option, securityProvider, dataProvider)
		{
		}
Exemplo n.º 45
0
		/// <summary>
		/// To create the volatility order book from usual order book.
		/// </summary>
		/// <param name="depth">The order book quotes of which will be changed to volatility quotes.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <param name="currentTime">The current time.</param>
		/// <param name="riskFree">The risk free interest rate.</param>
		/// <param name="dividend">The dividend amount on shares.</param>
		/// <returns>The order book volatility.</returns>
		public static MarketDepth ImpliedVolatility(this MarketDepth depth, ISecurityProvider securityProvider, IMarketDataProvider dataProvider, DateTimeOffset currentTime, decimal riskFree = 0, decimal dividend = 0)
		{
			if (depth == null)
				throw new ArgumentNullException("depth");

			return depth.ImpliedVolatility(new BlackScholes(depth.Security, securityProvider, dataProvider) { RiskFree = riskFree, Dividend = dividend }, currentTime);
		}
Exemplo n.º 46
0
		/// <summary>
		/// To get the timed option value.
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <returns>The timed value. If it is impossible to get the current market price of the asset then the <see langword="null" /> will be returned.</returns>
		public static decimal? GetTimeValue(this Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			if (securityProvider == null)
				throw new ArgumentNullException("securityProvider");

			option.CheckOption();

			var price = option.GetCurrentPrice(dataProvider);
			var intrinsic = option.GetIntrinsicValue(securityProvider, dataProvider);

			if (price == null || intrinsic == null)
				return null;

			return (decimal)(price - intrinsic);
		}
Exemplo n.º 47
0
		/// <summary>
		/// To get the internal option value.
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <returns>The internal value. If it is impossible to get the current market price of the asset then the <see langword="null" /> will be returned.</returns>
		public static decimal? GetIntrinsicValue(this Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			if (securityProvider == null)
				throw new ArgumentNullException("securityProvider");
			
			option.CheckOption();

			var assetPrice = option.GetUnderlyingAsset(securityProvider).GetCurrentPrice(dataProvider);

			if (assetPrice == null)
				return null;

			return ((decimal)((option.OptionType == OptionTypes.Call) ? assetPrice - option.Strike : option.Strike - assetPrice)).Max(0);
		}
Exemplo n.º 48
0
		/// <summary>
		/// To get at the money options (ATM).
		/// </summary>
		/// <param name="underlyingAsset">Underlying asset.</param>
		/// <param name="provider">The market data provider.</param>
		/// <param name="allStrikes">All strikes.</param>
		/// <returns>At the money options.</returns>
		public static IEnumerable<Security> GetAtTheMoney(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)
		{
			if (underlyingAsset == null)
				throw new ArgumentNullException("underlyingAsset");

			var centralStrikes = new List<Security>();

			var cs = underlyingAsset.GetCentralStrike(provider, allStrikes.Filter(OptionTypes.Call));

			if (cs != null)
				centralStrikes.Add(cs);

			cs = underlyingAsset.GetCentralStrike(provider, allStrikes.Filter(OptionTypes.Put));

			if (cs != null)
				centralStrikes.Add(cs);

			return centralStrikes;
		}
Exemplo n.º 49
0
		/// <summary>
		/// To get at the money options (ATM).
		/// </summary>
		/// <param name="underlyingAsset">Underlying asset.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <returns>At the money options.</returns>
		public static IEnumerable<Security> GetAtTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)
		{
			return underlyingAsset.GetAtTheMoney(dataProvider, underlyingAsset.GetDerivatives(securityProvider));
		}
Exemplo n.º 50
0
 private static void LogRequestMessage(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType, string obj3)
 {
     if (Trace.IsLevelEnabled(TraceLevel.Warning))
     {
         Trace.WriteLine("" + Environment.NewLine + "" + provider.Name + Environment.NewLine + "Symbol" + instrument.Symbol + Environment.NewLine + "Type:" + mdType.ToString() + Environment.NewLine + "" + obj3);
     }
 }
Exemplo n.º 51
0
 public static void CancelMarketData(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType)
 {
     DataManager.CancelMarketData(provider, instrument, mdType, SERIES_SEPARATOR + "UNSUBSCRIBE");
 }
Exemplo n.º 52
0
		public BarSliceEventArgs(long barSize, IMarketDataProvider provider) : base()
		{
			this.BarSize = barSize;
			this.Provider = provider;
		}
Exemplo n.º 53
0
 public static void CancelMarketData(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType, string suffix)
 {
     DataManager.DoRequest(provider, instrument, mdType, MARKET_DATA_UNSUBSCRIBE, suffix);
 }
Exemplo n.º 54
0
    protected StrategyBase(string name, string description)
    {
      this.metaStrategyBase = (MetaStrategyBase) null;
      this.name = name;
      this.description = description;
      this.isEnabled = true;
      this.isActive = true;
			this.ReportManager = StrategyComponentManager.GetComponent("getcom", (object) this) as ReportManager;
			this.MarketManager = StrategyComponentManager.GetComponent("getcom", (object) this) as MarketManager;
      this.portfolio = PortfolioManager.Portfolios[name];
      if (this.portfolio == null)
        this.portfolio = new Portfolio(name);
      this.tester = new LiveTester(this.portfolio);
      this.stops = new StopList();
      this.triggers = new TriggerList();
      this.marketDataProvider = (IMarketDataProvider) null;
      this.executionProvider = (IExecutionProvider) null;
      this.newsProvider = (INewsProvider) null;
      this.executionService = (IExecutionService) null;
      this.orders = new OrderTable();
      this.global = new Hashtable();
      this.activeInstruments = new InstrumentList();
      this.barSliceManager = new BarSliceManager();
      this.componentTypeList = new List<ComponentType>();
      this.componentTypeList.Add(ComponentType.MarketManager);
      this.componentTypeList.Add(ComponentType.ReportManager);
      this.activeStops = new Dictionary<Instrument, List<StopBase>>();
      this.portfolios = new Dictionary<Instrument, Portfolio>();
      this.testers = new Dictionary<Instrument, LiveTester>();
      this.statisticsPerInstrumentEnabled = false;
    }
Exemplo n.º 55
0
 public static bool IsSubscribed(IMarketDataProvider provider, Instrument instrument, MarketDataType mdType)
 {
     lock (DataManager.providers)
     {
         Hashtable local_0 = DataManager.providers[provider] as Hashtable;
         if (local_0 == null)
             return false;
         Hashtable local_1 = local_0[instrument] as Hashtable;
         if (local_1 == null)
             return false;
         else
             return local_1.ContainsKey(mdType);
     }
 }
Exemplo n.º 56
0
		/// <summary>
		/// To get the main strike.
		/// </summary>
		/// <param name="underlyingAsset">Underlying asset.</param>
		/// <param name="securityProvider">The provider of information about instruments.</param>
		/// <param name="dataProvider">The market data provider.</param>
		/// <param name="expirationDate">The options expiration date.</param>
		/// <param name="optionType">Option type.</param>
		/// <returns>The main strike.</returns>
		public static Security GetCentralStrike(this Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider, DateTimeOffset expirationDate, OptionTypes optionType)
		{
			return underlyingAsset.GetCentralStrike(dataProvider, underlyingAsset.GetDerivatives(securityProvider, expirationDate).Filter(optionType));
		}
Exemplo n.º 57
0
 private static void DoFixRequest(IMarketDataProvider provider, Instrument instrument, MarketDataType type, char subCh, string suffix)
 {
     FIXMarketDataRequest request = new FIXMarketDataRequest();
     request.MDReqID = DataManager.GetRequestId();
     request.SubscriptionRequestType = subCh;
     switch (type)
     {
         case MarketDataType.Trade:
             request.AddGroup(new FIXMDEntryTypesGroup('2'));
             break;
         case MarketDataType.Quote:
             request.AddGroup(new FIXMDEntryTypesGroup('0'));
             request.AddGroup(new FIXMDEntryTypesGroup('1'));
             request.MarketDepth = 1;  // Top of Book
             break;
         case MarketDataType.MarketDepth:
             request.AddGroup(new FIXMDEntryTypesGroup('0'));
             request.AddGroup(new FIXMDEntryTypesGroup('1'));
             request.MarketDepth = 0;  // Full Book
             break;
     }
     if (!instrument.ContainsField(15))
         instrument.Currency = Framework.Configuration.DefaultCurrency;
     FIXRelatedSymGroup symGrp = new FIXRelatedSymGroup();
     request.AddGroup(symGrp);
     symGrp.Symbol = instrument.Symbol;
     symGrp.SecurityType = instrument.SecurityType;
     symGrp.SecurityExchange = instrument.SecurityExchange;
     symGrp.Currency = instrument.Currency;
     symGrp.SecurityID = instrument.SecurityID;
     symGrp.SecurityIDSource = instrument.SecurityIDSource;
     symGrp.MaturityDate = instrument.MaturityDate;
     symGrp.MaturityMonthYear = instrument.MaturityMonthYear;
     symGrp.StrikePrice = instrument.StrikePrice;
     symGrp.PutOrCall = ((FIXInstrument)instrument).PutOrCall;
     foreach (FIXSecurityAltIDGroup group2 in instrument.SecurityAltIDGroup)
         symGrp.AddGroup(group2);
     symGrp.SetStringValue(10001, suffix);
     if (provider == ProviderManager.MarketDataSimulator)
     {
         provider.SendMarketDataRequest(request);
     }
     else
     {
         switch (subCh)
         {
             case MARKET_DATA_SUBSCRIBE:
                 bool flag1 = false;
                 lock (DataManager.providers)
                 {
                     Hashtable local_4 = DataManager.providers[provider] as Hashtable;
                     if (local_4 == null)
                     {
                         local_4 = new Hashtable();
                         DataManager.providers.Add(provider, local_4);
                     }
                     Hashtable local_5 = local_4[instrument] as Hashtable;
                     if (local_5 == null)
                     {
                         local_5 = new Hashtable();
                         local_4.Add(instrument, local_5);
                     }
                     RequestItem local_6 = local_5[type] as RequestItem;
                     if (local_6 == null)
                     {
                         local_6 = new RequestItem(request);
                         local_5.Add(type, local_6);
                         flag1 = true;
                     }
                     RequestItem temp_91 = local_6;
                     int temp_94 = temp_91.GetRequestId() + 1;
                     temp_91.SetRequestId(temp_94);
                 }
                 if (!flag1)
                     break;
                 provider.SendMarketDataRequest(request);
                 break;
             case MARKET_DATA_UNSUBSCRIBE:
                 bool canSend = false;
                 string msg = null;
                 lock (DataManager.providers)
                 {
                     Hashtable local_10 = DataManager.providers[provider] as Hashtable;
                     if (local_10 != null)
                     {
                         Hashtable local_11 = local_10[instrument] as Hashtable;
                         if (local_11 != null)
                         {
                             RequestItem local_12 = local_11[type] as RequestItem;
                             if (local_12 != null)
                             {
                                 RequestItem temp_152 = local_12;
                                 int temp_155 = temp_152.GetRequestId() - 1;
                                 temp_152.SetRequestId(temp_155);
                                 if (local_12.GetRequestId() == 0)
                                 {
                                     local_11.Remove(type);
                                     if (local_11.Count == 0)
                                     {
                                         local_10.Remove(instrument);
                                         if (local_10.Count == 0)
                                             DataManager.providers.Remove(provider);
                                     }
                                     canSend = true;
                                 }
                             }
                             else
                                 msg = "No this RequestItem";
                         }
                         else
                             msg = "No Request for this instrument";
                     }
                     else
                         msg = "No Request for this provider";
                 }
                 if (msg != null)
                     DataManager.LogRequestMessage(provider, instrument, type, msg);
                 if (!canSend)
                     break;
                 provider.SendMarketDataRequest(request);
                 break;
         }
     }
 }
Exemplo n.º 58
0
		/// <summary>
		/// To get the main strike.
		/// </summary>
		/// <param name="underlyingAsset">Underlying asset.</param>
		/// <param name="provider">The market data provider.</param>
		/// <param name="allStrikes">All strikes.</param>
		/// <returns>The main strike. If it is impossible to get the current market price of the asset then the <see langword="null" /> will be returned.</returns>
		public static Security GetCentralStrike(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)
		{
			var assetPrice = underlyingAsset.GetCurrentPrice(provider);

			return assetPrice == null
				? null
				: allStrikes.OrderBy(s => Math.Abs((decimal)(s.Strike - assetPrice))).FirstOrDefault();
		}
Exemplo n.º 59
0
    protected override void OnInit()
    {
      this.provider = this.Key as IMarketDataProvider;
		this.provider.Connected += new EventHandler(this.OnConnected);
			this.provider.Disconnected += new EventHandler(this.OnDisconnected);
      // ISSUE: method pointer
			this.provider.NewTrade += new TradeEventHandler(this.OnNewTrade);
      // ISSUE: method pointer
			this.provider.NewQuote += new QuoteEventHandler(this.OnNewQuote);
      // ISSUE: method pointer
			this.provider.NewBar += new BarEventHandler(this.OnNewBar);
      // ISSUE: method pointer
			this.provider.NewMarketDepth += new MarketDepthEventHandler(this.OnNewMarketDepth);
      this.TabText = string.Format("Data Capture [{0}]", this.provider.Name);
      this.UpdateStatusBar();
    }
Exemplo n.º 60
0
		/// <summary>
		/// To get in the money options (ITM).
		/// </summary>
		/// <param name="underlyingAsset">Underlying asset.</param>
		/// <param name="provider">The market data provider.</param>
		/// <param name="allStrikes">All strikes.</param>
		/// <returns>In the money options.</returns>
		public static IEnumerable<Security> GetInTheMoney(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)
		{
			if (underlyingAsset == null)
				throw new ArgumentNullException("underlyingAsset");

			var cs = underlyingAsset.GetCentralStrike(provider, allStrikes);

			return allStrikes.Where(s => s.OptionType == OptionTypes.Call ? s.Strike > cs.Strike : s.Strike < cs.Strike);
		}