Example #1
0
 protected List <string> RequestCodeList(List <string> list, string[] market)
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
         {
             foreach (var temp in db.Codes.Select(o => new
             {
                 o.Code,
                 o.Info
             }))
             {
                 if (temp.Code.Length == 6 && Array.Exists(market, o => o.Equals(temp.Code)) || temp.Code.Length == 8 && DateTime.Compare(DateTime.ParseExact(temp.Info, "yyyyMMdd", null), DateTime.Now) >= 0)
                 {
                     list.Add(temp.Code);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace);
     }
     return(list);
 }
Example #2
0
        protected bool SetBasicChart(Queue <Charts> charts)
        {
            bool result;

            using (var db = new GoblinBatDbContext(key))
                try
                {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.BulkInsert(charts, o =>
                    {
                        o.InsertIfNotExists      = true;
                        o.BatchSize              = 15000;
                        o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                        o.AutoMapOutputDirection = false;
                    });
                    result = true;
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace);
                    result = false;
                }
            finally
            {
                db.Configuration.AutoDetectChangesEnabled = true;
            }
            return(result);
        }
        protected void SetStorage(Logs log)
        {
            new Task(() =>
            {
                try
                {
                    using (var db = new GoblinBatDbContext(key))
                    {
                        var check = db.Logs.Find(new object[]
                        {
                            log.Code,
                            log.Strategy,
                            log.Assets,
                            log.Date
                        });
                        if (check != null && db.Logs.Where(o => o.Cumulative.Equals(log.Cumulative) && check.Cumulative.Equals(log.Cumulative) && o.Revenue.Equals(log.Revenue) && check.Revenue.Equals(log.Revenue) && check.Unrealized.Equals(log.Unrealized) && o.Unrealized.Equals(log.Unrealized)).Any())
                        {
                            return;
                        }

                        db.Logs.AddOrUpdate(log);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace);
                }
            }).Start();
        }
Example #4
0
        protected void SetInsertCode(string code, string name, string info)
        {
            new Task(() =>
            {
                try
                {
                    using (var db = new GoblinBatDbContext(key))
                    {
                        if (db.Codes.Where(o => o.Code.Equals(code) && o.Info.Equals(info) && o.Name.Equals(name)).Any())
                        {
                            return;
                        }

                        db.Codes.AddOrUpdate(new Codes
                        {
                            Code = code,
                            Name = name,
                            Info = info
                        });
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, code);
                }
            }).Start();
        }
Example #5
0
        protected bool SetStatisticalBulkStorage(Queue <Strategics> memo)
        {
            var complete = false;

            using (var db = new GoblinBatDbContext(key))
                try
                {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.BulkInsert(memo, o =>
                    {
                        o.InsertIfNotExists      = true;
                        o.BatchSize              = 13750;
                        o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                        o.AutoMapOutputDirection = false;
                    });
                    complete = true;
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, ex.TargetSite.Name);
                }
            finally
            {
                db.Configuration.AutoDetectChangesEnabled = true;
            }
            return(complete);
        }
Example #6
0
        protected Stack <double> GetBasicChart(string check, DateTime now, Specify specify, int period, Stack <double> stack)
        {
            if (specify.Time == 1440)
            {
                try
                {
                    for (int i = 0; i > int.MinValue; i--)
                    {
                        var date = i == 0 ? now.ToString(format) : now.AddDays(i).ToString(format);
                        int time;

                        if (check.Equals(date))
                        {
                            using (var db = new GoblinBatDbContext(key))
                            {
                                switch (now.Hour)
                                {
                                case 6:
                                case 7:
                                case 8:
                                    time = db.Charts.Any(o => o.Time == 660) ? 660 : 405;
                                    break;

                                case 16:
                                case 17:
                                    time = 405;
                                    break;

                                default:
                                    return(stack);
                                }
                                var call = db.Charts.Where(o => o.Code.Equals(specify.Code) && o.Time == time && o.Base == period).AsNoTracking();

                                if (call.Any(o => o.Date.Equals(check)))
                                {
                                    foreach (var e in call.OrderByDescending(o => o.Date).Take(period + 1).Select(o => new { o.Value, o.Date }).OrderBy(o => o.Date))
                                    {
                                        stack.Push(e.Value);
                                    }

                                    return(stack);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, specify.Code);
                }
            }
            return(null);
        }
Example #7
0
        protected void SetStorage(string code, IOrderedEnumerable <KeyValuePair <string, string> > param, Queue <Futures> cme)
        {
            using (var sw = new StreamWriter(string.Concat(System.IO.Path.Combine(Application.StartupPath, charts), @"\", code, res), true))
                foreach (var kv in param)
                {
                    if (kv.Key.Substring(6, 4).Equals(start))
                    {
                        return;
                    }

                    var temp = kv.Value.Split(',');

                    if (temp.Length == 2)
                    {
                        try
                        {
                            if (int.TryParse(temp[1], out int cVolume) && double.TryParse(temp[0], out double cPrice) && long.TryParse(kv.Key, out long cDate))
                            {
                                cme.Enqueue(new Futures
                                {
                                    Code   = code,
                                    Date   = cDate,
                                    Price  = cPrice,
                                    Volume = cVolume
                                });
                            }
                            sw.WriteLine(string.Concat(kv.Key, ",", temp[0], ",", temp[1]));
                        }
                        catch (Exception ex)
                        {
                            new ExceptionMessage(ex.StackTrace, code);
                        }
                    }
                }
            if (new Secret().GetTrustedConnection(key))
            {
                using (var db = new GoblinBatDbContext(key))
                    try
                    {
                        db.Configuration.AutoDetectChangesEnabled = false;
                        db.BulkInsert(cme, o =>
                        {
                            o.InsertIfNotExists      = true;
                            o.BatchSize              = 15000;
                            o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                            o.AutoMapOutputDirection = false;
                        });
                    }
                    catch (Exception ex)
                    {
                        new ExceptionMessage(ex.StackTrace, code);
                    }
            }
Example #8
0
 protected void BulkRemove(string code)
 {
     using (var db = new GoblinBatDbContext(key))
         try
         {
             db.Material.BulkDelete(db.Material.Where(o => o.Date.Equals(code)), o => o.BatchSize = 1000000);
         }
         catch (Exception ex)
         {
             new ExceptionMessage(ex.StackTrace);
         }
 }
 protected void DeleteLogs()
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
             db.Logs.BulkDelete(db.Logs.Where(o => o.Code.Equals(string.Concat(kospi200f, "Q3", futures))));
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace);
     }
 }
Example #10
0
 protected bool GetRegister()
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
             return(db.Logs.Any());
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace);
     }
     return(false);
 }
Example #11
0
 protected string SetDate(string code)
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
             return(db.Datums.Where(o => o.Code.Contains(code.Substring(0, 3)) && (o.Date.Contains("1545") || o.Date.Contains("0500"))).AsNoTracking().Max(o => o.Date).Trim());
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace, code);
     }
     return(DateTime.Now.ToString(date));
 }
Example #12
0
 protected bool GetDuplicateResults(Strategics game, string date)
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
             return(db.Material.Where(o => o.Assets == game.Assets && o.Code.Equals(game.Code) && o.Commission == game.Commission && o.MarginRate == game.MarginRate && o.Strategy.Equals(game.Strategy) && o.RollOver.Equals(game.RollOver) && o.BaseTime == game.BaseTime && o.BaseShort == game.BaseShort && o.BaseLong == game.BaseLong && o.NonaTime == game.NonaTime && o.NonaShort == game.NonaShort && o.NonaLong == game.NonaLong && o.OctaTime == game.OctaTime && o.OctaShort == game.OctaShort && o.OctaLong == game.OctaLong && o.HeptaTime == game.HeptaTime && o.HeptaShort == game.HeptaShort && o.HeptaLong == game.HeptaLong && o.HexaTime == game.HexaTime && o.HexaShort == game.HexaShort && o.HexaLong == game.HexaLong && o.PentaTime == game.PentaTime && o.PentaShort == game.PentaShort && o.PentaLong == game.PentaLong && o.QuadTime == game.QuadTime && o.QuadShort == game.QuadShort && o.QuadLong == game.QuadLong && o.TriTime == game.TriTime && o.TriShort == game.TriShort && o.TriLong == game.TriLong && o.DuoTime == game.DuoTime && o.DuoShort == game.DuoShort && o.DuoLong == game.DuoLong && o.MonoTime == game.MonoTime && o.MonoShort == game.MonoShort && o.MonoLong == game.MonoLong).AsNoTracking().Any(o => o.Date.Equals(date)));
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.TargetSite.Name, game.Strategy);
     }
     return(false);
 }
Example #13
0
 protected string GetStrategy()
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
             return(db.Codes.AsNoTracking().First(c => c.Info.Equals(db.Codes.Where(o => o.Code.Length == 8 && o.Code.Substring(0, 3).Equals(kospi200f) && o.Code.Substring(5, 3).Equals(futures)).Max(o => o.Info))).Code);
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace);
     }
     return(string.Empty);
 }
Example #14
0
        protected bool GetRecentAnalysis(Specify s)
        {
            var date = DateTime.Now.Hour < 5 && DateTime.Now.Hour >= 0 ? DateTime.Now.AddDays(-1).ToString(CallUpGoblinBat.date) : DateTime.Now.ToString(CallUpGoblinBat.date);

            try
            {
                using (var db = new GoblinBatDbContext(key))
                    return(db.Logs.Any(o => o.Date.ToString().Equals(date) && o.Code.Equals(s.Code) && o.Assets.Equals(s.Assets) && o.Strategy.Equals(s.Strategy) && o.Date.Equals(s.Time)));
            }
            catch (Exception ex)
            {
                new ExceptionMessage(ex.StackTrace, s.Code);
            }
            return(false);
        }
Example #15
0
        protected string OnReceiveRemainingDay(string code)
        {
            using (var db = new GoblinBatDbContext(key))
                try
                {
                    var day = db.Codes.Where(o => o.Code.Equals(code)).First().Info;

                    return(day.Substring(2));
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace);
                }
            return(string.Empty);
        }
Example #16
0
        protected int DeleteUnnecessaryInformation(string code, string info)
        {
            using (var db = new GoblinBatDbContext(key))
                try
                {
                    var entity = db.Codes.Where(o => o.Code.Equals(code) && o.Info.Equals(info)).First();
                    db.Codes.Remove(entity);

                    return(db.SaveChanges());
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace);
                }
            return(int.MinValue);
        }
Example #17
0
 protected string GetRecentFuturesCode(bool register)
 {
     if (register == false)
     {
         try
         {
             using (var db = new GoblinBatDbContext(key))
                 return(db.Codes.First(code => code.Info.Equals(db.Codes.Where(o => o.Code.Substring(0, 3).Equals(kospi200f) && o.Code.Substring(5, 3).Equals(futures)).Max(o => o.Info))).Code);
         }
         catch (Exception ex)
         {
             new ExceptionMessage(ex.StackTrace);
         }
     }
     return(string.Empty);
 }
Example #18
0
 protected string GetRecentDate(string max)
 {
     using (var db = new GoblinBatDbContext(key))
         try
         {
             if (db.Material.Any(o => o.Date.Equals(max)))
             {
                 return(max);
             }
         }
         catch (Exception ex)
         {
             new ExceptionMessage(ex.StackTrace);
         }
     return(string.Empty);
 }
Example #19
0
 protected bool GetRemainingDate(string code, long date)
 {
     try
     {
         if (code.Length == 8 && date.ToString().Substring(6).Equals("151959000"))
         {
             using (var db = new GoblinBatDbContext(key))
                 if (db.Codes.FirstOrDefault(o => o.Code.Equals(code)).Info.Substring(2).Equals(date.ToString().Substring(0, 6)))
                 {
                     return(true);
                 }
         }
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace, code);
     }
     return(false);
 }
Example #20
0
        protected string GetRetention(int param, string code)
        {
            long max = 0;

            try
            {
                using (var db = new GoblinBatDbContext(key))
                {
                    switch (param)
                    {
                    case 1:
                        max = db.Futures.Where(o => o.Code.Equals(code)).Max(o => o.Date);
                        break;

                    case 2:
                        max = db.Options.Where(o => o.Code.Equals(code)).Max(o => o.Date);
                        break;

                    case 3:
                        max = db.Stocks.Where(o => o.Code.Equals(code)).Max(o => o.Date);
                        break;

                    case 4:
                        max = db.Days.Where(o => o.Code.Equals(code)).Max(o => o.Date);
                        break;
                    }
                    ;
                }
            }
            catch (InvalidOperationException ex)
            {
                if (ex.TargetSite.Name.Equals("GetValue") == false)
                {
                    new ExceptionMessage(ex.TargetSite.Name, code);
                }
            }
            catch (Exception ex)
            {
                new ExceptionMessage(ex.StackTrace, code);
            }
            return(max > 0 ? (max.ToString().Length > 12 ? max.ToString().Substring(0, 12) : max.ToString()) : "DoesNotExist");
        }
Example #21
0
        protected bool SetStatisticalStorage(Queue <Strategics> memo)
        {
            int count = 0;

            using (var db = new GoblinBatDbContext(key))
                try
                {
                    while (memo.Count > 0)
                    {
                        db.Material.AddOrUpdate(memo.Dequeue());
                    }

                    count = db.SaveChanges();
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, ex.TargetSite.Name);
                }
            return(count > 0);
        }
Example #22
0
        protected long GetUserAssets(long assets)
        {
            try
            {
                var date     = DateTime.Now.ToString(format);
                var identity = new Secret().GetIdentify(key);
                var current  = long.MinValue;
                using (var db = new GoblinBatDbContext(key))
                    current = db.Identifies.First(o => o.Identity.Equals(identity) && o.Date.Equals(date)).Assets;

                if (current != long.MinValue && current != 0)
                {
                    return(current - assets);
                }
            }
            catch (Exception ex)
            {
                new ExceptionMessage(assets.ToString("N0"), ex.TargetSite.Name);
            }
            return(0);
        }
Example #23
0
 void SetStorage(List <Datum> model)
 {
     try
     {
         using (var db = new GoblinBatDbContext(key))
         {
             db.Configuration.AutoDetectChangesEnabled = true;
             db.BulkInsert(model, o =>
             {
                 o.InsertIfNotExists      = true;
                 o.BatchSize              = 15000;
                 o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                 o.AutoMapOutputDirection = false;
             });
             db.Configuration.AutoDetectChangesEnabled = false;
         }
     }
     catch (Exception ex)
     {
         new ExceptionMessage(ex.StackTrace, ex.TargetSite.Name);
     }
 }
Example #24
0
        protected Stack <double> GetBasicChart(Stack <double> stack, Specify specify, int period)
        {
            var path   = Path.Combine(Application.StartupPath, chart, specify.Code, specify.Time.ToString());
            var exists = new DirectoryInfo(path);
            var file   = string.Concat(path, @"\", period, res);
            var files  = new FileInfo(file);

            if (exists.Exists && files.Exists)
            {
                using (var sr = new StreamReader(file))
                    try
                    {
                        if (sr != null)
                        {
                            while (sr.EndOfStream == false)
                            {
                                if (double.TryParse(sr.ReadLine().Split(',')[1], out double value))
                                {
                                    stack.Push(value);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        new ExceptionMessage(ex.StackTrace, specify.Strategy);
                    }
            }
            else
            {
                var time = (int)specify.Time;
                var temp = new Dictionary <string, double>();
                using (var db = new GoblinBatDbContext(key))
                    try
                    {
                        var call = db.Charts.Where(o => o.Code.Equals(specify.Code) && o.Time == time && o.Base == period).AsNoTracking();

                        if (call.Any(o => o.Date.Equals(time == 1440 ? rDate : rTime)))
                        {
                            foreach (var e in call.OrderByDescending(o => o.Date).Take(period + 1).Select(o => new
                            {
                                o.Date,
                                o.Value
                            }).OrderBy(o => o.Date))
                            {
                                stack.Push(e.Value);
                                temp[e.Date] = e.Value;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        new ExceptionMessage(ex.StackTrace, specify.Strategy);
                    }
                if (temp.Count > 0)
                {
                    try
                    {
                        if (exists.Exists == false)
                        {
                            exists.Create();
                        }

                        using (var sw = new StreamWriter(file))
                            foreach (var kv in temp.OrderBy(o => o.Key))
                            {
                                sw.WriteLine(string.Concat(kv.Key, ',', kv.Value));
                            }
                    }
                    catch (Exception ex)
                    {
                        new ExceptionMessage(ex.StackTrace, specify.Strategy);
                    }
                }
            }
            return(stack);
        }
Example #25
0
        protected void SetStorage(string code, string[] param)
        {
            if (param.Length < 3)
            {
                return;
            }

            new Task(() =>
            {
                try
                {
                    string date  = string.Empty;
                    int i, count = 0;
                    bool days    = param[0].Split(',')[0].Length == 8, stocks = code.Length == 6, futures = code.Length > 6 && code.Substring(5, 3).Equals("000"), options = code.Length > 6 && !code.Substring(5, 3).Equals("000");
                    IList model;

                    if (futures)
                    {
                        model = new List <Futures>(32);
                    }

                    else if (options)
                    {
                        model = new List <Options>(32);
                    }

                    else if (days)
                    {
                        model = new List <Days>(32);
                    }

                    else
                    {
                        model = new List <Stocks>(32);
                    }

                    for (i = param.Length - 2; i > -1; i--)
                    {
                        var temp = param[i].Split(',');

                        if (temp[0].Length == 8)
                        {
                            model.Add(new Days
                            {
                                Code  = code,
                                Date  = int.Parse(temp[0]),
                                Price = double.Parse(temp[1])
                            });
                            continue;
                        }
                        else if (temp[0].Equals(date))
                        {
                            count++;
                        }

                        else
                        {
                            date  = temp[0];
                            count = 0;
                        }
                        if (stocks)
                        {
                            model.Add(new Stocks
                            {
                                Code   = code,
                                Date   = long.Parse(string.Concat(temp[0], count.ToString("D3"))),
                                Price  = int.Parse(temp[1]),
                                Volume = int.Parse(temp[2])
                            });
                        }
                        else if (options)
                        {
                            model.Add(new Options
                            {
                                Code   = code,
                                Date   = long.Parse(string.Concat(temp[0], count.ToString("D3"))),
                                Price  = double.Parse(temp[1]),
                                Volume = int.Parse(temp[2])
                            });
                        }
                        else if (futures)
                        {
                            model.Add(new Futures
                            {
                                Code   = code,
                                Date   = long.Parse(string.Concat(temp[0], count.ToString("D3"))),
                                Price  = double.Parse(temp[1]),
                                Volume = int.Parse(temp[2])
                            });
                        }
                    }
                    using (var db = new GoblinBatDbContext(key))
                    {
                        db.Configuration.AutoDetectChangesEnabled = true;

                        if (days)
                        {
                            db.BulkInsert((List <Days>)model, o =>
                            {
                                o.InsertIfNotExists      = true;
                                o.BatchSize              = 10000;
                                o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                                o.AutoMapOutputDirection = false;
                            });
                        }
                        else if (stocks)
                        {
                            db.BulkInsert((List <Stocks>)model, o =>
                            {
                                o.InsertIfNotExists      = true;
                                o.BatchSize              = 10000;
                                o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                                o.AutoMapOutputDirection = false;
                            });
                        }
                        else if (options)
                        {
                            db.BulkInsert((List <Options>)model, o =>
                            {
                                o.InsertIfNotExists      = true;
                                o.BatchSize              = 10000;
                                o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                                o.AutoMapOutputDirection = false;
                            });
                        }
                        else if (futures)
                        {
                            db.BulkInsert((List <Futures>)model, o =>
                            {
                                o.InsertIfNotExists      = true;
                                o.BatchSize              = 10000;
                                o.SqlBulkCopyOptions     = (int)SqlBulkCopyOptions.Default | (int)SqlBulkCopyOptions.TableLock;
                                o.AutoMapOutputDirection = false;
                            });
                        }
                        db.Configuration.AutoDetectChangesEnabled = false;
                    }
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, code);
                }
            }).Start();
        }
Example #26
0
        protected Dictionary <DateTime, string> GetInformation(Catalog.DataBase.ImitationGame game, string code)
        {
            try
            {
                var file     = string.Empty;
                var info     = new Dictionary <DateTime, string>(32);
                var temp     = new Dictionary <string, long>(32);
                var contents = new Dictionary <string, string>(32);
                var now      = DateTime.Now;
                using (var db = new GoblinBatDbContext(key))
                {
                    var count = 1;

                    while (count-- <= 1)
                    {
                        var find   = (count == 0 ? now : now.AddDays(count)).ToString("yyMMdd");
                        var exists = db.Material.Where(o => o.Date.Equals(find) && o.Assets == game.Assets && o.Code.Equals(game.Code) && o.Commission == game.Commission && o.MarginRate == game.MarginRate && o.Strategy.Equals(game.Strategy) && o.RollOver.Equals(game.RollOver) && o.BaseTime == game.BaseTime && o.BaseShort == game.BaseShort && o.BaseLong == game.BaseLong && o.NonaTime == game.NonaTime && o.NonaShort == game.NonaShort && o.NonaLong == game.NonaLong && o.OctaTime == game.OctaTime && o.OctaShort == game.OctaShort && o.OctaLong == game.OctaLong && o.HeptaTime == game.HeptaTime && o.HeptaShort == game.HeptaShort && o.HeptaLong == game.HeptaLong && o.HexaTime == game.HexaTime && o.HexaShort == game.HexaShort && o.HexaLong == game.HexaLong && o.PentaTime == game.PentaTime && o.PentaShort == game.PentaShort && o.PentaLong == game.PentaLong && o.QuadTime == game.QuadTime && o.QuadShort == game.QuadShort && o.QuadLong == game.QuadLong && o.TriTime == game.TriTime && o.TriShort == game.TriShort && o.TriLong == game.TriLong && o.DuoTime == game.DuoTime && o.DuoShort == game.DuoShort && o.DuoLong == game.DuoLong && o.MonoTime == game.MonoTime && o.MonoShort == game.MonoShort && o.MonoLong == game.MonoLong);

                        if (exists.Any())
                        {
                            var str = exists.First();
                            temp[str.Date]     = str.Cumulative + str.Unrealized;
                            contents[str.Date] = string.Concat(',', str.Unrealized, ',', str.Revenue, ',', str.Fees, ',', str.Cumulative, ',', str.Statistic);

                            if (string.IsNullOrEmpty(file))
                            {
                                file = string.Concat(str.BaseShort, '-', str.BaseLong, '-', str.MonoTime, '-', str.MonoShort, '-', str.MonoLong, '-', str.Strategy, '-', str.Primary, csv);
                            }
                        }
                        else if (find.Equals("190721"))
                        {
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(file) == false && contents.Count > 0)
                {
                    var queue = new Queue <string>(32);

                    foreach (var kv in contents.OrderBy(o => o.Key))
                    {
                        queue.Enqueue(string.Concat(kv.Key, kv.Value));
                    }

                    new ExceptionMessage(file, queue);
                    contents.Clear();
                }
                var dicPrice = new Dictionary <long, double>(128);
                var dicShort = new Dictionary <string, double>(128);
                var dicLong  = new Dictionary <string, double>(128);
                using (var db = new GoblinBatDbContext(key))
                    foreach (var dt in db.Futures.Where(o => o.Date % 0x3B9ACA00 == 0x9357BA0 && o.Code.Contains(code.Substring(0, 3)) && o.Code.Contains(code.Substring(5))).AsNoTracking().Select(o => new { o.Date, o.Price }))
                    {
                        dicPrice[dt.Date / 0x3B9ACA00] = dt.Price;
                    }

                using (var db = new GoblinBatDbContext(key))
                    foreach (var chart in db.Charts.Where(o => (o.Base == game.BaseShort || o.Base == game.BaseLong) && o.Code.Equals(code) && o.Time == 405).AsNoTracking().Select(o => new { o.Date, o.Base, o.Value }))
                    {
                        if (chart.Base == game.BaseShort)
                        {
                            dicShort[chart.Date] = chart.Value;
                        }

                        if (chart.Base == game.BaseLong)
                        {
                            dicLong[chart.Date] = chart.Value;
                        }
                    }
                foreach (var kv in temp.OrderBy(o => o.Key))
                {
                    if (dicShort.TryGetValue(kv.Key, out double bs) && dicLong.TryGetValue(kv.Key, out double bl) && long.TryParse(kv.Key, out long dp) && dicPrice.TryGetValue(dp, out double price) && DateTime.TryParseExact(string.Concat(kv.Key, "154500"), date, CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime infoDate))
                    {
                        info[infoDate] = string.Concat(kv.Value, ';', price, ';', bs, ';', bl);
                    }
                }

                return(info);
            }
            catch (Exception ex)
            {
                new ExceptionMessage(ex.StackTrace);
            }
            return(null);
        }
Example #27
0
        protected IOrderedEnumerable <KeyValuePair <long, Queue <Quotes> > > GetQuotes(Dictionary <long, Queue <Quotes> > catalog, string code)
        {
            string path = System.IO.Path.Combine(Application.StartupPath, enumerable, code), date = string.Empty;
            var    search = new List <string>();
            var    exists = new DirectoryInfo(path);
            var    chart  = new Queue <Quotes>(2048);

            try
            {
                using (var db = new GoblinBatDbContext(key))
                    date = db.Datums.Where(o => o.Code.Equals(code)).AsNoTracking().Max(o => o.Date).Substring(0, 8);

                if (exists.Exists)
                {
                    path = System.IO.Path.Combine(Application.StartupPath, enumerable);

                    foreach (var file in Directory.GetFiles(path, "*.res", SearchOption.AllDirectories))
                    {
                        using (var sr = new StreamReader(file))
                            if (sr != null)
                            {
                                while (sr.EndOfStream == false)
                                {
                                    var str = sr.ReadLine().Split(',');

                                    if (str.Length == 3)
                                    {
                                        chart.Enqueue(new Quotes
                                        {
                                            Time   = str[0],
                                            Price  = str[1],
                                            Volume = str[2]
                                        });
                                        continue;
                                    }
                                    chart.Enqueue(new Quotes
                                    {
                                        Time         = str[0],
                                        SellPrice    = str[1],
                                        SellQuantity = str[2],
                                        SellAmount   = str[3],
                                        BuyPrice     = str[4],
                                        BuyQuantity  = str[5],
                                        BuyAmount    = str[6]
                                    });
                                }
                            }
                        var temp = file.Split('\\');
                        search.Add(temp[temp.Length - 1].Split('.')[0]);
                        catalog[new FileInfo(file).CreationTime.Ticks] = new Queue <Quotes>(chart);
                        chart.Clear();
                        GC.Collect();
                    }
                    if (string.IsNullOrEmpty(date) == false && string.Compare(search.Max(), date) < 0)
                    {
                        var storage = new Stack <Quotes>();
                        var max     = search.Max();
                        using (var db = new GoblinBatDbContext(key))
                            foreach (var datum in db.Datums.Where(o => o.Code.Equals(code)).AsNoTracking().OrderByDescending(o => o.Date))
                            {
                                if (string.Compare(datum.Date.Substring(0, 8), max) <= 0)
                                {
                                    break;
                                }

                                if (datum.Price == null && datum.Volume == null)
                                {
                                    storage.Push(new Quotes
                                    {
                                        Time         = datum.Date,
                                        SellPrice    = datum.SellPrice,
                                        SellQuantity = datum.SellQuantity,
                                        SellAmount   = datum.TotalSellAmount,
                                        BuyPrice     = datum.BuyPrice,
                                        BuyQuantity  = datum.BuyQuantity,
                                        BuyAmount    = datum.TotalBuyAmount
                                    });
                                    continue;
                                }
                                storage.Push(new Quotes
                                {
                                    Time   = datum.Date,
                                    Price  = datum.Price,
                                    Volume = datum.Volume
                                });
                            }
                        var file = string.Concat(path, @"\", code, @"\", date, res);
                        using (var sw = new StreamWriter(file, true))
                            while (storage.Count > 0)
                            {
                                var str = storage.Pop();

                                if (str.Price == null && str.Volume == null)
                                {
                                    sw.WriteLine(string.Concat(str.Time, ",", str.SellPrice, ",", str.SellQuantity, ",", str.SellAmount, ",", str.BuyPrice, ",", str.BuyQuantity, ",", str.BuyAmount));
                                    chart.Enqueue(new Quotes
                                    {
                                        Time         = str.Time,
                                        SellPrice    = str.SellPrice,
                                        SellQuantity = str.SellQuantity,
                                        SellAmount   = str.SellAmount,
                                        BuyPrice     = str.BuyPrice,
                                        BuyQuantity  = str.BuyQuantity,
                                        BuyAmount    = str.BuyAmount
                                    });
                                    continue;
                                }
                                sw.WriteLine(string.Concat(str.Time, ",", str.Price, ",", str.Volume));
                                chart.Enqueue(new Quotes
                                {
                                    Time   = str.Time,
                                    Price  = str.Price,
                                    Volume = str.Volume
                                });
                            }
                        catalog[new FileInfo(file).CreationTime.Ticks] = new Queue <Quotes>(chart);
                        chart.Clear();
                        GC.Collect();
                    }
                }
                else
                {
                    exists.Create();
                    using (var db = new GoblinBatDbContext(key))
                        foreach (var tick in db.Datums.Where(o => o.Code.Equals(code)).AsNoTracking().OrderBy(o => o.Date))
                        {
                            if (tick.Price == null && tick.Volume == null)
                            {
                                chart.Enqueue(new Quotes
                                {
                                    Time         = tick.Date,
                                    SellPrice    = tick.SellPrice,
                                    SellQuantity = tick.SellQuantity,
                                    SellAmount   = tick.TotalSellAmount,
                                    BuyPrice     = tick.BuyPrice,
                                    BuyQuantity  = tick.BuyQuantity,
                                    BuyAmount    = tick.TotalBuyAmount
                                });
                                continue;
                            }
                            chart.Enqueue(new Quotes
                            {
                                Time   = tick.Date,
                                Price  = tick.Price,
                                Volume = tick.Volume
                            });
                        }
                    var file = string.Concat(path, @"\", date, res);
                    using (var sw = new StreamWriter(file, true))
                        foreach (var str in chart.OrderBy(o => o.Time))
                        {
                            if (str.Price == null && str.Volume == null)
                            {
                                sw.WriteLine(string.Concat(str.Time, ",", str.SellPrice, ",", str.SellQuantity, ",", str.SellAmount, ",", str.BuyPrice, ",", str.BuyQuantity, ",", str.BuyAmount));

                                continue;
                            }
                            sw.WriteLine(string.Concat(str.Time, ',', str.Price, ',', str.Volume));
                        }
                    catalog[new FileInfo(file).LastWriteTime.Ticks] = new Queue <Quotes>(chart);
                    chart.Clear();
                    GC.Collect();
                }
                return(catalog.OrderBy(o => o.Key));
            }
            catch (Exception ex)
            {
                new ExceptionMessage(ex.StackTrace, code);
            }
            return(null);
        }
Example #28
0
        protected Queue <Quotes> GetQuotes(string code, Queue <Quotes> chart)
        {
            if (code.Length > 6 && code.Substring(5, 3).Equals(futures))
            {
                try
                {
                    if (GetFileExists(new FileInfo(File)))
                    {
                        string temp = string.Empty;
                        using (var sr = new StreamReader(File))
                            if (sr != null)
                            {
                                while (sr.EndOfStream == false)
                                {
                                    var str = sr.ReadLine().Split(',');
                                    temp = str[0];

                                    if (str.Length == 3)
                                    {
                                        chart.Enqueue(new Quotes
                                        {
                                            Time   = str[0],
                                            Price  = str[1],
                                            Volume = str[2]
                                        });
                                        continue;
                                    }
                                    chart.Enqueue(new Quotes
                                    {
                                        Time         = str[0],
                                        SellPrice    = str[1],
                                        SellQuantity = str[2],
                                        SellAmount   = str[3],
                                        BuyPrice     = str[4],
                                        BuyQuantity  = str[5],
                                        BuyAmount    = str[6]
                                    });
                                }
                            }
                        if (temp.Equals(end))
                        {
                            return(chart);
                        }

                        var storage = new Stack <Quotes>();
                        using (var db = new GoblinBatDbContext(key))
                        {
                            var recent = db.Datums.Where(o => o.Code.Contains(code.Substring(0, 3)) && o.Code.Contains(code.Substring(5)) && o.Date.CompareTo(temp) > 0);

                            if (recent.Any())
                            {
                                foreach (var datum in recent.OrderByDescending(o => o.Date).Select(o => new
                                {
                                    o.Date,
                                    o.Price,
                                    o.Volume,
                                    o.SellPrice,
                                    o.SellQuantity,
                                    o.TotalSellAmount,
                                    o.BuyPrice,
                                    o.BuyQuantity,
                                    o.TotalBuyAmount
                                }).AsNoTracking())
                                {
                                    if (datum.Price == null && datum.Volume == null)
                                    {
                                        storage.Push(new Quotes
                                        {
                                            Time         = datum.Date,
                                            SellPrice    = datum.SellPrice,
                                            SellQuantity = datum.SellQuantity,
                                            SellAmount   = datum.TotalSellAmount,
                                            BuyPrice     = datum.BuyPrice,
                                            BuyQuantity  = datum.BuyQuantity,
                                            BuyAmount    = datum.TotalBuyAmount
                                        });
                                        continue;
                                    }
                                    storage.Push(new Quotes
                                    {
                                        Time   = datum.Date,
                                        Price  = datum.Price,
                                        Volume = datum.Volume
                                    });
                                }
                            }
                        }
                        using (var sw = new StreamWriter(File, true))
                            while (storage.Count > 0)
                            {
                                var str = storage.Pop();

                                if (str.Price == null && str.Volume == null)
                                {
                                    sw.WriteLine(string.Concat(str.Time, ",", str.SellPrice, ",", str.SellQuantity, ",", str.SellAmount, ",", str.BuyPrice, ",", str.BuyQuantity, ",", str.BuyAmount));
                                    chart.Enqueue(new Quotes
                                    {
                                        Time         = str.Time,
                                        SellPrice    = str.SellPrice,
                                        SellQuantity = str.SellQuantity,
                                        SellAmount   = str.SellAmount,
                                        BuyPrice     = str.BuyPrice,
                                        BuyQuantity  = str.BuyQuantity,
                                        BuyAmount    = str.BuyAmount
                                    });
                                    continue;
                                }
                                sw.WriteLine(string.Concat(str.Time, ",", str.Price, ",", str.Volume));
                                chart.Enqueue(new Quotes
                                {
                                    Time   = str.Time,
                                    Price  = str.Price,
                                    Volume = str.Volume
                                });
                            }
                        return(chart);
                    }
                    else
                    {
                        using (var db = new GoblinBatDbContext(key))
                            foreach (var temp in db.Datums.Where(o => o.Code.Contains(code.Substring(0, 3))).OrderBy(o => o.Date).Select(o => new
                            {
                                o.Date,
                                o.Price,
                                o.Volume,
                                o.SellPrice,
                                o.SellQuantity,
                                o.TotalSellAmount,
                                o.BuyPrice,
                                o.BuyQuantity,
                                o.TotalBuyAmount
                            }).AsNoTracking())
                            {
                                if (uint.TryParse(temp.Date.Substring(0, 8), out uint date) && date < 20040318)
                                {
                                    continue;
                                }

                                if (temp.Price == null && temp.Volume == null)
                                {
                                    chart.Enqueue(new Quotes
                                    {
                                        Time         = temp.Date,
                                        SellPrice    = temp.SellPrice,
                                        SellQuantity = temp.SellQuantity,
                                        SellAmount   = temp.TotalSellAmount,
                                        BuyPrice     = temp.BuyPrice,
                                        BuyQuantity  = temp.BuyQuantity,
                                        BuyAmount    = temp.TotalBuyAmount
                                    });
                                    continue;
                                }
                                chart.Enqueue(new Quotes
                                {
                                    Time   = temp.Date,
                                    Price  = temp.Price,
                                    Volume = temp.Volume
                                });
                                if (temp.Date.Equals(end))
                                {
                                    return(chart);
                                }
                            }
                    }
                    SetQuotesFile(chart);
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, code);
                }
            }
            return(chart);
        }
Example #29
0
        protected Queue <Chart> GetChart(string code)
        {
            var chart = new Queue <Chart>();

            if (code.Length > 6 && code.Substring(5, 3).Equals(futures))
            {
                try
                {
                    using (var db = new GoblinBatDbContext(key))
                    {
                        var tick = db.Futures.Where(o => o.Code.Contains(code.Substring(0, 3))).Select(o => new
                        {
                            o.Code,
                            o.Date,
                            o.Price,
                            o.Volume
                        }).OrderBy(o => o.Date);
                        var min       = int.Parse(tick.Min(o => o.Date).ToString().Substring(0, 6));
                        var remaining = db.Codes.Where(o => o.Code.Length == 8 && o.Code.Contains(code.Substring(0, 3))).Select(o => new
                        {
                            o.Code,
                            o.Info
                        }).OrderBy(o => o.Info).ToList();

                        foreach (var temp in db.Days.Where(o => o.Code.Length == 8 && o.Code.Contains(code.Substring(0, 3))).Select(o => new
                        {
                            o.Date,
                            o.Price
                        }).OrderBy(o => o.Date))
                        {
                            if (int.Parse(temp.Date.ToString().Substring(2)) < min)
                            {
                                chart.Enqueue(new Chart
                                {
                                    Date   = temp.Date,
                                    Price  = temp.Price,
                                    Volume = 0
                                });
                            }
                        }
                        foreach (var temp in tick)
                        {
                            int index = remaining.FindIndex(o => o.Code.Equals(temp.Code)) - 1;

                            if (index > -1 && int.TryParse(temp.Date.ToString().Substring(0, 6), out int date) && int.TryParse(remaining[index].Info.Substring(2), out int remain))
                            {
                                if (date < remain)
                                {
                                    continue;
                                }

                                else if (date > 200403)
                                {
                                    break;
                                }
                            }
                            chart.Enqueue(new Chart
                            {
                                Date   = temp.Date,
                                Price  = temp.Price,
                                Volume = temp.Volume
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    new ExceptionMessage(ex.StackTrace, code);
                }
            }
            return(chart);
        }
Example #30
0
        protected List <string> RequestCodeList(List <string> list)
        {
            string code = string.Empty;

            try
            {
                using (var db = new GoblinBatDbContext(key))
                    foreach (var temp in db.Codes.Select(o => new
                    {
                        o.Code
                    }))
                    {
                        code = temp.Code;

                        if (db.Codes.Any(o => o.Code.Length < 6))
                        {
                            db.Codes.BulkDelete(db.Codes.Where(o => o.Code.Length < 6), o => o.BatchSize = 100);
                        }

                        if (db.Days.Any(o => o.Code.Equals(temp.Code) && o.Date < 10000000))
                        {
                            db.Days.BulkDelete(db.Days.Where(o => o.Date < 10000000), o => o.BatchSize = 100);

                            if (db.Days.Any(o => o.Code.Length < 6))
                            {
                                db.Days.BulkDelete(db.Days.Where(o => o.Code.Length < 6), o => o.BatchSize = 100);
                            }
                        }
                        if (temp.Code.Equals(q3) && db.Quotes.Any(o => o.Code.Equals(q3)))
                        {
                            db.Quotes.BulkDelete(db.Quotes.Where(o => o.Code.Equals(q3)), o => o.BatchSize = 100);
                        }

                        if (temp.Code.Length == 6 && (db.Days.Any(o => o.Code.Equals(temp.Code)) == false || db.Stocks.Any(o => o.Code.Equals(temp.Code)) == false || int.Parse(db.Days.Where(o => o.Code.Equals(temp.Code)).Max(o => o.Date).ToString().Substring(2)) < int.Parse(db.Stocks.Where(o => o.Code.Equals(code)).Min(o => o.Date).ToString().Substring(0, 6))))
                        {
                            list.Add(temp.Code);

                            if (db.Stocks.Any(o => o.Code.Length < 6))
                            {
                                db.Stocks.BulkDelete(db.Stocks.Where(o => o.Code.Length < 6), o => o.BatchSize = 100);
                            }
                        }
                        else if (temp.Code.Length == 8 && temp.Code.Substring(5, 3).Equals("000") && db.Futures.Any(o => o.Date < 100000000000000))
                        {
                            db.Futures.BulkDelete(db.Futures.Where(o => o.Date < 100000000000000), o => o.BatchSize = 100);

                            if (db.Futures.Any(o => o.Code.Length < 8))
                            {
                                db.Futures.BulkDelete(db.Futures.Where(o => o.Code.Length < 8), o => o.BatchSize = 100);
                            }
                        }
                        else if (temp.Code.Length == 8 && temp.Code.Substring(5, 3).Equals("000") == false && db.Options.Any(o => o.Date < 100000000000000))
                        {
                            db.Options.BulkDelete(db.Options.Where(o => o.Date < 100000000000000), o => o.BatchSize = 100);

                            if (db.Options.Any(o => o.Code.Length < 8))
                            {
                                db.Options.BulkDelete(db.Options.Where(o => o.Code.Length < 8), o => o.BatchSize = 100);
                            }
                        }
                    }
            }
            catch (InvalidOperationException ex)
            {
                new ExceptionMessage(ex.StackTrace, code);
            }
            catch (Exception ex)
            {
                using (var db = new GoblinBatDbContext(key))
                {
                    var stocks = db.Stocks.Where(o => o.Code.Equals(code));

                    if (stocks.Any(o => o.Date < 100000000000000))
                    {
                        db.Stocks.BulkDelete(stocks.Where(o => o.Date < 100000000000000), o => o.BatchSize = 100);
                    }
                }
                new ExceptionMessage(ex.StackTrace, code);
            }
            return(list);
        }