Ejemplo n.º 1
0
        static async Task Main()
        {
            MainApp.log_info("Start...");

            // Load setting
            MainApp.log_info("Load setting...");
            Load_setting();
            g_setting.Save();

            // Calculate the time differences between Local and Australia
            var      cst_tz    = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
            var      local_tz  = TimeZoneInfo.Local;
            var      now       = DateTimeOffset.UtcNow;
            TimeSpan cst_off   = cst_tz.GetUtcOffset(now);
            TimeSpan local_off = local_tz.GetUtcOffset(now);

            g_time_diff = local_off - cst_off;

            // Global exception
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += Application_ThreadException;

            MainApp.log_info("Log in...");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            g_api       = new API_Con(MainApp.g_setting.api_endpoint);
            g_api_login = await connect_db();

            m_main_frm = new MainFrm();
            Application.Run(m_main_frm);
        }
Ejemplo n.º 2
0
        private async void MainFrm_Load(object sender, EventArgs e)
        {
            grid_note.DataSource = bind_main;
            grid_note.DoubleBuffered(true);

            MainApp.log_info("Program started.");
            MainApp.g_working = true;
        }
Ejemplo n.º 3
0
 public static async Task <bool> connect_db()
 {
     if (!await g_api.login())
     {
         MessageBox.Show("Failed to connect to backend service.");
         Environment.Exit(0);
     }
     MainApp.log_info("Backend API connected.");
     return(true);
 }
Ejemplo n.º 4
0
        async void load_events()
        {
            m_cur_date   = DateTime.Now;
            m_event_list = await m_dyn.get_event_schedule(DateTime.Now.AddDays(MainApp.DEBUG ? 1 : 0));

            if (m_event_list.Count == 0)
            {
                MainApp.log_info("No events are left today. No notification will be triggered this session.");
            }
            else
            {
                MainApp.log_info($"{m_event_list.Count} events loaded from Dynamic Odds API.");
            }
            m_event_status.Clear();
            foreach (var eve in m_event_list)
            {
                m_event_status.Add(eve, 0);
            }
        }
Ejemplo n.º 5
0
        void init_dynamic()
        {
            panel_wait.BringToFront();
            new System.Threading.Tasks.Task(async() =>
            {
                try
                {
                    bool _login = await m_dyn.login();
                    if (_login == false)
                    {
                        MainApp.log_info("Dynamic Odds API connection failed.");
                        if (MessageBox.Show("Failed to log in to Dynamic Odds XML feed service.\nDo you want to continue without live alert?", "OddAlert", MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            Close();
                            return;
                        }
                    }

                    play_sound();
                    MainApp.log_info("Dynamic Odds API connected.");
                    m_agency_lookup = await m_dyn.get_agencies();

                    load_events();

                    this.InvokeOnUiThreadIfRequired(() =>
                    {
                        panel_wait.SendToBack();
                    });

                    m_timer_alert.Start();
                }
                catch (Exception ex)
                {
                    MainApp.log_error("Exception in init_dynamic\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }).Start();
        }
Ejemplo n.º 6
0
        private async void M_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                {
                }
                if (m_dyn.Ready())
                {
                    if (m_cur_date.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
                    {
                        load_events();
                    }

                    foreach (var eve in m_event_list)
                    {
                        if (m_event_status[eve] == 0)
                        {
                            var au_now = MainApp.AuNow();
                            if (eve.StartTime < au_now)
                            {
                                m_event_status[eve] = 2; // ended
                                continue;
                            }

                            m_event_status[eve] = 1; // busy
                            new Thread(async() =>
                            {
                                var odd_view = await m_dyn.get_runner_odds(eve.ID);
                                // Check delta and raise the alert
                                if (eve.OddView != null && odd_view != null)
                                {
                                    MainApp.log_info($"Odds for {eve.State} - {eve.Venue} - {eve.EventNo} updated.");
                                    foreach (var runner in odd_view.RName)
                                    {
                                        foreach (var bookie in m_monitor_bookies)
                                        {
                                            decimal pre_price = eve.OddView.get_odd_for_bookie(bookie, runner);
                                            decimal cur_price = odd_view.get_odd_for_bookie(bookie, runner);

                                            if (pre_price < 2M || cur_price == 0)
                                            {
                                                continue;
                                            }

                                            int pre_point = PriceTable.get_point(pre_price);
                                            int cur_point = PriceTable.get_point(cur_price);
                                            int delta     = cur_point - pre_point;
                                            if (delta <= -MainApp.g_setting.alert_level && -delta <= 13)
                                            {
                                                play_sound();
                                                MainApp.log_info("Notification triggered.");

                                                int idx = odd_view.RName.IndexOf(runner);
                                                // get top prices
                                                List <KeyValuePair <string, decimal> > odd_dict = new List <KeyValuePair <string, decimal> >();
                                                foreach (var one_bookie in odd_view.Odds)
                                                {
                                                    odd_dict.Add(new KeyValuePair <string, decimal>(one_bookie.Bookie, one_bookie.Odds[idx]));
                                                }
                                                odd_dict.Sort((pair1, pair2) => - pair1.Value.CompareTo(pair2.Value));

                                                // new notification
                                                Notification note    = new Notification();
                                                note.event_id        = eve.ID;
                                                note.datetime        = au_now.ToString("yyyy-MM-dd hh:mm:ss");
                                                note.time_to_jump    = eve.StartTime.Subtract(au_now).ToString("h'h 'm'm 's's'");
                                                note.degree          = delta;
                                                note.state           = eve.State;
                                                note.venue           = eve.Venue;
                                                note.race_number     = int.Parse(eve.EventNo);
                                                note.horse_number    = int.Parse(odd_view.RNo[idx]);
                                                note.horse_name      = runner;
                                                note.previous_price  = pre_price;
                                                note.current_price   = cur_price;
                                                note.bookie          = bookie;
                                                note.suggested_stake = suggest_stake(pre_price, delta);
                                                note.max_profit      = note.suggested_stake * (pre_price - 1);
                                                note.top_price_1     = $"${odd_dict[0].Value} {odd_dict[0].Key}";
                                                note.top_price_2     = $"${odd_dict[1].Value} {odd_dict[1].Key}";
                                                note.top_price_3     = $"${odd_dict[2].Value} {odd_dict[2].Key}";
                                                note.top_price_4     = $"${odd_dict[3].Value} {odd_dict[3].Key}";
                                                note.status          = 0; // pending
                                                note.result          = "-";
                                                add_note_to_db(note);
                                                refresh_in_delay = true;
                                                //refresh_grid();
                                            }
                                        }
                                    }
                                }

                                eve.OddView         = odd_view;
                                m_event_status[eve] = 0; // idle
                            }).Start();
                        }
                    }

                    foreach (var pair in m_event_status)
                    {
                        if (pair.Value == 2)
                        {
                            m_event_list.Remove(pair.Key);
                        }
                    }

                    if (m_event_list.Count == 0)
                    {
                        MainApp.log_info("No active events are left today. " + m_cur_date.ToString("yyyy-MM-dd"));
                    }
                }

                if (MainApp.g_working)
                {
                    img_status.BackgroundImage = Properties.Resources.Circle_ON;
                }
                else
                {
                    img_status.BackgroundImage = Properties.Resources.Circle_OFF;
                }
            }
            catch (Exception ex)
            {
                MainApp.log_error("Exception in timer\n" + ex.Message + "\n" + ex.StackTrace);
            }
            m_timer_alert.Start();
        }