Ejemplo n.º 1
0
        void Proxy_GetStocksCompleted(Task <List <Stock> > t)
        {
            if (t.Status != TaskStatus.RanToCompletion)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    MessageBox.Show(t.Exception.ToString());
                });

                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                IsLoginEnabled = t.Result.Count > 0;

                Stocks.Clear();
                t.Result.ForEach(Stocks.Add);

                if (StocksReceived != null)
                {
                    StocksReceived(this, null);
                }
            });
        }
        async Task ExecuteLoadStocksCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Stocks.Clear();
                var stocks = await StoreDataStore.GetStoreStocksAsync(App.currentStore.StoreId, true);

                foreach (var stock in stocks)
                {
                    Stocks.Add(stock);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 3
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
                return;

            IsBusy = true;

            try
            {
                Stocks.Clear();
                var stocks = await StockDataStore.GetStocksAsync();
                foreach (var stock in stocks)
                {
                    Stocks.Add(stock);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 4
0
        public void Update()
        {
            Stocks.Clear();

            using (IStockController controller = factory.CreateStockController())
            {
                DataControllerMessage <IEnumerable <StockDisplayDTO> > message = controller.GetAll();
                if (message.IsSuccess)
                {
                    foreach (StockDisplayDTO stock in message.Data)
                    {
                        Stocks.Add(stock);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        void OnReceiveSecuritiesAPI(object sender, SendSecuritiesAPI e)
        {
            if (e.Accounts == null && Balance != null)
            {
                BeginInvoke(new Action(async() =>
                {
                    int empty = 0;
                    var param = string.Empty;
                    Retention retention;
                    ISecuritiesAPI <SendSecuritiesAPI> securities = null;
                    ICharts <SendSecuritiesAPI> chart             = null;

                    switch (e.Convey)
                    {
                    case Tuple <int, string, int, int, string> order:
                        if (com is OpenAPI.ConnectAPI openOrder)
                        {
                            openOrder.SendOrder(Info, order);
                        }

                        else if (com is XingAPI.ConnectAPI xingOrder)
                        {
                        }
                        return;

                    case string message:
                        Balance.OnReceiveMessage(message);
                        return;

                    case Tuple <string, string, int, dynamic, dynamic, long, double> balance:
                        SuspendLayout();
                        var strategics = string.Empty;

                        switch (com)
                        {
                        case XingAPI.ConnectAPI x when x.Strategics.Count > 0:
                            securities = x;
                            break;

                        case OpenAPI.ConnectAPI o when o.Strategics.Count > 0:
                            securities = o;
                            break;
                        }
                        if (securities != null && securities.Strategics.Count > 0 && securities.Strategics.Any(o => o.Code.Equals(balance.Item1)))
                        {
                            strategics = securities?.Strategics?.First(x => x.Code.Equals(balance.Item1)).GetType().Name;
                        }

                        Size = new Size(0x3CD, 0x63 + 0x28 + Balance.OnReceiveBalance(balance, strategics));
                        ResumeLayout();
                        return;

                    case long available:
                        Balance.OnReceiveDeposit(available);
                        return;

                    case Tuple <long, long> tuple:
                        Balance.OnReceiveDeposit(tuple);
                        return;

                    case Tuple <int, string> kw:

                        return;

                    case Tuple <string, string, string> code:
                        infoCodes[code.Item1] = new Codes
                        {
                            Code  = code.Item1,
                            Name  = code.Item2,
                            Price = code.Item3
                        };
                        return;

                    case Dictionary <string, Tuple <string, string> > dictionary:
                        var futures = double.MinValue;
                        var index   = 0;

                        foreach (var kv in dictionary)
                        {
                            if (infoCodes.TryGetValue(kv.Key, out Codes info) && double.TryParse(kv.Value.Item2, out double rate) && com is XingAPI.ConnectAPI xing)
                            {
                                info.MarginRate   = rate * 1e-2;
                                info.Name         = kv.Value.Item1;
                                infoCodes[kv.Key] = info;
                                xing.StartProgress(info);

                                if (kv.Key.StartsWith("101") && kv.Key.Length == 8 && kv.Key.EndsWith("000") && double.TryParse(info.Price, out double price))
                                {
                                    futures = price;
                                }
                            }
                        }
                        foreach (var kv in infoCodes)
                        {
                            if (futures > double.MinValue && kv.Key.StartsWith("2") && double.TryParse(kv.Key.Substring(kv.Key.Length - 3), out double oPrice) && oPrice < futures + 0x14 && oPrice > futures - 0x14 && index++ < 0xF && infoCodes.TryGetValue(string.Concat("3", kv.Key.Substring(1)), out Codes codes))
                            {
                                var option = com as XingAPI.ConnectAPI;
                                option?.StartProgress(kv.Value);
                                option?.StartProgress(codes);
                                options.Add(kv.Key);
                                options.Add(string.Concat("3", kv.Key.Substring(1)));
                            }
                        }
                        return;

                    case Tuple <string[], string[], string[], string[]> tuple:
                        for (int i = 0; i < tuple.Item1.Length; i++)
                        {
                            if (int.TryParse(tuple.Item3[i], out int gubun))
                            {
                                var statusCode = await client.PutContext <Codes>(new Codes
                                {
                                    Code       = tuple.Item1[i],
                                    Name       = tuple.Item2[i],
                                    MarginRate = gubun,
                                    Price      = tuple.Item4[i]
                                });
                                SendMessage(statusCode);
                                stocks.Add(tuple.Item1[i]);
                            }
                        }
                        return;

                    case Tuple <string, string, string, string, int> tuple:
                        var statusOptionsCode = await client.PutContext <Codes>(new Codes
                        {
                            Code = tuple.Item1,
                            Name = tuple.Item2,
                            MaturityMarketCap = tuple.Item3,
                            Price             = tuple.Item4,
                            MarginRate        = tuple.Item5
                        });
                        if (tuple.Item1.Length == 6)
                        {
                            stocks.Add(tuple.Item1);
                        }

                        else
                        {
                            options.Add(tuple.Item1);
                        }

                        SendMessage(statusOptionsCode);
                        return;

                    case Tuple <string, Stack <Catalog.OpenAPI.RevisedStockPrice> > tuple:
                        while (tuple.Item2 != null && tuple.Item2.Count > 0)
                        {
                            var info = tuple.Item2.Pop();

                            if (await client.PostContext(info) == 0xC8)
                            {
                                SendMessage(string.Concat(info.Name, " ", info.Date, " ", info.Revise, " ", info.Price, " ", info.Rate));
                            }
                        }
                        var axAPI = com as OpenAPI.ConnectAPI;
                        axAPI.InputValueRqData(opt10081, tuple.Item1).Send -= OnReceiveSecuritiesAPI;

                        if (axAPI.Count < 0x3B7 && DateTime.Now.Minute < 0x31)
                        {
                            retention = await SelectDaysCodeAsync();
                            axAPI.InputValueRqData(string.Concat(instance, opt10081), string.Concat(retention.Code, ';', retention.LastDate)).Send += OnReceiveSecuritiesAPI;
                        }
                        else
                        {
                            Stocks.Clear();
                            Stocks = null;
                        }
                        return;

                    case short error:
                        switch (error)
                        {
                        case -0x6A:
                            Dispose(WindowState);
                            return;
                        }
                        return;

                    case Tuple <byte, byte> tuple:
                        switch (tuple)
                        {
                        case Tuple <byte, byte> tp when tp.Item1 == 1 && tp.Item2 == 0x15 && com is XingAPI.ConnectAPI || com is OpenAPI.ConnectAPI && (tp.Item1 == 0 && tp.Item2 == 8 || tp.Item1 == 3 && tp.Item2 == 9):
                            if (WindowState.Equals(FormWindowState.Minimized))
                            {
                                strip.Items.Find(st, false).First(o => o.Name.Equals(st)).PerformClick();
                            }

                            return;

                        case Tuple <byte, byte> tp when tp.Item2 == 0x29 && tp.Item1 == 1 && com is XingAPI.ConnectAPI || com is OpenAPI.ConnectAPI && tp.Item1 == 8 && tp.Item2 == 0x58:
                            retention = await SelectStocksCodeAsync();
                            chart     = (com as XingAPI.ConnectAPI)?.Stocks;
                            param     = opt10079;
                            break;

                        case Tuple <byte, byte> tp when tp.Item2 == 41 && tp.Item1 == 5 && com is XingAPI.ConnectAPI:
                            retention = await SelectOptionsCodeAsync();
                            chart     = (com as XingAPI.ConnectAPI)?.Options;
                            break;

                        case Tuple <byte, byte> tp when tp.Item1 == 0x65 && tp.Item2 == 0xF && com is OpenAPI.ConnectAPI:
                            retention = await client.GetContext(SelectFuturesCode);
                            param     = opt50028;
                            break;

                        default:
                            GetSettleTheFare();
                            return;
                        }
                        if (WindowState.Equals(FormWindowState.Minimized) == false && ((tuple.Item1 == 0x65 && tuple.Item2 == 0xF || tuple.Item1 == 5 && tuple.Item2 == 0x29) && Info.Name.Equals("선물옵션") || Info.Name.Equals("위탁종합") && (tuple.Item1 == 8 && tuple.Item2 == 0x58 || tuple.Item1 == 1 && tuple.Item2 == 0x29)))
                        {
                            WindowState = FormWindowState.Minimized;
                        }

                        break;

                    case Tuple <string, Stack <string> > charts:
                        switch (charts.Item1.Length)
                        {
                        case 6:
                            if (com is XingAPI.ConnectAPI xs)
                            {
                                chart       = xs?.Stocks;
                                chart.Send -= OnReceiveSecuritiesAPI;
                            }
                            else if (com is OpenAPI.ConnectAPI os)
                            {
                                os.InputValueRqData(opt10079, charts.Item1).Send -= OnReceiveSecuritiesAPI;
                                param = opt10079;
                            }
                            retention = await client.PostContext((await SelectStocksCodeAsync()).Code, new Catalog.Convert().ToStoreInStocks(charts.Item1, charts.Item2));

                            break;

                        case int length when length == 8 && (charts.Item1.StartsWith("101") || charts.Item1.StartsWith("106")):
                            (com as OpenAPI.ConnectAPI).InputValueRqData(opt50028, charts.Item1).Send -= OnReceiveSecuritiesAPI;
                            param = opt50028;

                            if (this.futures.Remove(charts.Item1))
                            {
                                retention = await client.PostContext(SelectFuturesCode, new Catalog.Convert().ToStoreInFutures(charts.Item1, charts.Item2));
                            }

                            break;

                        case int length when length == 8 && (charts.Item1.StartsWith("2") || charts.Item1.StartsWith("3")):
                            switch (com)
                            {
                            case XingAPI.ConnectAPI xo:
                                chart       = xo?.Options;
                                chart.Send -= OnReceiveSecuritiesAPI;
                                break;

                            case OpenAPI.ConnectAPI o:
                                o.InputValueRqData(opt50066, charts.Item1).Send -= OnReceiveSecuritiesAPI;
                                param = opt50066;
                                break;
                            }
                            retention = await client.PostContext((await SelectOptionsCodeAsync()).Code, new Catalog.Convert().ToStoreInOptions(charts.Item1, charts.Item2));

                            if (com is XingAPI.ConnectAPI && (string.IsNullOrEmpty(retention.Code) || retention.Code.Equals(noMatch)))
                            {
                                return;
                            }

                            else if (stocks.Count == 0 && this.futures.Count == 0 && options.Count == 0)
                            {
                                Dispose(WindowState);

                                return;
                            }
                            break;
                        }
                        while (retention.Code == null && retention.LastDate == null)
                        {
                            switch (empty)
                            {
                            case 0:
                                if (com is OpenAPI.ConnectAPI)
                                {
                                    param = opt10079;
                                }

                                else if (com is XingAPI.ConnectAPI xs)
                                {
                                    chart = xs?.Stocks;
                                }

                                if (stocks.Count > 0)
                                {
                                    retention = await SelectStocksCodeAsync();
                                }

                                break;

                            case 1:
                                if (com is OpenAPI.ConnectAPI && this.futures.Count > 0)
                                {
                                    retention = await client.GetContext(SelectFuturesCode);
                                    param     = opt50028;
                                }
                                break;

                            case 2:
                                if (com is OpenAPI.ConnectAPI)
                                {
                                    param = opt50066;
                                }

                                else if (com is XingAPI.ConnectAPI xo)
                                {
                                    chart = xo?.Options;
                                }

                                if (options.Count > 0)
                                {
                                    retention = await SelectOptionsCodeAsync();
                                }

                                break;

                            case 3:
                                Dispose(WindowState);
                                return;
                            }
                            if (stocks.Count == 0 && this.futures.Count == 0 && options.Count == 0)
                            {
                                Dispose(WindowState);
                            }

                            else if (retention.LastDate == null)
                            {
                                empty++;
                            }

                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                    if (string.IsNullOrEmpty(retention.Code) == false && retention.Code.Equals(noMatch) == false)
                    {
                        switch (com)
                        {
                        case OpenAPI.ConnectAPI o when string.IsNullOrEmpty(param) == false:
                            o.InputValueRqData(string.Concat(instance, param), string.Concat(retention.Code, ";", retention.LastDate)).Send += OnReceiveSecuritiesAPI;
                            return;

                        case XingAPI.ConnectAPI _ when chart != null:
                            chart.Send += OnReceiveSecuritiesAPI;
                            chart?.QueryExcute(retention);
                            return;
                        }
                    }
                }));
            }
            else if (e.Convey is FormWindowState state)
            {
                WindowState = state;
                com.Send   -= OnReceiveSecuritiesAPI;
                ((Control)com).Hide();
                Controls.Add(e.Accounts);
                e.Accounts.Dock = DockStyle.Fill;
                e.Accounts.Show();
                Size               = new Size(0x13B, 0x7D);
                Visible            = true;
                ShowIcon           = true;
                notifyIcon.Visible = false;
                WindowState        = FormWindowState.Normal;
                CenterToScreen();

                if (e.Accounts is Accounts accounts)
                {
                    accounts.Send += OnReceiveSecuritiesAPI;
                }
            }
            else if (e.Convey is string str && e.Accounts is Accounts accounts)
            {
                Opacity         = 0;
                FormBorderStyle = FormBorderStyle.FixedSingle;
                WindowState     = FormWindowState.Minimized;
                strategy.Text   = balance;
                accounts.Hide();
                accounts.Send -= OnReceiveSecuritiesAPI;
                var param = str.Split(';');
                Info = com.SetPrivacy(com is OpenAPI.ConnectAPI ? new Privacies {
                    AccountNumber = param[0]
                } : new Privacies
                {
                    AccountNumber   = param[0],
                    AccountPassword = param[1]
                });
                Balance = new Balance(Info);
                Controls.Add(Balance);
                Balance.Dock    = DockStyle.Fill;
                Text            = Info.Nick;
                notifyIcon.Text = Info.Nick;
                Opacity         = 0.79315;
                backgroundWorker.RunWorkerAsync();
                OnReceiveData(MessageBox.Show("This is a Temporary Code.", "Emergency", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2));
            }
        }