Example #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);
        }
        public void ValidatesOrders(OrderType orderType, Symbol symbol, decimal quantity, decimal stopPrice, decimal limitPrice, bool isValid)
        {
            var security = CreateSecurity(symbol);

            security.SetMarketPrice(new Tick {
                Value = symbol == Symbols.EURUSD ? 1m : 10000m
            });

            var request = new SubmitOrderRequest(orderType, symbol.SecurityType, symbol, quantity, stopPrice, limitPrice, DateTime.UtcNow, "");
            var order   = Order.CreateOrder(request);

            var model = new FxcmBrokerageModel();

            BrokerageMessageEvent messageEvent;

            Assert.AreEqual(isValid, model.CanSubmitOrder(security, order, out messageEvent));
        }
Example #3
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);
        }