Example #1
0
File: TN.cs Project: 296083197/ts
        public TN()
        {
            DBDataContext db = new DBDataContext();
            var           t  = from a in db.tsInstructions
                               join b in db.tsSimplifiedStrategiesObjects
                               on a.idForObj equals b.id
                               where a.state == (short)Reactor.EInstructionState.WATING ||
                               a.state == (short)Reactor.EInstructionState.SENT
                               select new { b.code, a.id, a.priceAsc, a.priceDesc, a.priceType, a.price, a.category, a.quantity, a.state, a.generateTime, a.sendTime, a.resultTime, a.desc, b.direction };

            foreach (var item in t)
            {
                Reactor.CInstruction instruction = new Reactor.CInstruction()
                {
                    sso = null,

                    id            = item.id,
                    priceAsc      = item.priceAsc,
                    priceDesc     = item.priceDesc,
                    priceType     = item.priceType,
                    price         = item.price,
                    category      = item.category,
                    quantity      = item.quantity,
                    state         = item.state,
                    generateTime  = item.generateTime,
                    sendTime      = item.sendTime,
                    resultTime    = item.resultTime,
                    desc          = item.desc,
                    codeReference = item.code,
                };
                instruction.analyseEntryOrExit((Reactor.EDirection)(item.direction));

                if (Reactor.EInstructionState.WATING == (Reactor.EInstructionState)instruction.state)
                {
                    if (!Limit.getInstance().isTodayXDR(item.code))
                    {
                        Reactor.getInstance().addInstruction2Wating(item.code, instruction);
                    }
                }
                else if (Reactor.EInstructionState.SENT == (Reactor.EInstructionState)instruction.state)
                {
                    Reactor.getInstance().addInstruction2Sent(item.code, instruction);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            /*
             * string szTime = DateTime.Now.ToString("HHmmss");
             * while (string.Compare(szTime, "091500") < 0
             || string.Compare(szTime, "150000") > 0)
             ||{
             || Console.WriteLine(szTime);
             || System.Threading.Thread.Sleep(1000);
             || szTime = DateTime.Now.ToString("HHmmss");
             ||}
             */

            StringBuilder sErrInfo = new StringBuilder(256);
            int           ret      = TradeXB.OpenTdx(sErrInfo);

            if (ret < 0)
            {
                Console.WriteLine("TradeXB.OpenTdx error: " + sErrInfo);
                Console.ReadLine();
                return;
            }

            RealtimeDataCenter.getInstance(5, "999999,399001,399006", RealtimeDataCenter.EDataSource.tradeX);
            Limit.getInstance();
            Reactor.getInstance();

            TN   tn   = new TN();
            MAID maid = new MAID();
            RI   ri   = new RI();
            RT   rt   = new RT();

            while (true)
            {
                Console.ReadLine();
            }
        }
Example #3
0
File: RT.cs Project: 296083197/ts
        protected override void recv(RealtimeDataCenter.RealtimeData rd)
        {
            if (DateTime.Now.Date != rd.dt.Date)
            {
                return;
            } //expired data

            if (this.dcTendency.ContainsKey(rd.code))
            {
                decimal[] dcps = this.dcTendency[rd.code].ToArray();
                foreach (var dcp in dcps)
                {
                    if (rd.C >= dcp)
                    {
                        bool bCreate          = false;
                        Reactor.EPriceType pt = Reactor.EPriceType.REALTIME;

                        if ((rd.C / rd.lastC - 1) * 100 < 3.0m)
                        {
                            bCreate = true;
                            pt      = Reactor.EPriceType.REALTIME;
                        }

                        if (bCreate)
                        {
                            Reactor.CInstruction instruction = new Reactor.CInstruction();
                            instruction.id            = 0;
                            instruction.priceAsc      = dcp + 0.01m;
                            instruction.priceDesc     = Limit.getInstance().getLimitUp(rd.code, rd.lastC) - 0.01m; //-0.01m, don't buy when limit-up
                            instruction.generateTime  = DateTime.Now;
                            instruction.priceType     = (short)pt;
                            instruction.category      = (short)Reactor.ECategory.BUY;
                            instruction.state         = (short)Reactor.EInstructionState.WATING;
                            instruction.desc          = "entry";
                            instruction.quantity      = (int)(Math.Round(CASH_SIZE / (decimal)instruction.priceAsc / 100m) * 100m);
                            instruction.codeReference = rd.code;

                            if (instruction.quantity > 0)
                            {
                                instruction.sso = new Reactor.CSimplifiedStrategiesObject()
                                {
                                    id = 0,
                                    idForStrategies = (long)Reactor.EIFS.RT,
                                    code            = rd.code,
                                    state           = (short)Reactor.ESSOState.WAIT_CREATE,
                                    planQuantity    = instruction.quantity,
                                    lastStopPrice   = (decimal)instruction.priceAsc,
                                    createTime      = instruction.generateTime,
                                    direction       = (short)Reactor.EDirection.LONG,
                                };
                                instruction.analyseEntryOrExit((Reactor.EDirection)(instruction.sso.direction));

                                //直接removeObj,以及下面的break (foreach),而不使用下面的注释部分,原因在于:Reactor.EIFS.RT中,同一对象有多个tendency line时,当日只进入一次
                                removeObj(rd.code);

                                /*
                                 * this.dcTendency[rd.code].Remove(dcp);
                                 * if (this.dcTendency[rd.code].Count == 0)
                                 * { removeObj(rd.code); }
                                 */
                                Reactor.getInstance().addInstruction2Wating(rd.code, instruction);

                                break;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        protected override void recv(RealtimeDataCenter.RealtimeData rd)
        {
            if (DateTime.Now.Date != rd.dt.Date)
            {
                return;
            } //expired data

            if (this.dcWindow.ContainsKey(rd.code))
            {
                Tuple <decimal, decimal> wind = this.dcWindow[rd.code];
                if (rd.L <= wind.Item2) //当日将不再会形成跳空式的关闭窗口(即RI)
                {
                    removeObj(rd.code);
                }
                else
                {
                    if (rd.C >= wind.Item1)
                    {
                        bool bCreate          = false;
                        Reactor.EPriceType pt = Reactor.EPriceType.REALTIME;

                        if ((rd.C / rd.lastC - 1) * 100 > 9.0m) //推测其将limit-up,先买入(此点需继续验证)
                        {
                            bCreate = true;
                            pt      = Reactor.EPriceType.REALTIME;
                        }
                        else if (string.Compare(rd.dt.ToString("HHmmss"), "145940") > 0)
                        {
                            bCreate = true;
                            pt      = Reactor.EPriceType.CLOSE;
                        }

                        if (bCreate)
                        {
                            Reactor.CInstruction instruction = new Reactor.CInstruction();
                            instruction.id            = 0;
                            instruction.priceAsc      = wind.Item2 + 0.01m;
                            instruction.priceDesc     = Limit.getInstance().getLimitUp(rd.code, rd.lastC) - 0.01m; //-0.01m, don't buy when limit-up
                            instruction.generateTime  = DateTime.Now;
                            instruction.priceType     = (short)pt;
                            instruction.category      = (short)Reactor.ECategory.BUY;
                            instruction.state         = (short)Reactor.EInstructionState.WATING;
                            instruction.desc          = "entry";
                            instruction.quantity      = (int)(Math.Round(CASH_SIZE / (decimal)instruction.priceAsc / 100m) * 100m);
                            instruction.codeReference = rd.code;

                            if (instruction.quantity > 0)
                            {
                                instruction.sso = new Reactor.CSimplifiedStrategiesObject()
                                {
                                    id = 0,
                                    idForStrategies = (long)Reactor.EIFS.RI,
                                    code            = rd.code,
                                    state           = (short)Reactor.ESSOState.WAIT_CREATE,
                                    planQuantity    = instruction.quantity,
                                    lastStopPrice   = (decimal)instruction.priceAsc,
                                    createTime      = instruction.generateTime,
                                    direction       = (short)Reactor.EDirection.LONG,
                                };
                                instruction.analyseEntryOrExit((Reactor.EDirection)(instruction.sso.direction));

                                removeObj(rd.code);
                                Reactor.getInstance().addInstruction2Wating(rd.code, instruction);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        private void worker()
        {
            bool bExecuted = false;

            while (!bExecuted)
            {
                DateTime dt = DateTime.Now;
                if (string.Compare(dt.ToString("HHmmss"), "144000") > 0 &&
                    string.Compare(dt.ToString("HHmmss"), "155900") < 0)
                {
                    bExecuted = true;

                    List <KeyValuePair <string, List <coRDC.Bar1M> > > lt1M = new List <KeyValuePair <string, List <coRDC.Bar1M> > >();
                    coRDC crdc = new coRDC();
                    crdc.getAll1MBars(ref lt1M);
                    foreach (var obj in lt1M)
                    {
                        string code  = obj.Key;
                        int    count = obj.Value.Count;
                        if (count < 200)
                        {
                            continue;
                        }

                        int       moreAvgInDayCount = 0;
                        decimal   sumV = 0, sum_vm = 0, maxH = 0;
                        decimal[] avg = new decimal[count];
                        int       idx = 0;
                        foreach (var b1m in obj.Value)
                        {
                            if (b1m.H > maxH)
                            {
                                maxH = b1m.H;
                            }

                            sumV   += b1m.V;
                            sum_vm += b1m.vm;
                            if (sumV > 0)
                            {
                                avg[idx] = sum_vm / sumV;
                                if (b1m.C > avg[idx])
                                {
                                    moreAvgInDayCount++;
                                }
                            }

                            idx++;
                        }

                        decimal percent = (decimal)moreAvgInDayCount / count;
                        if (percent >= 0.50m)
                        {
                            decimal lastC = Limit.getInstance().getLastC(code);
                            if (lastC > 0 &&
                                maxH != Limit.getInstance().getLimitUp(code, lastC))      //exclude that limit up to drawdown
                            {
                                decimal priceAsc  = Math.Max(lastC * 1.085m, maxH * 0.999m);
                                decimal priceDesc = Limit.getInstance().getLimitUp(code, lastC) - 0.01m;
                                if (priceDesc >= priceAsc)
                                {
                                    Reactor.CInstruction instruction = new Reactor.CInstruction();
                                    instruction.id            = 0;
                                    instruction.priceAsc      = priceAsc;
                                    instruction.priceDesc     = priceDesc;
                                    instruction.generateTime  = DateTime.Now;
                                    instruction.priceType     = (short)Reactor.EPriceType.REALTIME;
                                    instruction.category      = (short)Reactor.ECategory.BUY;
                                    instruction.state         = (short)Reactor.EInstructionState.WATING;
                                    instruction.desc          = "entry";
                                    instruction.quantity      = (int)(Math.Round(CASH_SIZE / (decimal)instruction.priceAsc / 100m) * 100m);
                                    instruction.codeReference = code;

                                    if (instruction.quantity > 0)
                                    {
                                        instruction.sso = new Reactor.CSimplifiedStrategiesObject()
                                        {
                                            id = 0,
                                            idForStrategies = (long)Reactor.EIFS.MAID,
                                            code            = code,
                                            state           = (short)Reactor.ESSOState.WAIT_CREATE,
                                            planQuantity    = instruction.quantity,
                                            lastStopPrice   = (decimal)instruction.priceAsc,
                                            createTime      = instruction.generateTime,
                                            direction       = (short)Reactor.EDirection.LONG,
                                        };
                                        instruction.analyseEntryOrExit((Reactor.EDirection)(instruction.sso.direction));

                                        Reactor.getInstance().addInstruction2Wating(code, instruction);
                                    }
                                }
                            }
                        }
                    }
                }

                if (!bExecuted)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            }
        }