예제 #1
0
        public void MarketOrderFillsAtBidAsk(OrderDirection direction)
        {
            var symbol           = Symbol.Create("EURUSD", SecurityType.Forex, "fxcm");
            var exchangeHours    = SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork);
            var quoteCash        = new Cash("USD", 1000, 1);
            var symbolProperties = SymbolProperties.GetDefault("USD");
            var config           = new SubscriptionDataConfig(typeof(Tick), symbol, Resolution.Tick, TimeZones.NewYork, TimeZones.NewYork, true, true, false);
            var security         = new Forex(exchangeHours, quoteCash, config, symbolProperties);

            var reference    = DateTime.Now;
            var referenceUtc = reference.ConvertToUtc(TimeZones.NewYork);
            var timeKeeper   = new TimeKeeper(referenceUtc);

            security.SetLocalTimeKeeper(timeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));

            var brokerageModel = new FxcmBrokerageModel();
            var fillModel      = brokerageModel.GetFillModel(security);

            const decimal bidPrice = 1.13739m;
            const decimal askPrice = 1.13746m;

            security.SetMarketPrice(new Tick(DateTime.Now, symbol, bidPrice, askPrice));

            var quantity = direction == OrderDirection.Buy ? 1 : -1;
            var order    = new MarketOrder(symbol, quantity, DateTime.Now);
            var fill     = fillModel.MarketFill(security, order);

            var expected = direction == OrderDirection.Buy ? askPrice : bidPrice;

            Assert.AreEqual(expected, fill.FillPrice);
        }
예제 #2
0
        public void MarketOrderFillsAtBidAsk(OrderDirection direction)
        {
            var symbol           = Symbol.Create("EURUSD", SecurityType.Forex, "fxcm");
            var exchangeHours    = SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork);
            var quoteCash        = new Cash(Currencies.USD, 1000, 1);
            var symbolProperties = SymbolProperties.GetDefault(Currencies.USD);
            var config           = new SubscriptionDataConfig(typeof(Tick), symbol, Resolution.Tick, TimeZones.NewYork, TimeZones.NewYork, true, true, false);
            var security         = new Forex(exchangeHours, quoteCash, config, symbolProperties, ErrorCurrencyConverter.Instance, RegisteredSecurityDataTypesProvider.Null);

            var reference    = DateTime.Now;
            var referenceUtc = reference.ConvertToUtc(TimeZones.NewYork);
            var timeKeeper   = new TimeKeeper(referenceUtc);

            security.SetLocalTimeKeeper(timeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));

            var brokerageModel = new FxcmBrokerageModel();
            var fillModel      = brokerageModel.GetFillModel(security);

            const decimal bidPrice = 1.13739m;
            const decimal askPrice = 1.13746m;

            security.SetMarketPrice(new Tick(DateTime.Now, symbol, bidPrice, askPrice));

            var quantity = direction == OrderDirection.Buy ? 1 : -1;
            var order    = new MarketOrder(symbol, quantity, DateTime.Now);
            var fill     = fillModel.Fill(new FillModelParameters(
                                              security,
                                              order,
                                              new MockSubscriptionDataConfigProvider(config),
                                              Time.OneHour)).OrderEvent;

            var expected = direction == OrderDirection.Buy ? askPrice : bidPrice;

            Assert.AreEqual(expected, fill.FillPrice);
            Assert.AreEqual(0, fill.OrderFee.Value.Amount);
        }