public void Update()
        {
            InstrumentList instruments = new InstrumentList();

            instruments.Load();
            Instrument instrument          = instruments.FirstOrDefault(ct => ct.Description == "SLTEST");
            Instrument retrievedInstrument = new Instrument();

            if (instrument != null)
            {
                retrievedInstrument.Id = instrument.Id;

                instrument.Description = "SLTEST1";

                //Act
                HttpClient client = InitializeClient();
                //Serialize a question object that we're trying to insert
                string serializedInstrument = JsonConvert.SerializeObject(instrument);
                var    content = new StringContent(serializedInstrument);
                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                HttpResponseMessage response = client.PutAsync("Instrument/" + instrument.Id, content).Result;

                retrievedInstrument.LoadById();
            }
            //Assert
            Assert.AreEqual(instrument.Description, retrievedInstrument.Description);
        }
        public void UpdateTest()
        {
            //Load up Guids
            PerformerList performers = new PerformerList();
            Performer     performer  = new Performer();

            performers.Load();
            performer = performers.FirstOrDefault(p => p.FirstName == "Hunter");

            GroupList groups = new GroupList();
            Group     group  = new Group();

            groups.Load();
            group = groups.FirstOrDefault(c => c.Name == "Jazz Ensemble");

            InstrumentList instruments = new InstrumentList();
            Instrument     instrument  = new Instrument();

            instruments.Load();
            instrument = instruments.FirstOrDefault(c => c.Description == "Euphonium");

            GroupMember     groupMember  = new GroupMember();
            GroupMemberList groupMembers = new GroupMemberList();

            groupMembers.Load();
            groupMember           = groupMembers.FirstOrDefault(p => p.GroupId == group.Id && p.PerformerId == performer.Id);
            groupMember.StartDate = Convert.ToDateTime("04/24/3000");
            groupMember.EndDate   = Convert.ToDateTime("04/25/3000");

            groupMember.Instrument = instrument.Id;
            int results = groupMember.Update();

            Assert.IsTrue(results == 1);
        }
Exemple #3
0
        void RefreshResult()
        {
            ResultList.Clear();
            foreach (var condition in ConditionList)
            {
                var l = condition.GetResult(null, AnalyseEndTime);
                foreach (var r in l)
                {
                    var inst = InstrumentList.FirstOrDefault(v => v.Ticker == r.Ticker);
                    if (inst != null)
                    {
                        if (!ResultList.Any(v => v.Ticker == inst.Ticker))
                        {
                            ResultList.Add(inst);
                        }
                    }
                }
            }

            var rl = new List <IInstrument>();

            foreach (var preicate in PredicateList)
            {
                rl.Clear();
                var l = preicate.GetResult(null, AnalyseEndTime);
                foreach (var r in l)
                {
                    var inst = InstrumentList.FirstOrDefault(v => v.Ticker == r.Ticker);
                    rl.Add(inst);
                }
                ResultList.RemoveAll(v => !rl.Any(r => r.Ticker == v.Ticker));
            }
        }
        public void DeleteTest()
        {
            Instrument     instrument  = new Instrument();
            InstrumentList instruments = new InstrumentList();

            instruments.Load();
            instrument = instruments.FirstOrDefault(i => i.Description == "Update");

            int results = instrument.Delete();

            Assert.IsTrue(results == 1);
        }
        public void LoadById()
        {
            Instrument     instrument  = new Instrument();
            InstrumentList instruments = new InstrumentList();

            instruments.Load();
            instrument = instruments.FirstOrDefault(i => i.Description == "Update");

            Instrument newInstrument = new Instrument {
                Id = instrument.Id
            };

            newInstrument.LoadById();

            Assert.AreEqual(instrument.Description, newInstrument.Description);
        }
Exemple #6
0
        public override void Refresh()
        {
            CheckRunningStatus();
            CommonProc.SynchroniseList <IMarketData>(TargetProject.MarketDataList, MarketDataList);
            //CommonProc.SynchroniseList<IIndicatorValue>(TargetProject.IndicatorDataList, IndicatorDataList);
            CommonProc.SynchroniseList <IOrder>(TargetProject.OrderList, OrderList);
            CommonProc.SynchroniseList <TimeValueObject>(TargetProject.CurrentValueList, CurrentValueList);
            CommonProc.SynchroniseList <TimeValueObject>(TargetProject.StandardValueList, StandardValueList);
            if (CurrentInstrument == null && InstrumentList.Count > 0)
            {
                CurrentInstrument = InstrumentList.FirstOrDefault();
            }
            if (CurrentInstrument != null)
            {
                var l = MarketDataList.Where(v => v.InstrumentTicker == CurrentInstrument.Ticker);
                CommonProc.SynchroniseList <IMarketData>(l, CurrentInstrumentMarketDataList);
                var ol = OrderList.Where(v => v.Ticker == CurrentInstrument.Ticker);
                CommonProc.SynchroniseList <IOrder>(ol, CurrentInstrumentOrderList);
            }

            TestCurrentTime = TargetProject.TestCurrentTime;
            OnPropertyChanged("CurrentValue");
            OnPropertyChanged("Pnl");
            OnPropertyChanged("StatusPnl");
            OnPropertyChanged("Efficiency");
            OnPropertyChanged("MaxLost");
            refreshChartAxis();
            OnPropertyChanged("CanStart");
            OnPropertyChanged("CanPause");
            OnPropertyChanged("CanStop");
            OnPropertyChanged("FinishPercent");
            if (TargetSummaryVM != null)
            {
                TargetSummaryVM.Refresh();
            }
            OnPropertyChanged("CanStart");
            OnPropertyChanged("CanPause");
            OnPropertyChanged("CanStop");
            OnPropertyChanged("TestCurrentTimeInfo");
            base.Refresh();
        }
        public void Delete()
        {
            //Setup
            InstrumentList instruments = new InstrumentList();

            instruments.Load();
            int        originalCount = instruments.Count();
            Instrument instrument    = instruments.FirstOrDefault(ct => ct.Description == "SLTEST1");


            //Act
            if (instrument != null)
            {
                HttpClient          client   = InitializeClient();
                HttpResponseMessage response = client.DeleteAsync("Instrument/" + instrument.Id).Result;
            }

            //Assert
            instruments.Clear();
            instruments.Load();
            Assert.AreEqual(originalCount - 1, instruments.Count);
        }
        public void LoadById()
        {
            //Load up Guids
            PerformerList performers = new PerformerList();
            Performer     performer  = new Performer();

            performers.Load();
            performer = performers.FirstOrDefault(p => p.FirstName == "Hunter");

            GroupList groups = new GroupList();
            Group     group  = new Group();

            groups.Load();
            group = groups.FirstOrDefault(c => c.Name == "Jazz Ensemble");

            InstrumentList instruments = new InstrumentList();
            Instrument     instrument  = new Instrument();

            instruments.Load();
            instrument = instruments.FirstOrDefault(c => c.Description == "Euphonium");

            GroupMember     groupMember  = new GroupMember();
            GroupMemberList groupMembers = new GroupMemberList();

            groupMembers.Load();
            groupMember           = groupMembers.FirstOrDefault(p => p.GroupId == group.Id && p.PerformerId == performer.Id);
            groupMember.StartDate = Convert.ToDateTime("04/24/3000");
            groupMember.EndDate   = Convert.ToDateTime("04/25/3000");

            GroupMember newgroupmember = new GroupMember {
                Id = groupMember.Id
            };

            newgroupmember.LoadById();

            Assert.AreEqual(groupMember.Instrument, newgroupmember.Instrument);
        }
        public void GetOne()
        {
            //Setup
            Instrument     instrument          = new Instrument();
            Instrument     retrievedInstrument = new Instrument();
            InstrumentList instruments         = new InstrumentList();

            instruments.Load();
            instrument = instruments.FirstOrDefault(ct => ct.Description == "Saxophone");

            //Act
            if (instrument != null)
            {
                HttpClient          client   = InitializeClient();
                HttpResponseMessage response = client.GetAsync("Instrument/" + instrument.Id).Result;

                string result = response.Content.ReadAsStringAsync().Result;

                retrievedInstrument = JsonConvert.DeserializeObject <Instrument>(result);
            }

            //Assert
            Assert.IsTrue(instrument.Description == retrievedInstrument.Description && !string.IsNullOrEmpty(retrievedInstrument.Description));
        }
Exemple #10
0
        void TestStep(DateTime start, DateTime end)
        {
            TestStrategy.CurrentTime = end;
            AddInfo("test step, start:" + start.ToString() + ",end:" + end.ToString());
            var dl = CurrentDataSource.GetDataList(InstrumentList, start, end, Grade);

            AddInfo("got market data ,count is:" + dl.Count.ToString());
            if (dl == null || dl.Count == 0)
            {
                return;
            }
            TestStrategy.CurrentTime = dl.Max(d => d.Time);
            dl.ForEach(v =>
            {
                var inst = InstrumentList.FirstOrDefault(i => i.Ticker == v.InstrumentTicker);
                if (inst != null)
                {
                    AddInfo("update " + inst.Name + " price, value is:" + v.Close.ToString() + "(" + v.Time.ToString() + ")");
                    inst.CurrentPrice = v.Close;
                }
            });
            MarketDataList.AddRange(dl);
            AddInfo("portfolio process market data!");
            TargetPortfolio.ProcessMarketData(dl);
            AddInfo("standard portfolio process market data!");
            standardPortfolio.ProcessMarketData(dl);
            AddInfo("strategy process market data!");
            TestStrategy.ProcessMarketData(dl);

            if (analyseTime <= end)
            {
                AddInfo("prepare analyse, analyse time is:" + analyseTime.ToString());
                AnalyseStep();
                analyseTime = MarketData.GetNextTime(end, AnalyseGrade);
                var cl = new List <ISignal>();
                foreach (var condition in ConditionList)
                {
                    var rl = condition.GetResult();
                    if (rl != null && rl.Count > 0)
                    {
                        cl.AddRange(rl);
                    }
                }
                if (cl.Count > 0)
                {
                    AddInfo("got signal, count is " + cl.Count.ToString());
                    TestStrategy.ProcessSignal(cl);
                }
            }
            AddInfo("strategy process portfolio");
            TestStrategy.ProcessPortfolio();
            var ol = TestStrategy.GetOrderList();

            if (ol.Count > 0)
            {
                AddInfo("strategy generate order, count is :" + ol.Count.ToString());
                List <IOrder> col = new List <IOrder>();
                foreach (var o in ol)
                {
                    if (o != null && RiskPolicy.PredictOrder(o, TargetPortfolio))
                    {
                        col.Add(o);
                    }
                }
                OrderList.AddRange(col);
                AddInfo("trade gate process order");
                CurrentTradeGate.ProcessorOrder(col);
                AddInfo("portfolio info before process order is" + GetPortfolioMemo(TargetPortfolio));
                TargetPortfolio.ProcessOrderList(col);
                AddInfo("portfolio info after process order is" + GetPortfolioMemo(TargetPortfolio));
            }

            if (!IsUnlimited)//adjust risk
            {
                AddInfo("adjust risk");
                ol = RiskPolicy.AdjustRisk(TargetPortfolio);
                if (ol.Count > 0)
                {
                    AddInfo("risk order generate, count is:" + ol.Count.ToString());
                    OrderList.AddRange(ol);
                    List <IOrder> col = ol.Where(v => v != null).ToList();
                    CurrentTradeGate.ProcessorOrder(col);
                    TargetPortfolio.ProcessOrderList(col);
                }
            }
            CurrentValueList.Add(new TimeValueObject()
            {
                Time = dl.Max(v => v.Time), Value = CurrentValue, Memo = GetPortfolioMemo(TargetPortfolio)
            });
            StandardValueList.Add(new TimeValueObject()
            {
                Time = dl.Max(v => v.Time), Value = StandardValue, Memo = GetPortfolioMemo(standardPortfolio)
            });
            if (_MaxLost.Number > Pnl.Number)
            {
                _MaxLost.Number = Pnl.Number;
            }
            if (TestStepDelayMS > 0)
            {
                Thread.Sleep(TestStepDelayMS);
            }
        }