コード例 #1
0
 public void GetLastOrder()
 {
     // Last order
     Assert.IsNull(_emptyRecord.LastOrder);
     Assert.AreEqual(Order.BuyAt(7), _openedRecord.LastOrder);
     Assert.AreEqual(Order.SellAt(8), _closedRecord.LastOrder);
     // Last BUY order
     Assert.IsNull(_emptyRecord.GetLastOrder(OrderType.Buy));
     Assert.AreEqual(Order.BuyAt(7), _openedRecord.GetLastOrder(OrderType.Buy));
     Assert.AreEqual(Order.BuyAt(7), _closedRecord.GetLastOrder(OrderType.Buy));
     // Last SELL order
     Assert.IsNull(_emptyRecord.GetLastOrder(OrderType.Sell));
     Assert.AreEqual(Order.SellAt(3), _openedRecord.GetLastOrder(OrderType.Sell));
     Assert.AreEqual(Order.SellAt(8), _closedRecord.GetLastOrder(OrderType.Sell));
 }
コード例 #2
0
        public void Operate()
        {
            var record = new TradingRecord();

            record.Operate(1);
            Assert.IsTrue(record.CurrentTrade.Opened);
            Assert.AreEqual(0, record.TradeCount);
            Assert.IsNull(record.LastTrade);
            Assert.AreEqual(Order.BuyAt(1), record.LastOrder);
            Assert.AreEqual(Order.BuyAt(1), record.GetLastOrder(OrderType.Buy));
            Assert.IsNull(record.GetLastOrder(OrderType.Sell));
            Assert.AreEqual(Order.BuyAt(1), record.LastEntry);
            Assert.IsNull(record.LastExit);

            record.Operate(3);
            Assert.IsTrue(record.CurrentTrade.New);
            Assert.AreEqual(1, record.TradeCount);
            Assert.AreEqual(new Trade(Order.BuyAt(1), Order.SellAt(3)), record.LastTrade);
            Assert.AreEqual(Order.SellAt(3), record.LastOrder);
            Assert.AreEqual(Order.BuyAt(1), record.GetLastOrder(OrderType.Buy));
            Assert.AreEqual(Order.SellAt(3), record.GetLastOrder(OrderType.Sell));
            Assert.AreEqual(Order.BuyAt(1), record.LastEntry);
            Assert.AreEqual(Order.SellAt(3), record.LastExit);

            record.Operate(5);
            Assert.IsTrue(record.CurrentTrade.Opened);
            Assert.AreEqual(1, record.TradeCount);
            Assert.AreEqual(new Trade(Order.BuyAt(1), Order.SellAt(3)), record.LastTrade);
            Assert.AreEqual(Order.BuyAt(5), record.LastOrder);
            Assert.AreEqual(Order.BuyAt(5), record.GetLastOrder(OrderType.Buy));
            Assert.AreEqual(Order.SellAt(3), record.GetLastOrder(OrderType.Sell));
            Assert.AreEqual(Order.BuyAt(5), record.LastEntry);
            Assert.AreEqual(Order.SellAt(3), record.LastExit);
        }
コード例 #3
0
        public override bool IsSatisfied(int index, TradingRecord tradingRecord)
        {
            var satisfied = false;
            // No trading history, no need to wait
            var lastOrder = tradingRecord?.GetLastOrder(_orderType);

            if (lastOrder != null)
            {
                var currentNumberOfTicks = index - lastOrder.Index;
                satisfied = currentNumberOfTicks >= _numberOfTicks;
            }
            TraceIsSatisfied(index, satisfied);
            return(satisfied);
        }