private async Task <OrderList> GetOrdersSummaryAsync(Customers customer) { OrderList orderList = new OrderList(); String requestTemplate = Application.Current.Resources["GetOrders"] as String; String requesturl = String.Format(requestTemplate, BaseURLHelper.BaseURL, customer.CustomerID); string response = null; using (HttpClient client = new HttpClient()) { try { response = await HttpHelper.GetAsync(client, requesturl); OrderList newOrders = JsonConvert.DeserializeObject <OrderList>(response); orderList.AddRange(newOrders.Take <Orders>(20)); String nextBatch = (string)JArray.Parse(response).Last["@metadata"]["next_batch"]; if (requesturl != null) { // requesturl = requesturl + "&auth=" + apiKey; } Debug.WriteLine("Just a break point."); } catch (Exception) { Debug.WriteLine("Just a break point."); requesturl = null; } } //orderList.RemoveAll(o => o.CustomerID != customer.CustomerID); return(orderList); }
//IOrder AdjustRisk(IPosition p) //{ // if (p == null) return null; // if (p.IsProfit && ((p.MaxPrice - p.CurrentPrice) / p.MaxPrice > StopProfitPercent)) // { // var o = CurrentPortfolio.GenerateOrder(p.InstrumentTicker, p.CurrentPrice, (int)p.Shares, OrderType.Sell); // return o; // } // if (p.IsLoss && (p.Cost - p.CurrentPrice) / p.Cost > StopLossPercent) // { // var o = CurrentPortfolio.GenerateOrder(p.InstrumentTicker, p.CurrentPrice, (int)p.Shares, OrderType.Sell); // return o; // } // return null; //} //public override void ProcessPortfolio() //{ // base.ProcessPortfolio(); // //CurrentPortfolio.PositionList.ForEach(v => // //{ // // var o = AdjustRisk(v); // // if (o != null && o.Ticker != null) // // OrderList.Add(o); // //}); //} public override void ProcessSignal(List <ISignal> signalList) { TradeAlgorithmList.ForEach(t => { var ol = t.ProcessSignal(signalList, CurrentPortfolio); if (ol != null && ol.Count > 0) { OrderList.AddRange(ol); } }); }
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); } }