示例#1
0
        protected void placeOrderCallback(MarketSimulation.ReturnCode errorCode, MarketSimulation.ISystemLimitOrder lo, int quantity)
        {
            MarketSimulationMaof.Option option = marketSimulationMaof.GetOption(lo.SecurityId);
            string optionName = option.GetName();

            if (errorCode == MarketSimulation.ReturnCode.Fill)
            {
                System.Console.WriteLine("Tick {6} Order {0} {5} id {1} quantity {3} price {4} got fill at price {2}",
                                         optionName, lo.Id, lo.FillPrice, quantity, lo.Price, lo.SecurityId, lo.FillTick);
            }
            else
            {
                System.Console.WriteLine("Tick {5} Order {0} id {1} price {2} quantity {3} failed on {4}",
                                         optionName, lo.Id, lo.Price, quantity, errorCode.ToString(), lo.FillTick);
            }
        }
示例#2
0
        protected void debugMarketSimulationMaofPlaceOrderCallback(IWrite iWrite, string cmdName, object[] cmdArguments)
        {
            if (marketSimulationMaof == default(MarketSimulationMaof))             // check if there active simulation to get data from
            {
                iWrite.WriteLine("No active market simulations.");
                return;
            }

            int  id;
            bool res = FindSecurity(cmdName, out id);

            if (!res)
            {
                iWrite.WriteLine("Unknown security in the command " + cmdName);
                return;
            }

            // i got security ID
            bool buyOrder  = (cmdArguments[1].ToString().ToUpper().CompareTo("BUY") == 0);
            bool sellOrder = (cmdArguments[1].ToString().ToUpper().CompareTo("SELL") == 0);

            if (!buyOrder && !sellOrder)
            {
                iWrite.WriteLine("Use words buy or sell to specify the order type");
                return;
            }
            if (buyOrder && sellOrder)
            {
                iWrite.WriteLine("Internal error: both buy and sell in " + cmdArguments[1]);
                return;
            }


            // are there three and only three numbers in the command line ?
            const string patternNumbers = ".+[0-9]+.+[0-9]+ +[0-9]+";

            System.Text.RegularExpressions.Regex           regexNumbers = new System.Text.RegularExpressions.Regex(patternNumbers);
            System.Text.RegularExpressions.MatchCollection matches      = regexNumbers.Matches(cmdName);
            if (matches.Count != 1)
            {
                iWrite.WriteLine("Three and only three numbers - security ID, limit price and quantiy are allowed. I got '" + cmdName + "'");
                return;
            }

            // last arguments are price and quantity
            string limitPriceStr = cmdArguments[cmdArguments.Length - 2].ToString();
            string quantintyStr  = cmdArguments[cmdArguments.Length - 1].ToString();
            int    limitPrice    = Int32.Parse(limitPriceStr);
            int    quantity      = Int32.Parse(quantintyStr);

            if (limitPrice == 0)
            {
                iWrite.WriteLine("Failed to parse limit price " + limitPriceStr);
                return;
            }
            if (quantity == 0)
            {
                iWrite.WriteLine("Failed to parse quantinty " + quantintyStr);
                return;
            }

            TransactionType transaction;

            if (buyOrder)
            {
                transaction = TransactionType.BUY;
            }
            else
            {
                transaction = TransactionType.SELL;
            }
            MarketSimulation.ReturnCode        errorCode;
            MarketSimulation.ISystemLimitOrder order = marketSimulationMaof.CreateOrder(id, limitPrice, quantity, transaction, placeOrderCallback);
            res = marketSimulationMaof.PlaceOrder(order, out errorCode);
            if (!res)
            {
                iWrite.WriteLine("Failed to place order error=" + errorCode);
            }
        }