Ejemplo n.º 1
0
        public void TestTrade_Minute()
        {
            string            code               = "RB1710";
            int               startDate          = 20170601;
            int               endDate            = 20170605;
            IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, false);
            IAccount          account            = DataCenter.Default.AccountManager.CreateAccount(100000, historyDataForward);

            account.OnReturnOrder += Account_OnReturnOrder;
            account.OnReturnTrade += Account_OnReturnTrade;
            account.Open(code, 3099, market.OrderSide.Buy, 10);
            account.Open(code, 3095, market.OrderSide.Buy, 10);
            int index = 0;

            while (index < 200)
            {
                historyDataForward.Forward();
                index++;
                if (isOpen && historyDataForward.Price >= 3102)
                {
                    account.Close(code, 3102, market.OrderSide.Sell, 10);
                    account.Close(code, 3105, market.OrderSide.Sell, 10);
                }
                //Console.WriteLine(historyDataForward.GetTickData());
            }
            Console.WriteLine(account);
            Assert.AreEqual(101180, account.Money);
        }
Ejemplo n.º 2
0
        public void TestAccountSave()
        {
            string            code               = "RB1710";
            int               startDate          = 20170601;
            int               endDate            = 20170605;
            IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, true);

            historyDataForward.Forward();
            IAccount account = DataCenter.Default.AccountManager.CreateAccount(100000, historyDataForward);

            account.AccountSetting.TradeType = AccountTradeType.MARKETPRICE;
            account.OnReturnOrder           += Account_OnReturnOrder;
            account.OnReturnTrade           += Account_OnReturnTrade;
            account.Open(code, 3099, market.OrderSide.Buy, 10);
            account.Open(code, 3095, market.OrderSide.Buy, 10);
            int index = 0;

            while (index < 2000)
            {
                historyDataForward.Forward();
                index++;
                if (isOpen && historyDataForward.GetTickData().SellPrice >= 3102)
                {
                    account.Close(code, 3102, market.OrderSide.Sell, 10);
                    account.Close(code, 3105, market.OrderSide.Sell, 10);
                }
                //Console.WriteLine(historyDataForward.GetTickData());
            }

            account.Open(code, 3105, market.OrderSide.Buy, 10);
            account.Open(code, 3025, market.OrderSide.Buy, 10);

            for (int i = 0; i < 100; i++)
            {
                historyDataForward.Forward();
            }

            XmlElement root = GetXmlRoot();

            account.Save(root);

            Account account2 = (Account)DataCenter.Default.AccountManager.CreateAccount(root);

            //Console.WriteLine(account);
            //Console.WriteLine(account2);
            Assert.AreEqual(XmlUtils.ToString(account), XmlUtils.ToString(account2));

            IDataForward_Code historyDataForward2 = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, true);

            historyDataForward2.NavigateTo(account2.Time);
            account2.BindRealTimeReader(historyDataForward2);
            //IDataForward_Code historyDataForward2 = account2.DataForward_Code;
            for (int i = 0; i < 100; i++)
            {
                historyDataForward2.Forward();
            }
            Console.WriteLine(account2);
        }
Ejemplo n.º 3
0
        public void TestTrade_Immediately2()
        {
            string   code    = "RB1710";
            IAccount account = DataCenter.Default.AccountManager.CreateAccount(100000);

            account.Open(code, 3099, market.OrderSide.Buy, 10);
            account.Close(code, 3102, market.OrderSide.Sell, 10);
            account.Open(code, 3095, market.OrderSide.Buy, 10);
            account.Close(code, 3102, market.OrderSide.Sell, 10);
            Console.WriteLine(account);
            Assert.AreEqual(100880, account.Money);
        }
Ejemplo n.º 4
0
        public void TestTrade_Immediately()
        {
            string   code    = "RB1710";
            IAccount account = DataCenter.Default.AccountManager.CreateAccount(100000);

            account.AccountSetting.TradeType = AccountTradeType.IMMEDIATELY;
            account.Open(code, 3099, market.OrderSide.Buy, 10);
            account.Open(code, 3095, market.OrderSide.Buy, 10);
            account.Close(code, 3102, market.OrderSide.Sell, 10);
            account.Close(code, 3102, market.OrderSide.Sell, 10);

            Assert.AreEqual(100880, account.Money);
        }
Ejemplo n.º 5
0
        public void TestTrade_SlipPrice()
        {
            string   code    = "RB1710";
            IAccount account = DataCenter.Default.AccountManager.CreateAccount(100000);

            account.AccountSetting.TradeType = AccountTradeType.IMMEDIATELY;
            account.AccountSetting.SlipPrice = 1;
            account.Open(code, 3099, market.OrderSide.Buy, 10);
            account.Open(code, 3095, market.OrderSide.Buy, 10);
            account.Close(code, 3102, market.OrderSide.Sell, 10);
            account.Close(code, 3102, market.OrderSide.Sell, 10);

            //Console.WriteLine(account);
            //Console.WriteLine(account.Money);
            //Assert.AreEqual(100880, account.Money);
            //Assert.AreEqual(100510, account.Money);
            Assert.AreEqual(100680, account.Money);
        }
Ejemplo n.º 6
0
        public void Calling_Withdraw_OnClosedAccount_ShouldNotChangeBalance()
        {
            IAccount closedAccount = CreatetNewAccount();

            closedAccount.Close();

            closedAccount.Deposit(5);

            Assert.Equal(0, closedAccount.Balance);
        }