Esempio n. 1
0
        public void make_CookieToOrderNoAssociation_for_SystemCancel_update_test()
        {
            this.rawData.GetData <UpdateOrder>().Add(this.filledStopOrder);
            Assert.AreEqual(0, this.rawData.GetData <CookieToOrderNoAssociation>().Count());

            this.filledMarketOrder =
                new UpdateOrder("BP12354-RF-01",
                                "RTS-9.14_FT",
                                StOrder_State.StOrder_State_SystemCancel,
                                StOrder_Action.StOrder_Action_Buy,
                                StOrder_Type.StOrder_Type_Market,
                                StOrder_Validity.StOrder_Validity_Day,
                                150,
                                10,
                                0,
                                8,
                                DateTime.Now,
                                this.stopOrderNo,
                                this.marketOrderNo,
                                0,
                                0);

            this.rawData.GetData <UpdateOrder>().Add(this.filledMarketOrder);
            Assert.AreEqual(1, this.rawData.GetData <CookieToOrderNoAssociation>().Count());

            CookieToOrderNoAssociation association = this.rawData.GetData <CookieToOrderNoAssociation>().Last();

            Assert.AreEqual(this.cookie, association.Cookie);
            Assert.AreEqual(this.marketOrderNo, association.OrderNo);
        }
Esempio n. 2
0
        public void make_CookieToOrderNoAssociation_for_expired_update_test()
        {
            this.partialUpdate =
                new UpdateOrder("BP12354-RF-01",
                                "RTS-9.14_FT",
                                StOrder_State.StOrder_State_Expired,
                                StOrder_Action.StOrder_Action_Buy,
                                StOrder_Type.StOrder_Type_Market,
                                StOrder_Validity.StOrder_Validity_Day,
                                150,
                                10,
                                0,
                                8,
                                DateTime.Now,
                                "0",
                                this.orderNo,
                                0,
                                this.cookie);

            this.rawData.GetData <UpdateOrder>().Add(this.partialUpdate);
            Assert.AreEqual(1, this.rawData.GetData <CookieToOrderNoAssociation>().Count());

            CookieToOrderNoAssociation expectedTradeInfo = this.rawData.GetData <CookieToOrderNoAssociation>().Last();

            Assert.AreEqual(this.cookie, expectedTradeInfo.Cookie);
            Assert.AreEqual(this.orderNo, expectedTradeInfo.OrderNo);
        }
        public override void Update(UpdateOrder item)
        {
            if (!IsCancelUpdate(item))
            {
                return;
            }

            CookieToOrderNoAssociation association = FindCookieToOrderNoAssociation(item.OrderNo);

            if (association == null)
            {
                association = FindCookieToOrderNoAssociation(item.OrderId);
            }

            if (association == null)
            {
                return;
            }

            Order order = FindOrder(association.Cookie);

            if (order == null)
            {
                return;
            }

            order.Cancel(item.Datetime, item.State.ToString());

            this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, заявка отменена {2}",
                                          BrokerDateTime.Make(DateTime.Now),
                                          this.GetType().Name,
                                          order.ToString()));
        }
Esempio n. 4
0
        public void CookieToOrderNoAssociation_constructor_test()
        {
            int    cookie  = 150;
            string orderNo = "12345678";
            CookieToOrderNoAssociation item = new CookieToOrderNoAssociation(cookie, orderNo);

            Assert.AreEqual(cookie, item.Cookie);
            Assert.AreEqual(orderNo, item.OrderNo);
        }
Esempio n. 5
0
        public void make_CookieToOrderNoAssociation_for_partial_update_test()
        {
            this.rawData.GetData <UpdateOrder>().Add(this.partialUpdate);
            Assert.AreEqual(1, this.rawData.GetData <CookieToOrderNoAssociation>().Count());

            CookieToOrderNoAssociation expectedTradeInfo = this.rawData.GetData <CookieToOrderNoAssociation>().Last();

            Assert.AreEqual(this.cookie, expectedTradeInfo.Cookie);
            Assert.AreEqual(this.orderNo, expectedTradeInfo.OrderNo);
        }
Esempio n. 6
0
        public void CookieToOrderNoAssociation_ToString_test()
        {
            int    cookie  = 150;
            string orderNo = "12345678";
            CookieToOrderNoAssociation item = new CookieToOrderNoAssociation(cookie, orderNo);

            string expected = String.Format("{0}, {1}", cookie, orderNo);

            Assert.AreEqual(expected, item.ToString());
        }
Esempio n. 7
0
        public void ignore_CookieToOrderNoAssociation_when_no_Order_exists_test()
        {
            this.cookieToOrderNoAssociation =
                new CookieToOrderNoAssociation(1, this.tradeInfo.OrderNo);

            this.rawData.GetData <PendingTradeInfo>().Add(this.pendingTradeInfo);
            this.rawData.GetData <CookieToOrderNoAssociation>().Add(this.cookieToOrderNoAssociation);
            Assert.AreEqual(1, this.rawData.GetData <CookieToOrderNoAssociation>().Count);
            Assert.AreEqual(1, this.rawData.GetData <PendingTradeInfo>().Count);
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Trade> >().Count());
        }
Esempio n. 8
0
        private void RegisterCookieToOrderNoAssociation(UpdateOrder item)
        {
            CookieToOrderNoAssociation association = new CookieToOrderNoAssociation(this.sourceUpdateOrder.Cookie, item.OrderNo);

            this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, {2}",
                                          BrokerDateTime.Make(DateTime.Now),
                                          this.GetType().Name,
                                          association.ToString()));

            this.dataContext.GetData <CookieToOrderNoAssociation>().Add(association);
        }
        private void RegisterTradeInfoPending(UpdateOrder item)
        {
            CookieToOrderNoAssociation expectedTradeInfo = new CookieToOrderNoAssociation(item.Cookie, item.OrderNo);

            this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, {2}",
                                          BrokerDateTime.Make(DateTime.Now),
                                          this.GetType().Name,
                                          expectedTradeInfo.ToString()));

            this.dataContext.GetData <CookieToOrderNoAssociation>().Add(expectedTradeInfo);
        }
Esempio n. 10
0
 private void UpdateCookieAndOrderNoAssociationFor(PendingTradeInfo item)
 {
     try {
         this.cookieAndOrderNoAssociation =
             this.dataContext.GetData <CookieToOrderNoAssociation>().Where(i => i.OrderNo == item.OrderNo).Last();
     }
     catch
     {
         this.cookieAndOrderNoAssociation = null;
     }
 }
Esempio n. 11
0
        public void make_CookieToOrderNoAssociation_for_Partial_update_test()
        {
            this.rawData.GetData <UpdateOrder>().Add(this.filledStopOrder);
            Assert.AreEqual(0, this.rawData.GetData <CookieToOrderNoAssociation>().Count());

            this.rawData.GetData <UpdateOrder>().Add(this.filledMarketOrder);
            Assert.AreEqual(1, this.rawData.GetData <CookieToOrderNoAssociation>().Count());

            CookieToOrderNoAssociation association = this.rawData.GetData <CookieToOrderNoAssociation>().Last();

            Assert.AreEqual(this.cookie, association.Cookie);
            Assert.AreEqual(this.marketOrderNo, association.OrderNo);
        }
Esempio n. 12
0
        public void make_Trade_when_multiple_PendingTradeInfo_exists_test()
        {
            this.tradeInfo =
                new TradeInfo("ST12345-RF-01",
                              "RTS-9.14_FT",
                              "12345",
                              this.order.Price,
                              -5,
                              BrokerDateTime.Make(DateTime.Now),
                              "54321");
            this.pendingTradeInfo =
                new PendingTradeInfo(this.tradeInfo);
            this.rawData.GetData <PendingTradeInfo>().Add(this.pendingTradeInfo);

            this.tradeInfo =
                new TradeInfo("ST12345-RF-01",
                              "RTS-9.14_FT",
                              "12345",
                              this.order.Price,
                              -5,
                              BrokerDateTime.Make(DateTime.Now),
                              "54325");
            this.pendingTradeInfo =
                new PendingTradeInfo(this.tradeInfo);
            this.rawData.GetData <PendingTradeInfo>().Add(this.pendingTradeInfo);

            this.cookieToOrderNoAssociation =
                new CookieToOrderNoAssociation(this.order.Id, this.tradeInfo.OrderNo);
            this.rawData.GetData <CookieToOrderNoAssociation>().Add(this.cookieToOrderNoAssociation);


            Assert.AreEqual(1, this.rawData.GetData <CookieToOrderNoAssociation>().Count);
            Assert.AreEqual(0, this.rawData.GetData <PendingTradeInfo>().Count);
            Assert.AreEqual(2, this.tradingData.Get <IEnumerable <Trade> >().Count());

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

            Assert.AreEqual(this.tradeInfo.Amount, trade.Amount);
            Assert.AreEqual(this.tradeInfo.DateTime, trade.DateTime);
            Assert.AreEqual(this.tradeInfo.Portfolio, trade.Portfolio);
            Assert.AreEqual(this.tradeInfo.Price, trade.Price);
            Assert.AreEqual(this.order.Id, trade.OrderId);
            Assert.AreEqual(this.order, trade.Order);
        }
Esempio n. 13
0
        public void Setup()
        {
            this.rawData     = new RawTradingDataContext();
            this.tradingData = new TradingDataContext();

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

            this.signal = new Signal(this.strategyHeader,
                                     BrokerDateTime.Make(DateTime.Now),
                                     TradeAction.Sell,
                                     OrderType.Market,
                                     125000,
                                     0,
                                     0);

            this.order = this.tradingData.AddSignalAndItsOrder(this.signal);

            this.tradeInfo =
                new TradeInfo("ST12345-RF-01",
                              "RTS-9.14_FT",
                              "12345",
                              this.order.Price,
                              -1,
                              BrokerDateTime.Make(DateTime.Now),
                              "54321");

            this.cookieToOrderNoAssociation =
                new CookieToOrderNoAssociation(this.order.Id, this.tradeInfo.OrderNo);

            this.pendingTradeInfo =
                new PendingTradeInfo(this.tradeInfo);

            this.handler =
                new MakeTradeOnCookieToOrderNoAssociation(this.rawData, this.tradingData, new NullLogger());

            Assert.AreEqual(0, this.rawData.GetData <CookieToOrderNoAssociation>().Count);
            Assert.AreEqual(0, this.rawData.GetData <PendingTradeInfo>().Count);
            Assert.AreEqual(0, this.tradingData.Get <IEnumerable <Trade> >().Count());
        }
Esempio n. 14
0
        public override void Update(PendingTradeInfo item)
        {
            UpdateCookieAndOrderNoAssociationFor(item);

            if (!HasCookieAndOrderNoAssociation())
            {
                return;
            }

            UpdateOrder();

            if (!HasOrder())
            {
                this.cookieAndOrderNoAssociation = null;
                return;
            }

            if (this.order.IsFilled)
            {
                this.order = null;
                return;
            }

            Trade trade = new Trade(this.order, item.Portfolio, item.Symbol, item.Price, item.Amount, item.DateTime);

            this.logger.Log(String.Format("{0:dd/MM/yyyy H:mm:ss.fff}, {1}, исполнена сделка {2}",
                                          BrokerDateTime.Make(DateTime.Now),
                                          this.GetType().Name,
                                          trade.ToString()));

            this.dataContext.GetData <PendingTradeInfo>().Remove(item);
            this.tradingData.Get <ObservableHashSet <Trade> >().Add(trade);

            this.cookieAndOrderNoAssociation = null;
            this.order = null;
        }