示例#1
0
        public override void Notify(Guid tradeGuid, OpenStatus status, double dealQty = 0, double dealPrice = 0, string weituobianhao = "", string pendWeituobianhao = "")
        {
            if (tps.ContainsKey(tradeGuid))
            {
                PTradePoints t = tps[tradeGuid];
                if (status == OpenStatus.Opened)
                {
                    decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                    t.EnterPoint.DealQty = (double)((decimal)dealQty + (decimal)t.EnterPoint.PartDealQty);
                    if (t.EnterPoint.OpenType == OpenType.KaiDuo)
                    {
                        DuoHands       += (Decimal)t.EnterPoint.DealQty;
                        FrozenDuoHands -= (Decimal)t.EnterPoint.DealQty;
                    }
                    else
                    {
                        KongHands       += (Decimal)t.EnterPoint.DealQty;
                        FrozenKongHands -= (Decimal)t.EnterPoint.DealQty;
                    }
                    if (currentTick.IsReal)
                    {
                        t.Status = OpenStatus.Opened;
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受开仓通知,成交数量:{1}", this.policyName, dealQty)));
                    }
                }
                else if (status == OpenStatus.Open)
                {
                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受开仓下单通知", this.policyName)));
                }
                else if (status == OpenStatus.Close)
                {
                    OpenPointWeiTuo opwt = new OpenPointWeiTuo();
                    opwt.Weituobianhao = weituobianhao;
                    opwt.OpenQty       = dealQty;
                    t.OutPoint.OpenPointWeiTuo.Add(opwt);
                    if (currentTick.IsReal)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受平仓下单通知", this.policyName)));
                    }
                }
                else if (status == OpenStatus.Closed)
                {
                    double RealTotalDeal = 0;
                    bool   find          = false;
                    for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                    {
                        if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                        {
                            OpenPointWeiTuo opwt        = t.OutPoint.OpenPointWeiTuo[j];
                            decimal         realDealQty = (decimal)dealQty + (decimal)opwt.PartDealQty - (decimal)opwt.DealQty;
                            t.OutPoint.OpenPointWeiTuo[j].DealQty = dealQty + opwt.PartDealQty;
                            find = true;
                        }
                        RealTotalDeal += t.OutPoint.OpenPointWeiTuo[j].DealQty;
                    }

                    if (t.EnterPoint.DealQty == RealTotalDeal)
                    {
                        if (t.EnterPoint.OpenType == OpenType.KaiDuo)
                        {
                            DuoHands -= (decimal)RealTotalDeal;
                        }
                        else
                        {
                            KongHands -= (decimal)RealTotalDeal;
                        }
                        t.Finished = true;
                        PTradePoints tptemp;
                        tps.TryRemove(tradeGuid, out tptemp);
                    }
                    if (currentTick.IsReal)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受平仓通知-{1}-有单子:{2}", this.policyName, weituobianhao, find.ToString())));
                    }
                }
                else if (status == OpenStatus.OpenPending)
                {
                    t.EnterPoint.PartDealQty = t.EnterPoint.DealQty;
                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接收入场追单通知", this.policyName)));
                }
                else if (status == OpenStatus.ClosePending)
                {
                    OpenPointWeiTuo opwt = new OpenPointWeiTuo();
                    opwt.Weituobianhao = pendWeituobianhao;
                    opwt.OpenQty       = dealQty;
                    t.OutPoint.OpenPointWeiTuo.Add(opwt);
                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接收出场追单通知", this.policyName)));
                }
                else if (status == OpenStatus.Failed)
                {
                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受失败通知", this.policyName)));
                }
                else if (status == OpenStatus.PartOpend)
                {
                    if (dealQty > (t.EnterPoint.DealQty - t.EnterPoint.PartDealQty))
                    {
                        decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                        t.EnterPoint.DealQty = dealQty + t.EnterPoint.PartDealQty;
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分入场成交通知,成交数量:{1}", this.policyName, dealQty)));
                    }
                }
                else if (status == OpenStatus.PartClosed)
                {
                    for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                    {
                        if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                        {
                            OpenPointWeiTuo opwt = t.OutPoint.OpenPointWeiTuo[j];
                            if (dealQty > (opwt.DealQty - opwt.PartDealQty))
                            {
                                RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分出场成交通知,成交数量:{1}", this.policyName, dealQty)));
                                decimal realDealQty = (decimal)dealQty + (decimal)opwt.PartDealQty - (decimal)opwt.DealQty;
                                t.OutPoint.OpenPointWeiTuo[j].DealQty = dealQty + opwt.PartDealQty;
                            }
                            break;
                        }
                    }
                }
                else if (status == OpenStatus.OpenCanceled)
                {
                    if (t.EnterPoint.DealQty == 0)
                    {
                        t.Finished = true;
                    }
                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受入场撤单通知", this.policyName)));
                }
                else if (status == OpenStatus.CloseCanceled)
                {
                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受出场撤单通知", this.policyName)));
                }
            }
        }
示例#2
0
        public override void Notify(Guid tradeGuid, OpenStatus status, double dealQty = 0, double dealPrice = 0, string weituobianhao = "", string pendWeituobianhao = "")
        {
            for (int i = 0; i < tps.ToArray().Count(); i++)
            {
                var t = tps[i];
                if (t.TradeGuid == tradeGuid)
                {
                    if (status == OpenStatus.Opened)
                    {
                        decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                        t.EnterPoint.DealQty   = (double)((decimal)dealQty + (decimal)t.EnterPoint.PartDealQty);
                        t.EnterPoint.DealPrice = (dealPrice + t.EnterPoint.OpenPrice) / t.EnterPoint.DealQty;
                        holdHands += realDealQty;

                        if (t.EnterPoint.OpenType == OpenType.KaiDuo)
                        {
                            long_position += (int)dealQty;
                        }
                        else if (t.EnterPoint.OpenType == OpenType.KaiKong)
                        {
                            short_position += (int)dealQty;
                        }
                        if (long_position == (int)parameter.qty || short_position == (int)parameter.qty)
                        {
                            open_complete = 0;
                        }

                        t.Status         = OpenStatus.Opened;
                        frozenOpenHands -= realDealQty;
                        RaiseMessage(new PolicyMessageEventArgs("策略已接受开仓通知"));
                    }
                    else if (status == OpenStatus.Open)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受开仓下单通知", this.policyName)));
                    }
                    else if (status == OpenStatus.Close)
                    {
                        OpenPointWeiTuo opwt = new OpenPointWeiTuo();
                        opwt.Weituobianhao = weituobianhao;
                        opwt.OpenQty       = dealQty;
                        t.OutPoint.OpenPointWeiTuo.Add(opwt);
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受平仓下单通知", this.policyName)));
                    }
                    else if (status == OpenStatus.Closed)
                    {
                        double RealTotalDeal = 0;
                        bool   find          = false;
                        for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                        {
                            if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                            {
                                OpenPointWeiTuo opwt        = t.OutPoint.OpenPointWeiTuo[j];
                                decimal         realDealQty = (decimal)dealQty + (decimal)opwt.PartDealQty - (decimal)opwt.DealQty;
                                frozenCloseHands -= realDealQty;
                                holdHands        -= realDealQty;
                                t.OutPoint.OpenPointWeiTuo[j].DealQty = dealQty + opwt.PartDealQty;
                                find = true;
                            }
                            RealTotalDeal += t.OutPoint.OpenPointWeiTuo[j].DealQty;
                        }


                        if (t.OutPoint.OpenType == OpenType.PingDuo)
                        {
                            long_position -= (int)dealQty;
                        }
                        else if (t.OutPoint.OpenType == OpenType.PingKong)
                        {
                            short_position -= (int)dealQty;
                        }

                        if (long_position == 0 || short_position == 0)
                        {
                            close_complete = 0;
                        }


                        if (t.EnterPoint.DealQty == RealTotalDeal)
                        {
                            t.Finished = true;
                        }
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受平仓通知-{1}-有单子:{2}", this.policyName, weituobianhao, find.ToString())));
                    }
                    else if (status == OpenStatus.OpenPending)
                    {
                        t.EnterPoint.PartDealQty = t.EnterPoint.DealQty;
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接收入场追单通知-HoldHands:{1}", this.policyName, holdHands)));
                    }
                    else if (status == OpenStatus.ClosePending)
                    {
                        OpenPointWeiTuo opwt = new OpenPointWeiTuo();
                        opwt.Weituobianhao = pendWeituobianhao;
                        opwt.OpenQty       = dealQty;
                        t.OutPoint.OpenPointWeiTuo.Add(opwt);
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接收出场追单通知HoldHands:{1}", this.policyName, holdHands)));
                    }
                    else if (status == OpenStatus.Failed)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受失败通知", this.policyName)));
                    }
                    else if (status == OpenStatus.PartOpend)
                    {
                        if (dealQty > (t.EnterPoint.DealQty - t.EnterPoint.PartDealQty))
                        {
                            decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                            t.EnterPoint.DealQty = dealQty + t.EnterPoint.PartDealQty;
                            frozenOpenHands     -= realDealQty;
                            holdHands           += realDealQty;
                            RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分入场成交通知,成交数量:{1}", this.policyName, dealQty)));
                        }
                        long_position  += (int)dealQty;
                        short_position += (int)dealQty;
                    }
                    else if (status == OpenStatus.PartClosed)
                    {
                        for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                        {
                            if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                            {
                                OpenPointWeiTuo opwt = t.OutPoint.OpenPointWeiTuo[j];
                                if (dealQty > (opwt.DealQty - opwt.PartDealQty))
                                {
                                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分出场成交通知,成交数量:{1}", this.policyName, dealQty)));
                                    decimal realDealQty = (decimal)dealQty + (decimal)opwt.PartDealQty - (decimal)opwt.DealQty;
                                    frozenCloseHands -= realDealQty;
                                    holdHands        -= realDealQty;
                                    t.OutPoint.OpenPointWeiTuo[j].DealQty = dealQty + opwt.PartDealQty;
                                }
                                break;
                            }
                        }
                        long_position  -= (int)dealQty;
                        short_position -= (int)dealQty;
                    }
                    else if (status == OpenStatus.OpenCanceled)
                    {
                        frozenOpenHands -= (decimal)dealQty;
                        if (t.EnterPoint.DealQty == 0)
                        {
                            t.Finished = true;
                        }

                        open_complete  = 0;
                        close_complete = 0;


                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受入场撤单通知", this.policyName)));
                    }
                    else if (status == OpenStatus.CloseCanceled)
                    {
                        frozenCloseHands -= (decimal)dealQty;
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受出场撤单通知", this.policyName)));
                    }
                }
            }
        }
示例#3
0
        public override void Notify(Guid tradeGuid, OpenStatus status, double dealQty = 0, double dealPrice = 0, string weituobianhao = "", string pendWeituobianhao = "")
        {
            for (int i = 0; i < tps.ToArray().Count(); i++)
            {
                var t = tps[i];
                if (t.TradeGuid == tradeGuid && currentTick.IsReal)
                {
                    if (status == OpenStatus.Opened)
                    {
                        t.EnterPoint.OpenPrice = dealPrice;
                        decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                        t.EnterPoint.DealQty = (double)((decimal)dealQty + (decimal)t.EnterPoint.PartDealQty);
                        t.Status             = OpenStatus.Opened;
                        openComplete         = true;
                        openHands            = 0;
                        RaiseMessage(new PolicyMessageEventArgs("策略已接受开仓通知"));
                    }
                    else if (status == OpenStatus.Open)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受开仓下单通知", this.policyName)));
                    }
                    else if (status == OpenStatus.Close)
                    {
                        OpenPointWeiTuo opwt = new OpenPointWeiTuo();
                        opwt.Weituobianhao = weituobianhao;
                        opwt.OpenQty       = dealQty;
                        t.OutPoint.OpenPointWeiTuo.Add(opwt);

                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受平仓下单通知", this.policyName)));
                    }
                    else if (status == OpenStatus.Closed)
                    {
                        double RealTotalDeal = 0;
                        bool   find          = false;
                        for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                        {
                            if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                            {
                                OpenPointWeiTuo opwt        = t.OutPoint.OpenPointWeiTuo[j];
                                decimal         realDealQty = (decimal)dealQty + (decimal)opwt.PartDealQty - (decimal)opwt.DealQty;
                                t.OutPoint.OpenPointWeiTuo[j].DealQty = dealQty + opwt.PartDealQty;
                                find = true;
                            }
                            RealTotalDeal += t.OutPoint.OpenPointWeiTuo[j].DealQty;
                        }
                        if (t.EnterPoint.DealQty == RealTotalDeal)
                        {
                            closeComplete = true;
                            t.Finished    = true;
                        }
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受平仓通知-{1}-有单子:{2}", this.policyName, weituobianhao, find.ToString())));
                    }
                    else if (status == OpenStatus.OpenPending)
                    {
                        t.EnterPoint.PartDealQty = t.EnterPoint.DealQty;
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略HoldHands:{1}", this.policyName, holdHands)));
                    }
                    else if (status == OpenStatus.ClosePending)
                    {
                        for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                        {
                            if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                            {
                                t.OutPoint.OpenPointWeiTuo[j].PartDealQty   = t.OutPoint.OpenPointWeiTuo[j].DealQty;
                                t.OutPoint.OpenPointWeiTuo[j].Weituobianhao = pendWeituobianhao;
                            }
                        }
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略HoldHands:{1}", this.policyName, holdHands)));
                    }
                    else if (status == OpenStatus.Failed)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受失败通知", this.policyName)));
                    }
                    else if (status == OpenStatus.PartOpend)
                    {
                        if (dealQty > (t.EnterPoint.DealQty - t.EnterPoint.PartDealQty))
                        {
                            decimal realDealQty = (decimal)dealQty + (decimal)t.EnterPoint.PartDealQty - (decimal)t.EnterPoint.DealQty;
                            t.EnterPoint.DealQty = dealQty + t.EnterPoint.PartDealQty;
                            RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分入场成交通知,成交数量:{1}", this.policyName, dealQty)));
                        }
                    }
                    else if (status == OpenStatus.PartClosed)
                    {
                        for (int j = 0; j < t.OutPoint.OpenPointWeiTuo.Count; j++)
                        {
                            if (t.OutPoint.OpenPointWeiTuo[j].Weituobianhao == weituobianhao)
                            {
                                OpenPointWeiTuo opwt = t.OutPoint.OpenPointWeiTuo[j];
                                if (dealQty > (opwt.DealQty - opwt.PartDealQty))
                                {
                                    RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受部分出场成交通知,成交数量:{1}", this.policyName, dealQty)));
                                    decimal realDealQty = (decimal)dealQty + (decimal)opwt.PartDealQty - (decimal)opwt.DealQty;
                                    t.OutPoint.OpenPointWeiTuo[j].DealQty = dealQty + opwt.PartDealQty;
                                }
                                break;
                            }
                        }
                    }
                    else if (status == OpenStatus.OpenCanceled)
                    {
                        if (t.EnterPoint.DealQty == 0)
                        {
                            t.Finished   = true;
                            openSide     = 0;
                            openComplete = true;
                            openHands    = 0;
                        }
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受入场撤单通知", this.policyName)));
                    }
                    else if (status == OpenStatus.CloseCanceled)
                    {
                        RaiseMessage(new PolicyMessageEventArgs(string.Format("{0}-策略已接受出场撤单通知", this.policyName)));
                    }
                }
            }
        }