Пример #1
0
        public void MatchedAndUnmatchedTransactions()
        {
            string path     = @"C:\Users\Nick\Documents\Visual Studio 2013\Projects\LeanITrend\Engine\bin\Debug\";
            string pathname = path + "transactions.csv";
            // This part of the test is just to look at the JsonConvert
            //string txt;
            //using (StreamReader sr = new StreamReader(pathname))
            //{
            //    txt = sr.ReadToEnd();
            //    sr.Close();
            //}
            //int index = txt.IndexOf("\r\n", System.StringComparison.Ordinal);
            //string titlesremoved = txt.Substring(index + 2);

            int counter = 0;
            List <OrderTransaction> list = new List <OrderTransaction>();

            OrderTransactionProcessor processor = new OrderTransactionProcessor();

            using (StreamReader sr = new StreamReader(pathname))
            {
                string line = sr.ReadLine();    // read the header but do not count it.

                while (!sr.EndOfStream)
                {
                    line = sr.ReadLine();
                    if (line != null && line.Contains("Symbol"))
                    {
                        continue;
                    }
                    Assert.IsNotNull(line);
                    counter++;
                    OrderTransaction t = new OrderTransaction();
                    CsvSerializer.Deserialize(",", line, ref t, false);
                    list.Add(t);
                    processor.ProcessTransaction(t);
                }
                sr.Close();
            }
            var csv = CsvSerializer.Serialize(",", processor.Trades, true);

            using (StreamWriter sw = new StreamWriter(path + "Trades.csv"))
            {
                foreach (var s in csv)
                {
                    sw.WriteLine(s);
                }
                sw.Flush();
                sw.Close();
            }
            var x = JsonConvert.SerializeObject(list);

            Assert.IsTrue(counter == list.Count);
            Assert.IsTrue(processor.TotalProfit == 52.75m);
            Assert.IsTrue(processor.TotalCommission == -26m);
        }
Пример #2
0
        public void CanOpenPosition()
        {
            OrderTransaction trans = new OrderTransaction();

            trans.Symbol    = "AAPL";
            trans.Direction = OrderDirection.Buy;
            OrderTransactionProcessor processor    = new OrderTransactionProcessor();
            IPositionInventory        openPosition = processor.OpenPosition(trans, PositionInventoryMethod.Fifo);

            processor.OpenPositions.Add(openPosition);
            Assert.IsTrue(processor.OpenPositions.Count > 0);
        }
Пример #3
0
 public void Setup()
 {
     p = new OrderTransactionProcessor();
 }