コード例 #1
0
 public PlaceStrategyTakeProfitByPointsOnTrade(StrategyHeader strategyHeader)
     : this(strategyHeader,
            TradingData.Instance,
            SignalQueue.Instance,
            DefaultLogger.Instance)
 {
 }
コード例 #2
0
ファイル: CancelOrderOnTrade.cs プロジェクト: w1r2p1/TRx
        public override void OnItemAdded(Trade item)
        {
            StrategyHeader strategyHeader = item.Order.Signal.Strategy;

            if (strategyHeader == null)
            {
                return;
            }

            IEnumerable <Order> unfilled = this.tradingData.Get <ICollection <Order> >().GetUnfilled(strategyHeader);

            if (unfilled == null || unfilled.Count() == 0)
            {
                return;
            }

            foreach (Order o in unfilled)
            {
                if (this.tradingData.GetAmount(strategyHeader) == 0)
                {
                    if (!CancelOrderRequestExists(o.Id))
                    {
                        string descr = String.Format("Отменить заявку {0}, потому что позиция была закрыта заявкой {1}", o.ToString(), item.Order.ToString());
                        this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, {2}", DateTime.Now, this.GetType().Name, descr));
                        this.tradingData.Get <ObservableHashSet <OrderCancellationRequest> >().Add(new OrderCancellationRequest(o, descr));
                    }
                }
            }
        }
コード例 #3
0
ファイル: UpdatePositionOnTrade.cs プロジェクト: w1r2p1/TRx
        private bool StrategyExists(Trade item)
        {
            if (item.Order == null)
            {
                return(false);
            }

            if (item.Order.Signal == null)
            {
                return(false);
            }

            if (item.Order.Signal.Strategy == null)
            {
                return(false);
            }

            StrategyHeader strategyHeader = item.Order.Signal.Strategy;

            return(this.tradingData.Get <IEnumerable <StrategyHeader> >().Any(s => s.Id == strategyHeader.Id &&
                                                                              s.Description == strategyHeader.Description &&
                                                                              s.Portfolio == strategyHeader.Portfolio &&
                                                                              s.Symbol == strategyHeader.Symbol &&
                                                                              s.Amount == strategyHeader.Amount));
        }
コード例 #4
0
        /// <summary>
        /// пример переопределения
        /// Program.Sample1.SetupStrategy()
        /// </summary>
        /// <param name="args"></param>
        override public void SetupStrategy(string[] args)
        {
            Console.WriteLine("BackTest.Converter.SetupStrategy()");
            // инициализация обработчиков стратегии
            //strategySample1 = new Strategy.Sample1(args);
            //strategyHeader = strategySample1.strategyHeader;
            //AppSettings.GetStringValue("Symbol")
            string symbol = System.Configuration.ConfigurationManager.AppSettings["Symbol"];

            //Console.WriteLine(String.Format("Sybol: {0}", symbol));
            if (symbol == "")
            {
                symbol = null;
            }

            StrategyHeader strategyHeader = new StrategyHeader(1, "Sample strategyHeader", null, symbol, 1);
            BarSettings    barSettings    = new BarSettings(
                strategyHeader,
                strategyHeader.Symbol,
                //null,
                AppSettings.GetValue <int>("Interval"),
                AppSettings.GetValue <int>("Period"));

            TradingData.Instance.Get <ICollection <StrategyHeader> >().Add(strategyHeader);

            //BarSettings barSettings = new BarSettings(strategyHeader, "RIH4", 3600, 3);
            //BarSettings barSettings = new BarSettings(strategyHeader, "SPFB.RTS-3.14", 3600, 3);
            //TradingData.Instance.Get<ICollection<BarSettings>>().Add(barSettings);

            MakeRangeBarsOnTick updateBarsHandler =
                new MakeRangeBarsOnTick(barSettings,
                                        new TimeTracker(),
                                        TradingData.Instance,
                                        DefaultLogger.Instance);
        }
コード例 #5
0
        public void TradeCollectionExtensions_Combine_remove_first_three_trades_from_collection_test()
        {
            StrategyHeader strategyHeader = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 4);
            Signal         signal         = new Signal(strategyHeader, DateTime.Now, TradeAction.Buy, OrderType.Market, 10500, 0, 0);

            EmulateTradeFor(signal, 10500, 10);
            EmulateTradeFor(signal, 10500, 5);
            EmulateTradeFor(signal, 10500, 5);

            this.trades.Add(this.tradingData.Get <IEnumerable <Trade> >().Last());
            Assert.AreEqual(1, this.trades.Count);

            Signal s2 = new Signal(strategyHeader, DateTime.Now, TradeAction.Buy, OrderType.Market, 10500, 0, 0);

            EmulateTradeFor(s2);

            Trade second = this.tradingData.Get <IEnumerable <Trade> >().Last();

            this.trades.Add(second);
            Assert.AreEqual(2, this.trades.Count);

            Signal cClose = new Signal(strategyHeader, DateTime.Now, TradeAction.Sell, OrderType.Market, 10500, 0, 0);

            EmulateTradeFor(cClose);
            Trade lastTrade = this.tradingData.Get <IEnumerable <Trade> >().Last();

            this.trades.Combine(lastTrade);
            Assert.AreEqual(1, this.trades.Count);

            Assert.AreSame(second, this.trades.Last());
        }
コード例 #6
0
        public void TradingDataContext_GetFilledPartially_stop_orders()
        {
            StrategyHeader st1 = new StrategyHeader(1, "Strategy 1", "BP12345-RF-01", "RTS-9.13_FT", 8);

            this.tradingData.Get <ICollection <StrategyHeader> >().Add(st1);

            Signal s1 = new Signal(st1, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Stop, 150000, 150000, 0);

            this.tradingData.Get <ICollection <Signal> >().Add(s1);

            Order o1 = new Order(s1);

            o1.FilledAmount = 2;
            Assert.IsFalse(o1.IsFilled);
            Assert.IsTrue(o1.IsFilledPartially);
            Assert.IsFalse(o1.IsCanceled);
            Assert.IsFalse(o1.IsExpired);
            Assert.IsFalse(o1.IsRejected);

            this.tradingData.Get <ICollection <Order> >().Add(o1);

            IEnumerable <Order> unfilled = this.tradingData.GetFilledPartially(st1, OrderType.Stop);

            Assert.AreEqual(1, unfilled.Count());

            Assert.AreSame(unfilled.Last(), o1);
        }
コード例 #7
0
 public StrategyStopLossByPointsOnTick(StrategyHeader strategyHeader, bool measureFromSignalPrice = false)
     : this(strategyHeader,
            TradingData.Instance,
            SignalQueue.Instance,
            DefaultLogger.Instance, measureFromSignalPrice)
 {
 }
コード例 #8
0
        public void Handlers_TraderBaseInitializer_EmulateTradeFor_sell_Signal_with_price_and_amount_test()
        {
            StrategyHeader strategyHeader = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 2);
            Signal         signal         = new Signal(strategyHeader, DateTime.Now, TradeAction.Sell, OrderType.Market, 32000, 0, 0);

            this.signalQueue.Enqueue(signal);

            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Trade> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Position> >().Count());
            Assert.AreEqual(0, this.tradingData.GetAmount(strategyHeader));

            double price  = 32001;
            double amount = 1;

            EmulateTradeFor(signal, price, amount);

            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Trade> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Position> >().Count());
            Assert.AreEqual(-1, this.tradingData.GetAmount(strategyHeader));

            Trade trade = this.tradingData.Get <IEnumerable <Trade> >().Last();

            Assert.AreEqual(price, trade.Price);
            Assert.AreEqual(-amount, trade.Amount);
        }
コード例 #9
0
        public void Setup()
        {
            this.tradingData = new TradingDataContext();
            this.signalQueue = new ObservableQueue <Signal>();

            this.strategyHeader = new StrategyHeader(1, "Description", "ST12345-RF-01", "RTS-9.14", 10);
            this.tradingData.Get <ICollection <StrategyHeader> >().Add(this.strategyHeader);

            this.spSettings = new StopPointsSettings(this.strategyHeader, 100, false);
            this.tradingData.Get <ICollection <StopPointsSettings> >().Add(this.spSettings);

            this.slSettings = new StopLossOrderSettings(this.strategyHeader, 180);
            this.tradingData.Get <ICollection <StopLossOrderSettings> >().Add(this.slSettings);

            this.handler =
                new StrategyStopLossByPointsOnTick(this.strategyHeader, this.tradingData, this.signalQueue, new NullLogger(), true);

            this.buySignal =
                new Signal(this.strategyHeader, DateTime.Now, TradeAction.Buy, OrderType.Market, 125000, 0, 0);
            this.sellSignal =
                new Signal(this.strategyHeader, DateTime.Now, TradeAction.Sell, OrderType.Market, 125000, 0, 0);

            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(0, this.signalQueue.Count);
        }
コード例 #10
0
ファイル: MakeBarsOnTickTests.cs プロジェクト: w1r2p1/TRx
        public void Handlers_Make_Fifteen_Minutes_Bars()
        {
            DateTime start = new DateTime(2013, 5, 15, 0, 0, 0);

            DateTime end = new DateTime(2013, 5, 16, 11, 0, 0);

            FakeTimeTracker tt       = new FakeTimeTracker(start, end);
            StrategyHeader  s        = new StrategyHeader(1, "Strategy 2", "BP12345-RF-01", "RTS-12.12_FT", 10);
            BarSettings     settings = new BarSettings(s, "RTS-12.12_FT", 900, 10);

            MakeBarsOnTick updateBars = new MakeBarsOnTick(settings, tt, this.tradingData, new NullLogger());

            this.tradingData.Get <ObservableCollection <Bar> >().Add(new Bar {
                Symbol = "RTS-12.12_FT", DateTime = start, Open = 150000, High = 160000, Low = 140000, Close = 145000, Volume = 100
            });
            this.tradingData.Get <ObservableCollection <Bar> >().Add(new Bar {
                Symbol = "RTS-12.12_FT", DateTime = end, Open = 150000, High = 160000, Low = 140000, Close = 145000, Volume = 100
            });

            Assert.AreEqual(2, this.tradingData.Get <ObservableCollection <Bar> >().Count);


            for (int i = 0; i < settings.Interval * 4; i++)
            {
                this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                    DateTime = end.AddSeconds(i), Symbol = "RTS-12.12_FT", Price = 150000 + i, TradeAction = TradeAction.Buy, Volume = 100
                });

                if (i == 1000)
                {
                    this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                        DateTime = end.AddSeconds(1000), Symbol = "RTS-12.12_FT", Price = 149000, TradeAction = TradeAction.Buy, Volume = 100
                    });
                    this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                        DateTime = end.AddSeconds(2000), Symbol = "RTS-12.12_FT", Price = 154500, TradeAction = TradeAction.Buy, Volume = 100
                    });
                }

                tt.IncrementStopDate(1);
            }

            this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                DateTime = end.AddSeconds(-1), Symbol = "RTS-12.12_FT", Price = 148000, TradeAction = TradeAction.Buy, Volume = 100
            });
            this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                DateTime = end.AddSeconds(3600), Symbol = "RTS-12.12_FT", Price = 155500, TradeAction = TradeAction.Buy, Volume = 100
            });

            Assert.AreEqual(6, this.tradingData.Get <ObservableCollection <Bar> >().Count);

            Bar bar = this.tradingData.Get <ObservableCollection <Bar> >().Last();

            Assert.AreEqual("RTS-12.12_FT", this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).Symbol);
            Assert.AreEqual(end.AddHours(1), this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).DateTime);
            Assert.AreEqual(152700, this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).Low);
            Assert.AreEqual(153599, this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).High);
            Assert.AreEqual(152700, this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).Open);
            Assert.AreEqual(153599, this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).Close);
            Assert.AreEqual(90000, this.tradingData.Get <ObservableCollection <Bar> >().ElementAt(5).Volume);
        }
コード例 #11
0
        public void Transaction_ExportOrdersTransaction_do_nothing_when_no_orders_exists()
        {
            StrategyHeader st1 = new StrategyHeader(1, "First strategyHeader", "BP12345-RF-01", "RTS-9.13_FT", 10);

            this.tradingData.Get <ICollection <StrategyHeader> >().Add(st1);

            StrategyHeader st2 = new StrategyHeader(2, "Second strategyHeader", "BP12345-RF-01", "RTS-9.13_FT", 8);

            this.tradingData.Get <ICollection <StrategyHeader> >().Add(st2);

            StrategyHeader st3 = new StrategyHeader(3, "Third strategyHeader", "BP12345-RF-01", "RTS-9.13_FT", 5);

            this.tradingData.Get <ICollection <StrategyHeader> >().Add(st3);

            Signal s1 = new Signal(st1, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Market, 150000, 0, 0);

            this.tradingData.Get <ICollection <Signal> >().Add(s1);

            Signal s2 = new Signal(st2, BrokerDateTime.Make(DateTime.Now), TradeAction.Sell, OrderType.Limit, 150000, 0, 150000);

            this.tradingData.Get <ICollection <Signal> >().Add(s2);

            Signal s3 = new Signal(st3, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Stop, 150000, 150000, 0);

            this.tradingData.Get <ICollection <Signal> >().Add(s3);

            ITransaction export = new ExportOrdersTransaction((IObservableHashSetFactory)this.tradingData, this.path);

            export.Execute();
            Assert.IsFalse(File.Exists(this.path));
        }
コード例 #12
0
ファイル: MakeBarsOnTickTests.cs プロジェクト: w1r2p1/TRx
        public void Handlers_Do_Nothing_If_Bar_With_Same_Date_Exists()
        {
            StrategyHeader s           = new StrategyHeader(1, "Strategy 1", "BP12345-RF-01", "RTS-12.12_FT", 10);
            BarSettings    barSettings = new BarSettings(s, "RTS-12.12_FT", 3600, 19);

            DateTime start = new DateTime(2013, 5, 15, 10, 0, 0);

            FakeTimeTracker tt = new FakeTimeTracker(start, start);

            this.tradingData.Get <ObservableCollection <Bar> >().Add(new Bar {
                Symbol = barSettings.Symbol, DateTime = start.AddHours(1), Open = 100, High = 100, Low = 100, Close = 100, Volume = 100
            });

            MakeBarsOnTick updateBars = new MakeBarsOnTick(barSettings, tt, this.tradingData, new NullLogger());

            Assert.AreEqual(1, this.tradingData.Get <ObservableCollection <Bar> >().Count);


            for (int i = 0; i < barSettings.Interval; i++)
            {
                this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                    DateTime = start.AddSeconds(i), Symbol = "RTS-12.12_FT", Price = 150000 + i, TradeAction = TradeAction.Buy, Volume = 100
                });

                if (i == 1000)
                {
                    this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                        DateTime = start.AddSeconds(1000), Symbol = "RTS-12.12_FT", Price = 149000, TradeAction = TradeAction.Buy, Volume = 100
                    });
                    this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                        DateTime = start.AddSeconds(2000), Symbol = "RTS-12.12_FT", Price = 154500, TradeAction = TradeAction.Buy, Volume = 100
                    });
                }

                tt.IncrementStopDate(1);
            }

            this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                DateTime = start.AddSeconds(-1), Symbol = "RTS-12.12_FT", Price = 148000, TradeAction = TradeAction.Buy, Volume = 100
            });
            this.tradingData.Get <ObservableCollection <Tick> >().Add(new Tick {
                DateTime = start.AddSeconds(3600), Symbol = "RTS-12.12_FT", Price = 155500, TradeAction = TradeAction.Buy, Volume = 100
            });

            IEnumerable <Tick> ticks = this.tradingData.Get <ObservableCollection <Tick> >().Where(t => t.DateTime >= start && t.DateTime < start.AddSeconds(3600));

            Assert.AreEqual(3602, ticks.Count());

            Assert.AreEqual(1, this.tradingData.Get <ObservableCollection <Bar> >().Count);

            Bar bar = this.tradingData.Get <ObservableCollection <Bar> >().First();

            Assert.AreEqual("RTS-12.12_FT", bar.Symbol);
            Assert.AreEqual(start.AddHours(1), bar.DateTime);
            Assert.AreEqual(100, bar.Low);
            Assert.AreEqual(100, bar.High);
            Assert.AreEqual(100, bar.Open);
            Assert.AreEqual(100, bar.Close);
            Assert.AreEqual(100, bar.Volume);
        }
コード例 #13
0
        public void BuySpreadOnQuote_ignore_updates_when_any_position_from_basket_of_strategies_exists()
        {
            StrategyHeader strtgy = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 1);

            Signal sgnl = new Signal(strtgy, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Market, 143000, 0, 0);

            this.tradingData.Get <ICollection <Signal> >().Add(sgnl);

            Order ordr = new Order(sgnl);

            this.tradingData.Get <ICollection <Order> >().Add(ordr);

            OrderDeliveryConfirmation cnfrmtn = new OrderDeliveryConfirmation(ordr, BrokerDateTime.Make(DateTime.Now));

            this.tradingData.Get <ObservableHashSet <OrderDeliveryConfirmation> >().Add(cnfrmtn);
            Assert.IsTrue(ordr.IsDelivered);

            Trade trd = new Trade(ordr, ordr.Portfolio, ordr.Symbol, 1430000, ordr.Amount, BrokerDateTime.Make(DateTime.Now));

            this.tradingData.Get <ObservableHashSet <Trade> >().Add(trd);
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Position> >().Count());

            this.qProvider.Update(0, "RTS-12.13_FT", 128990, 20, 129000, 100);
            this.qProvider.Update(0, "Si-12.13_FT", 33000, 50, 33001, 40);
            this.qProvider.Update(0, "Eu-12.13_FT", 44000, 30, 44001, 0);

            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Signal> >().Count());
        }
コード例 #14
0
        public void Setup()
        {
            Symbol symbol = new Symbol("RTS-9.13_FT", 1, 8, 10, BrokerDateTime.Make(DateTime.Now));

            this.tradingData.Get <HashSetOfNamedMutable <Symbol> >().Add(symbol);

            this.strategyHeader = new StrategyHeader(10, "strategyHeader", "BP12345-RF-01", "RTS-9.13_FT", 10);
            this.tradingData.Get <ICollection <StrategyHeader> >().Add(this.strategyHeader);

            StopPointsSettings slSettings = new StopPointsSettings(this.strategyHeader, 300, false);

            this.tradingData.Get <ICollection <StopPointsSettings> >().Add(slSettings);

            ProfitPointsSettings tpSettings = new ProfitPointsSettings(this.strategyHeader, 500, false);

            this.tradingData.Get <ICollection <ProfitPointsSettings> >().Add(tpSettings);

            StopLossOrderSettings slOrderSettings = new StopLossOrderSettings(this.strategyHeader, 3600);

            this.tradingData.Get <ICollection <StopLossOrderSettings> >().Add(slOrderSettings);

            TakeProfitOrderSettings tpOrderSettings = new TakeProfitOrderSettings(this.strategyHeader, 3600);

            this.tradingData.Get <ICollection <TakeProfitOrderSettings> >().Add(tpOrderSettings);

            StrategyStopLossByPointsOnTick stopLossHandler =
                new StrategyStopLossByPointsOnTick(strategyHeader, this.tradingData, this.signalQueue, new NullLogger());
            StrategyTakeProfitByPointsOnTick takeProfitHandler =
                new StrategyTakeProfitByPointsOnTick(strategyHeader, this.tradingData, this.signalQueue, new NullLogger());

            PlaceStrategyStopLossByPointsOnTrade placeStopOnTradeHandler =
                new PlaceStrategyStopLossByPointsOnTrade(strategyHeader, this.tradingData, this.signalQueue, new NullLogger());
            PlaceStrategyTakeProfitByPointsOnTrade placeTakeProfitOnTradeHandler =
                new PlaceStrategyTakeProfitByPointsOnTrade(strategyHeader, this.tradingData, this.signalQueue, new NullLogger());
        }
コード例 #15
0
        public void SetDeliveryDate_test()
        {
            StrategyHeader strategyHeader = new StrategyHeader(1, "Sample strategyHeader", "BP12345-RF-01", "RTS-9.13_FT", 10);

            this.tradingData.Get <ICollection <StrategyHeader> >().Add(strategyHeader);

            Signal signal = new Signal(strategyHeader, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Market, 150000, 0, 0);

            this.tradingData.Get <ICollection <Signal> >().Add(signal);

            Order order = new Order(signal, 150);

            this.tradingData.Get <ICollection <Order> >().Add(order);
            Assert.IsFalse(order.IsDelivered);
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <OrderDeliveryConfirmation> >().Count());

            OrderSucceeded os = new OrderSucceeded(order.Id, "12345");

            this.rawData.GetData <OrderSucceeded>().Add(os);

            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <OrderDeliveryConfirmation> >().Count());
            OrderDeliveryConfirmation confirmation = this.tradingData.Get <IEnumerable <OrderDeliveryConfirmation> >().Last();

            Assert.AreEqual(order.Id, confirmation.OrderId);
            Assert.AreEqual(order, confirmation.Order);
            Assert.AreEqual(os.DateTime, confirmation.DateTime);
        }
コード例 #16
0
        public void Handlers_place_stop_order_when_no_any_unfilled_orders_exists()
        {
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <ObservableHashSet <OrderCancellationConfirmation> >().Count);

            StrategyHeader strategyHeader = this.tradingData.Get <ICollection <StrategyHeader> >().Single(s => s.Id == 2);
            Signal         signal         = new Signal(strategyHeader, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Stop, 150000, 150100, 0);

            this.signalQueue.Enqueue(signal);

            Assert.AreEqual(1, this.orderQueue.Count);
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(0, this.signalQueue.Count);
            Assert.AreEqual(1, this.orderQueue.Count);

            Order order = this.orderQueue.Dequeue();

            Assert.IsTrue(order.Id > 0);
            Assert.AreEqual(strategyHeader.Portfolio, order.Portfolio);
            Assert.AreEqual(strategyHeader.Symbol, order.Symbol);
            Assert.AreEqual(strategyHeader.Amount, order.Amount);
            Assert.AreEqual(signal.TradeAction, order.TradeAction);
            Assert.AreEqual(signal.OrderType, order.OrderType);
            Assert.AreEqual(signal.Limit, order.Price);
            Assert.AreEqual(signal.Stop, order.Stop);
        }
コード例 #17
0
        public void Handlers_TraderBaseInitializer_EmulateTradeFor_buy_Signal_with_price_test()
        {
            StrategyHeader strategyHeader = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 1);
            Signal         signal         = new Signal(strategyHeader, DateTime.Now, TradeAction.Buy, OrderType.Market, 150000, 0, 0);

            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Trade> >().Count());
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Position> >().Count());
            Assert.AreEqual(0, this.tradingData.GetAmount(strategyHeader));

            double price = 150010;

            EmulateTradeFor(signal, price);

            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Signal> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Order> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Trade> >().Count());
            Assert.AreEqual(1, this.tradingData.Get <IEnumerable <Position> >().Count());
            Assert.AreEqual(1, this.tradingData.GetAmount(strategyHeader));

            Trade trade = this.tradingData.Get <IEnumerable <Trade> >().Last();

            Assert.AreEqual(price, trade.Price);
        }
コード例 #18
0
        public void Setup()
        {
            this.tradingData = new TradingDataContext();

            this.strategyHeader = new StrategyHeader(1, "Description", "BP12345-RF-01", "RTS-3.14_FT", 10);
            this.tradingData.Get <ICollection <StrategyHeader> >().Add(this.strategyHeader);
        }
コード例 #19
0
        public void Handlers_UpdatePositionOnTrade_ignore_single_duplicate_trade()
        {
            StrategyHeader strategyHeader = new StrategyHeader(1, "Strategy", "BP12345-RF-01", "RTS-9.13_FT", 8);

            this.tradingData.Get <ICollection <StrategyHeader> >().Add(strategyHeader);

            Signal signal = new Signal(strategyHeader, BrokerDateTime.Make(DateTime.Now), TradeAction.Buy, OrderType.Market, 131000, 0, 0);

            this.tradingData.Get <ICollection <Signal> >().Add(signal);

            Order order = new Order(signal);

            this.tradingData.Get <ICollection <Order> >().Add(order);

            Assert.AreEqual(0, this.tradingData.GetAmount(strategyHeader));

            Trade trade = new Trade(order, order.Portfolio, order.Symbol, 131010, order.Amount, BrokerDateTime.Make(DateTime.Now));

            this.tradingData.Get <ObservableHashSet <Trade> >().Add(trade);

            Assert.AreEqual(8, this.tradingData.GetAmount(strategyHeader));

            Trade duplicate = new Trade(order, order.Portfolio, order.Symbol, 131010, order.Amount, BrokerDateTime.Make(DateTime.Now));

            this.tradingData.Get <ObservableHashSet <Trade> >().Add(duplicate);

            Assert.AreEqual(8, this.tradingData.GetAmount(strategyHeader));
        }
コード例 #20
0
ファイル: BuyOnTick.cs プロジェクト: w1r2p1/TRx
 public BuyOnTick(StrategyHeader strategyHeader, IDataContext tradingData, ObservableQueue <Signal> signalQueue, ILogger logger)
     : base(tradingData.Get <ObservableCollection <Tick> >())
 {
     this.strategyHeader = strategyHeader;
     this.tradingData    = tradingData;
     this.signalQueue    = signalQueue;
     this.logger         = logger;
 }
コード例 #21
0
ファイル: DealListTests.cs プロジェクト: w1r2p1/TRx
        public void Setup()
        {
            symbol = "RTS-12.13_FT";
            StrategyHeader sh = new StrategyHeader(1, "1", "BP12345-RF-01", symbol, 1);

            //dealList = new DealList(symbol);
            dealList = new DealList(sh);
        }
コード例 #22
0
 public StrategyStopLossByPointsOnTick(StrategyHeader strategyHeader,
                                       IDataContext tradingData,
                                       ObservableQueue <Signal> signalQueue,
                                       ILogger logger,
                                       bool measureFromSignalPrice = false)
     : base(strategyHeader, tradingData, signalQueue, logger, measureFromSignalPrice)
 {
 }
コード例 #23
0
 public MarkOrderAsOutdatedOnTick(StrategyHeader strategyHeader, int outdateSeconds, IDataContext tradingData, ILogger logger)
     : base(tradingData.Get <ObservableCollection <Tick> >())
 {
     this.strategyHeader = strategyHeader;
     this.outdateSeconds = outdateSeconds;
     this.tradingData    = tradingData;
     this.logger         = logger;
 }
コード例 #24
0
 public PlaceStrategyTakeProfitByPointsOnTrade(StrategyHeader strategyHeader,
                                               IDataContext tradingData,
                                               ObservableQueue <Signal> signalQueue,
                                               ILogger logger,
                                               bool measureFromSignalPrice = false)
     : base(strategyHeader, tradingData, signalQueue, logger, measureFromSignalPrice)
 {
 }
コード例 #25
0
ファイル: SourcePriceOnBar.cs プロジェクト: w1r2p1/TRx
        //public Bar bar { get; private set; }

        public SourcePriceOnBar(StrategyHeader strategyHeader, IDataContext tradingData, ILogger logger)
        //: base(tradingData.Get<ObservableCollection<Bar>>())
        {
            this.strategyHeader = strategyHeader;
            this.tradingData    = tradingData;
            //this.signalQueue = signalQueue;
            this.logger = logger;
        }
コード例 #26
0
 public void Handlers_Setup()
 {
     this.tradingData    = new TradingDataContext();
     this.strategyHeader = new StrategyHeader(1, "Sample strategyHeader", "ST12345-RF-01", "RTS-9.14", 10);
     this.tradingData.Get <ICollection <StrategyHeader> >().Add(this.strategyHeader);
     this.handler =
         new UpdateOrderAmountOnTrade(this.tradingData, new NullLogger());
 }
コード例 #27
0
        public void Setup()
        {
            this.strategy1 = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 1);
            this.strategy2 = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 2);

            StopPointsSettings sps1 = new StopPointsSettings(this.strategy1, 100, false);

            this.tradingData.Get <ICollection <StopPointsSettings> >().Add(sps1);
        }
コード例 #28
0
        public void Setup()
        {
            this.strategy1 = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 1);
            this.strategy2 = this.tradingData.Get <IEnumerable <StrategyHeader> >().Single(s => s.Id == 2);

            this.signalQueue.Enqueue(new Signal(this.strategy2, DateTime.Now, TradeAction.Buy, OrderType.Market, 32000, 0, 0));
            this.signalQueue.Enqueue(new Signal(this.strategy2, DateTime.Now, TradeAction.Buy, OrderType.Limit, 32000, 0, 32000));
            this.signalQueue.Enqueue(new Signal(this.strategy2, DateTime.Now, TradeAction.Buy, OrderType.Stop, 32000, 32000, 0));
        }
コード例 #29
0
 private void AddStrategies()
 {
     this.st1 = new StrategyHeader(1, "Strategy 1", "BP12345-RF-01", "RTS-9.13_FT", 10);
     this.st2 = new StrategyHeader(2, "Strategy 2", "BP12345-RF-01", "Si-9.13_FT", 10);
     this.st3 = new StrategyHeader(3, "Strategy 3", "BP12345-RF-01", "RTS-9.13_FT", 10);
     this.tradingData.Get <ICollection <StrategyHeader> >().Add(st1);
     this.tradingData.Get <ICollection <StrategyHeader> >().Add(st2);
     this.tradingData.Get <ICollection <StrategyHeader> >().Add(st3);
 }