public void Can_Add_Minutes()
 {
     Time time = new Time(22, 30);
     time = time.AddMinutes(105);
     Assert.AreEqual(0, time.Hour);
     Assert.AreEqual(15, time.Minute);
 }
 public void AddMinsTest()
 {
     int hour = 8;
     int mins = 9;
     int second = 1;
     var target = new Time(hour, mins, second);
     int min = 55;
     target = target.AddMinutes(min);
     var expect = new TimeSpan(hour, (min + mins), second);
     Assert.AreEqual(expect.Ticks, target.Ticks);
 }
Exemple #3
0
        public void AddMinsTest()
        {
            int hour   = 8;
            int mins   = 9;
            int second = 1;
            var target = new Time(hour, mins, second);
            int min    = 55;

            target = target.AddMinutes(min);
            var expect = new TimeSpan(hour, (min + mins), second);

            Assert.AreEqual(expect.Ticks, target.Ticks);
        }
Exemple #4
0
        public static void RunClock()
        {
            int day = Time.Day;

            Time = Time.AddMinutes(20);
            if (Time.Day != day)
            {
                CountRoom     = 0;
                CountCustomer = 0;
                CountBooking  = 0;
                CountReserv   = 0;
            }
        }
Exemple #5
0
        /// <summary>获取版本信息,检查是否需要更新</summary>
        /// <returns></returns>
        public Boolean Check()
        {
            // 删除备份文件
            DeleteBuckup(DestinationPath);

            var url = Server;

            WriteLog("检查资源包 {0}", url);

            var web   = CreateClient();
            var html  = web.GetHtml(url);
            var links = Link.Parse(html, url, item => item.Name.ToLower().Contains(Name.ToLower()));

            if (links == null || links.Length == 0)
            {
                WriteLog("找不到资源包");
                return(false);
            }

            // 先比较版本
            if (Version > new Version(0, 0))
            {
                var link = links.OrderByDescending(e => e.Version).FirstOrDefault();
                if (link.Version > Version)
                {
                    Link = link;
                    WriteLog("线上版本[{0}]较新 {1}>{2}", link.FullName, link.Version, Version);
                }
                else
                {
                    WriteLog("线上版本[{0}]较旧 {1}<={2}", link.FullName, link.Version, Version);
                }
            }
            // 再比较时间
            else
            {
                var link = links.OrderByDescending(e => e.Time).FirstOrDefault();
                // 只有文件时间大于编译时间才更新,需要考虑文件编译后过一段时间才打包
                if (link.Time > Time.AddMinutes(10))
                {
                    Link = link;
                    WriteLog("线上版本[{0}]较新 {1}>{2}", link.FullName, link.Time, Time);
                }
                else
                {
                    WriteLog("线上版本[{0}]较旧 {1}<={2}", link.FullName, link.Time, Time);
                }
            }

            return(Link != null);
        }
 private static void Tick(object sender, EventArgs e)
 {
     Time = Time.AddMinutes(1);
     if ((Time.Hour >= 7 && Time.Hour < 11) ||
         (Time.Hour == 11 && Time.Minute < 30) ||
         (Time.Hour == 12 && Time.Minute > 30) ||
         (Time.Hour >= 13 && Time.Hour < 16))
     {
         WorkTimeTick?.Invoke();
     }
     else
     {
         FreeTimeTick?.Invoke();
     }
 }
        protected override void unpack(BinaryBitReader reader)
        {
            Time = START.AddDays(reader.ReadUInt(14));
            Time = Time.AddHours(reader.ReadUInt(5));
            Time = Time.AddMinutes(reader.ReadUInt(2) * 15);

            if (reader.ReadBoolean())
            {
                MonthlyBegin = START.AddDays(reader.ReadUInt(14));
                MonthlyNext  = START.AddDays(reader.ReadUInt(14));
            }

            Balance = (int?)reader.ReadIntNullable(15);
            Units   = (int?)reader.ReadIntNullable(15);
            Usages  = (int?)reader.ReadIntNullable(15);
        }
        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">TradeBars IDictionary object with your stock data</param>
        public void OnData(TradeBars data)
        {
            foreach (string symbol in symbols)
            {
                if (!hma[symbol].IsReady)
                {
                    return;
                }

                Strategy[symbol].AddSerieValue(Time, hma[symbol]);

                isMarketOpen = Market.DateTimeIsOpen(Time) && Market.DateTimeIsOpen(Time.AddMinutes(10));

                if (isMarketOpen)
                {
                    if (Strategy[symbol].IsReady)
                    {
                        // If I have stocks and there's a turn around, then liquidate
                        if (Portfolio[symbol].HoldStock && Strategy[symbol].TurnAround)
                        {
                            Liquidate(symbol);
                        }
                        // If I don't have stocks and there's a signal, then operate.
                        else if (!Portfolio[symbol].HoldStock && Strategy[symbol].OrderSignal != 0)
                        {
                            EntryAndSetStopLoss(symbol, Strategy[symbol].OrderSignal);
                        }
                    }
                }
                // If have stocks and the market is about ot close (15 minutes earlier), liquidate.
                else if (Portfolio[symbol].HoldStock)
                {
                    Liquidate(symbol);
                }
            }
            leverage = Portfolio.TotalHoldingsValue / Portfolio.TotalPortfolioValue;
            if (leverage > maxLeverageValue)
            {
                if (leverage > maxLeverage)
                {
                    Log("Leverage exceeds max allowed leverage");
                    leverageBuffer *= 0.975m;
                }
                maxLeverageValue = leverage;
            }
        }
Exemple #9
0
        private void CallFrm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                if (Duration == 0)
                {
                    if (MessageBox.Show("You Have Specified a 0 Minute Call, Is This Correct?", "Duration", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                }

                //get every call from same service user and on the same date
                IEnumerable <Call> conflictCalls = CallManager.Instance.Calls.Where(c => c.ServiceUser == ServiceUser && c.time.Date == Time.Date);

                //now check for time overlap
                int conflictcount = conflictCalls.Where(c => c.ID != _id && Time.AddMinutes(Duration) > c.time && Time < c.time.AddMinutes(c.duration_mins)).Count();
                if (conflictcount > 0)
                {
                    string conflictString = "This call will overlap with " + conflictcount;

                    conflictString += (conflictcount > 1 ? "other calls" : "another call");

                    //check whther any are marked for deletion.
                    if (conflictCalls.Where(c => c.MarkedForDeletion).Count() > 0)
                    {
                        conflictString += (conflictcount > 1 ? ", some of which are pending for deletion" : " which is pending for deletion");
                    }

                    if (MessageBox.Show(conflictString + ". Is this ok?", "Overlap", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.Yes)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }
        }
Exemple #10
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     Time = Time.AddMinutes(1);
     OnOneMinuteIsOver(Time);
 }
        public void OnData(TradeBars data)
        {
            barCounter++; // just for debug

            #region logging

            comment     = string.Empty;
            tradingDate = this.Time;

            #endregion
            bool        isMarketAboutToClose = !theMarket.DateTimeIsOpen(Time.AddMinutes(10));
            OrderSignal actualOrder          = OrderSignal.doNothing;

            int i = 0;
            foreach (string symbol in Symbols)
            {
                // Operate only if the market is open
                if (theMarket.DateTimeIsOpen(Time))
                {
                    // First check if there are some limit orders not filled yet.
                    if (Transactions.LastOrderId > 0)
                    {
                        CheckLimitOrderStatus(symbol, data);
                    }
                    // Check if the market is about to close and noOvernight is true.
                    if (noOvernight && isMarketAboutToClose)
                    {
                        actualOrder = ClosePositions(symbol);
                    }
                    else
                    {
                        // Now check if there is some signal and execute the strategy.
                        actualOrder = Strategy[symbol].ActualSignal;
                    }
                    ExecuteStrategy(symbol, actualOrder);

                    sharesOwned = Portfolio[symbol].Quantity;
                }

                #region Logging stuff - Filling the data StockLogging

                //"Counter, Time, Close, ITrend, Trigger," +
                //"Momentum, EntryPrice, Signal," +
                //"TriggerCrossOverITrend, TriggerCrossUnderITrend, ExitFromLong, ExitFromShort," +
                //"StateFromStrategy, StateFromPorfolio, Portfolio Value"
                string newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}",
                                               barCounter,
                                               Time,
                                               (data[symbol].Close + data[symbol].Open) / 2,
                                               Strategy[symbol].ITrend.Current.Value,
                                               Strategy[symbol].ITrend.Current.Value + Strategy[symbol].ITrendMomentum.Current.Value,
                                               Strategy[symbol].ITrendMomentum.Current.Value,
                                               (Strategy[symbol].EntryPrice == null) ? 0 : Strategy[symbol].EntryPrice,
                                               actualOrder,
                                               Strategy[symbol].TriggerCrossOverITrend.ToString(),
                                               Strategy[symbol].TriggerCrossUnderITrend.ToString(),
                                               Strategy[symbol].ExitFromLong.ToString(),
                                               Strategy[symbol].ExitFromShort.ToString(),
                                               Strategy[symbol].Position.ToString(),
                                               Portfolio[symbol].Quantity.ToString(),
                                               Portfolio.TotalPortfolioValue
                                               );
                stockLogging[i].AppendLine(newLine);
                i++;

                #endregion Logging stuff - Filling the data StockLogging
                #region "biglog"

                string logmsg =
                    string.Format(
                        "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}" +
                        ",{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32}",
                        symbol,
                        data[symbol].EndTime,
                        barCounter,
                        data[symbol].Volume,
                        data[symbol].Open,
                        data[symbol].High,
                        data[symbol].Low,
                        data[symbol].Close,
                        "",
                        "",
                        data[symbol].EndTime.ToShortTimeString(),
                        data[symbol].Close,
                        Strategy[symbol].ITrend.Current.Value,
                        "",
                        Strategy[symbol].ActualSignal,
                        comment,
                        "",
                        Strategy[symbol].EntryPrice ?? 0,
                        "",
                        Portfolio.TotalUnrealisedProfit,
                        "",
                        sharesOwned,
                        "",
                        Portfolio.TotalPortfolioValue,
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        "",
                        ""
                        );
                mylog.Debug(logmsg);


                //tradeprofit = 0;
                //tradefees = 0;
                //tradenet = 0;
                #endregion
            }
            if (tradingDate.Hour == 16)
            {
                barCounter = 0;
            }
        }
Exemple #12
0
 public static ScheduleLocation[] CreateClaphamWokingSchedule(Time start) => new[]
 {
     (ScheduleLocation)TestScheduleLocations.CreateOrigin(TestStations.ClaphamJunction, start),
     TestScheduleLocations.CreateStop(TestStations.Weybridge, start.AddMinutes(15)),
     TestScheduleLocations.CreateDestination(TestStations.Woking, start.AddMinutes(30))
 };
 private static object GetSampleValue(Type fieldType, bool allowNull, int n)
 {
     if (fieldType == typeof(string))
     {
         return "Sample Data " + n;
     }
     if (allowNull)
     {
         return GetSampleValue(fieldType.GetGenericArguments()[0], false, n);
     }
     if (fieldType == typeof(int))
     {
         return (int)(1 + n);
     }
     if (fieldType == typeof(short))
     {
         return (short)(1 + n);
     }
     if (fieldType == typeof(long))
     {
         return (long)(1 + n);
     }
     if (fieldType == typeof(float))
     {
         return (float)(0.1 + n);
     }
     if (fieldType == typeof(double))
     {
         return (double)(0.1 + n);
     }
     if (fieldType == typeof(bool))
     {
         return (n % 2) == 0;
     }
     if (fieldType == typeof(DateTime))
     {
         var dt = new DateTime(2008, 3, 6, 12, 24, 35);
         return dt.AddDays(n);
     }
     if (fieldType == typeof(Date))
     {
         var d = new Date(2008, 3, 17);
         return d.AddDays(n);
     }
     if (fieldType == typeof(Time))
     {
         var t = new Time(12, 24, 35);
         return t.AddMinutes(n);
     }
     if (fieldType == typeof(Guid))
     {
         return Util.NewGuid();
     }
     if (fieldType == typeof(byte))
     {
         return (byte)n;
     }
     if (fieldType == typeof(sbyte))
     {
         return (sbyte)n;
     }
     if (fieldType == typeof(decimal))
     {
         return (decimal)n;
     }
     if (fieldType == typeof(byte[]))
     {
         return new byte[] { 61, 62, 63 };
     }
     if (fieldType.IsEnum)
     {
         string[] ss = Enum.GetNames(fieldType);
         string name = ss[n % ss.Length];
         return Enum.Parse(fieldType, name);
     }
     return null;
 }
Exemple #14
0
        public void AddMinutes()
        {
            Time t = new Time(2010, 2, 3);
            Time t2 = t.AddMinutes(5);

            (t2.NetTime - t.NetTime).TotalMinutes.Should().Be(5);
        }
Exemple #15
0
                 List <WorkerStats> WorkersStats) GetStats()
        {
            try
            {
                var sssss = $"https://{CoinName}.2miners.com/api/accounts/{Wallet}";

                var request = System.Net.WebRequest.
                              Create(sssss);
                var    response = request.GetResponse();
                string req;
                using (var stream = response.GetResponseStream())
                {
                    using (var reader = new System.IO.StreamReader(stream))
                    {
                        req = reader.ReadToEnd();
                    }
                }

                var xxx = JsonConvert.DeserializeObject <Root>(req);
                xxx.WorkersRoot = GetWorkers(req);

                if (xxx.code == 999)
                {
                    var h = Math.Round((DateTime.Now - DateTime.UtcNow).TotalHours);

                    var Workers = xxx.WorkersRoot.Workers.Select(w => new WorkerStats
                    {
                        Name      = w.Name,
                        Rep       = GetValOrNull(ReportedVisible, w.rhr),
                        Curr      = w.hr,
                        ShInvalid = w.sharesInvalid,
                        ShValid   = w.sharesValid,
                        ShStale   = w.sharesStale,
                        LastSeen  = new DateTime(1970, 1, 1).AddSeconds(w.lastBeat).AddHours(h)
                    }).ToList();

                    var Current = new CurrStats
                    {
                        Curr      = xxx.currentHashrate,
                        Rep       = GetValOrNull(ReportedVisible, xxx.WorkersRoot.Workers.Sum(w => w.rhr)),
                        ShInvalid = xxx.sharesInvalid,
                        ShValid   = xxx.sharesValid,
                        ShStale   = xxx.sharesStale,
                        LastSeen  = new DateTime(1970, 1, 1).
                                    AddMilliseconds(xxx.updatedAt).AddHours(h),
                        Unpaid        = Convert.ToDouble(xxx.stats.balance) / Divider,
                        ActiveWorkers = xxx.workersOnline,
                        MinPayout     = Convert.ToDouble(xxx.config.minPayout) / Divider
                    };
                    xxx.rewards.Reverse();
                    var His = xxx.rewards.Select(st => new MiningStats
                    {
                        Curr = st.reward,
                        Rep  = null,
                        Time = new DateTime(1970, 1, 1).
                               AddSeconds(st.timestamp).AddHours(h)
                    }).ToList();

                    DateTime Time;

                    var ttt = His.Select(h => h.Time).ToList();

                    if (((His[0].Time.Minute / 10) + 1) * 10 > 55)
                    {
                        var nt = His[0].Time.AddMinutes(10);
                        Time = new DateTime(nt.Year, nt.Month, nt.Day, nt.Hour, 0, 0);
                    }
                    else
                    {
                        Time = new DateTime(His[0].Time.Year, His[0].Time.Month, His[0].Time.Day, His[0].Time.Hour, ((His[0].Time.Minute / 10) + 1) * 10, 0);
                    }
                    double Curr = 0;
                    var    Hist = new List <MiningStats>();
                    foreach (var hs in His)
                    {
                        if ((Time - hs.Time).TotalMinutes > 0)
                        {
                            Curr += hs.Curr;
                        }
                        else
                        {
                            Hist.Add(new MiningStats
                            {
                                Time = Time,
                                Curr = Curr
                            });
                            Curr = hs.Curr;
                            Time = Time.AddMinutes(10);
                        }
                    }
                    Hist.Add(new MiningStats
                    {
                        Time = Time,
                        Curr = Curr
                    });

                    var n = DateTime.Now.AddDays(-1);
                    Hist = Hist.Where(h => h.Time > n).ToList();
                    var sdt = Hist[0].Time;
                    for (int i = 1; i < Hist.Count; i++)
                    {
                        while (Hist[i].Time != sdt.AddMinutes(10))
                        {
                            Hist.Insert(i, new MiningStats
                            {
                                Curr = 0,
                                Rep  = 0,
                                Time = Hist[i].Time.AddMinutes(-10),
                            });
                        }
                        sdt = sdt.AddMinutes(10);
                    }

                    return(xxx.message, Current, Hist, Workers);
                }
                else
                {
                    return(xxx.message, null, null, null);
                }
            }
            catch (Exception e) { return(e.Message, null, null, null); }
        }
Exemple #16
0
 private static object GetSampleValue(Type fieldType, bool allowNull, int n)
 {
     if (fieldType == typeof(string))
     {
         return("Sample Data " + n);
     }
     if (allowNull)
     {
         return(GetSampleValue(fieldType.GetGenericArguments()[0], false, n));
     }
     if (fieldType == typeof(int))
     {
         return((int)(1 + n));
     }
     if (fieldType == typeof(short))
     {
         return((short)(1 + n));
     }
     if (fieldType == typeof(long))
     {
         return((long)(1 + n));
     }
     if (fieldType == typeof(float))
     {
         return((float)(0.1 + n));
     }
     if (fieldType == typeof(double))
     {
         return((double)(0.1 + n));
     }
     if (fieldType == typeof(bool))
     {
         return((n % 2) == 0);
     }
     if (fieldType == typeof(DateTime))
     {
         var dt = new DateTime(2008, 3, 6, 12, 24, 35);
         return(dt.AddDays(n));
     }
     if (fieldType == typeof(Date))
     {
         var d = new Date(2008, 3, 17);
         return(d.AddDays(n));
     }
     if (fieldType == typeof(Time))
     {
         var t = new Time(12, 24, 35);
         return(t.AddMinutes(n));
     }
     if (fieldType == typeof(Guid))
     {
         return(Util.NewGuid());
     }
     if (fieldType == typeof(byte))
     {
         return((byte)n);
     }
     if (fieldType == typeof(sbyte))
     {
         return((sbyte)n);
     }
     if (fieldType == typeof(decimal))
     {
         return((decimal)n);
     }
     if (fieldType == typeof(byte[]))
     {
         return(new byte[] { 61, 62, 63 });
     }
     if (fieldType.IsEnum)
     {
         string[] ss   = Enum.GetNames(fieldType);
         string   name = ss[n % ss.Length];
         return(Enum.Parse(fieldType, name));
     }
     return(null);
 }