コード例 #1
0
ファイル: Limit.cs プロジェクト: 296083197/ts
        private Limit()
        {
            //:lastC
            DBDataContext db = new DBDataContext();
            var           t0 = from a in db.tbDateLineExts
                               group a by a.code into g
                               select new { code = g.Key, date = g.Max(a => a.date) };

            var t1 = from a in db.tbDateLineExts
                     join b in t0
                     on new { a.code, a.date } equals new { b.code, b.date }
            select new { a.code, a.date, a.C };

            foreach (var item in t1)
            {
                this.mpCodeLastC.Add(item.code, item.C);
            }

            coRDC crdc = new coRDC();

            //update
            Console.WriteLine("Limit-getAllQuotes");
            List <RealtimeDataCenter.RealtimeData> ltRd = new List <RealtimeDataCenter.RealtimeData>();

            if (!crdc.getAllQuotes(ref ltRd))
            {
                throw new Exception("getAllQuotes");
            }
            foreach (var rd in ltRd)
            {
                if (this.mpCodeLastC.ContainsKey(rd.code))
                {
                    if (this.mpCodeLastC[rd.code] != rd.lastC && rd.lastC != 0)
                    {
                        Console.WriteLine("ModifiedLastC:" + rd.code + "," + this.mpCodeLastC[rd.code].ToString() + "," + rd.lastC.ToString());

                        dcModifiedLastC.Add(rd.code, new Tuple <decimal, decimal>(this.mpCodeLastC[rd.code], rd.lastC));
                        this.mpCodeLastC[rd.code] = rd.lastC;
                    }
                }
                else
                {
                    this.mpCodeLastC.Add(rd.code, rd.lastC);
                }
            }
            Console.WriteLine("Limit-getAllQuotes OK");
            ///:~

            //:TodayXDR
            Console.WriteLine("Limit-getAllTodayXDR");
            List <KeyValuePair <string, coRDC.TodayXDR> > ltData = new List <KeyValuePair <string, coRDC.TodayXDR> >();

            crdc.getAllTodayXDR(ref ltData);
            foreach (var item in ltData)
            {
                if (!this.dcXDR.ContainsKey(item.Key))
                {
                    this.dcXDR.Add(item.Key, item.Value);
                }
            }
            Console.WriteLine("Limit-getAllTodayXDR OK");
            ///:~

            //:name
            Console.WriteLine("Limit-getAllSecuritys");
            if (!crdc.getAllSecuritys(ref dcCodeNameShenzhen, ref dcCodeNameShanghai))
            {
                throw new Exception("getAllSecuritys");
            }
            Console.WriteLine("Limit-getAllSecuritys OK");
            ///:~
        }
コード例 #2
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);
                }
            }
        }