Beispiel #1
0
 public static string PriceFormat(string Zqdm)
 {
     if (L2Api.Get精度(Zqdm) == 2)
     {
         return("#0.00");
     }
     else
     {
         return("#0.000");
     }
 }
Beispiel #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     AccountDataSet.价格提示Row 价格提示Row1 = Program.accountDataSet.价格提示.New价格提示Row();
     价格提示Row1.证券代码 = this.comboBox证券代码.Text;
     价格提示Row1.证券名称 = this.comboBox证券代码.Text;
     价格提示Row1.提示类型 = this.comboBox提示类型.SelectedIndex;
     价格提示Row1.提示价格 = Math.Round(this.numericUpDown提示价格.Value, L2Api.Get精度(this.comboBox证券代码.Text), MidpointRounding.AwayFromZero);
     价格提示Row1.提示等级 = this.comboBox提示等级.SelectedIndex;
     价格提示Row1.启用   = this.checkBox启用.Checked;
     Program.accountDataSet.价格提示.Add价格提示Row(价格提示Row1);
 }
Beispiel #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            foreach (AASClient.AASServiceReference.DbDataSet.订单Row 订单Row1 in Program.serverDb.订单)
            {
                decimal XJ, ZS;
                if (TDFData.DataSourceConfig.IsUseTDFData && TDFData.DataCache.GetInstance().MarketNewDict.ContainsKey(订单Row1.证券代码))
                {
                    var marketData = TDFData.DataCache.GetInstance().MarketNewDict[订单Row1.证券代码];
                    XJ = (decimal)marketData.Match / 10000;
                    ZS = (decimal)marketData.PreClose / 10000;

                    //订单Row1.当前价位 = Math.Round((XJ == 0 ? ZS : XJ), L2Api.Get精度(订单Row1.证券代码), MidpointRounding.AwayFromZero);
                    订单Row1.当前价位 = Math.Round((XJ == 0 ? ZS : XJ), 2, MidpointRounding.AwayFromZero);
                    订单Row1.刷新浮动盈亏();
                    //Program.logger.LogRunning("根据TDF行情数据更新,证券代码{0}, 现价{1}, 昨收{2}, 计算后当前价位{3}", 订单Row1.证券代码, XJ, ZS, 订单Row1.当前价位);
                }
                else if (Program.HqDataTable.ContainsKey(订单Row1.证券代码))
                {
                    DataTable DataTable1 = Program.HqDataTable[订单Row1.证券代码];
                    DataRow   DataRow1   = DataTable1.Rows[0];
                    XJ          = decimal.Parse((DataRow1["现价"] as string));
                    ZS          = decimal.Parse((DataRow1["昨收"] as string));
                    订单Row1.当前价位 = Math.Round((XJ == 0 ? ZS : XJ), L2Api.Get精度(订单Row1.证券代码), MidpointRounding.AwayFromZero);
                    订单Row1.刷新浮动盈亏();
                    //Program.logger.LogRunning("根据Tdx行情数据更新,证券代码{0}, 现价{1}, 昨收{2}, 计算后当前价位{3}", 订单Row1.证券代码, XJ, ZS, 订单Row1.当前价位);
                }
                else
                {
                    Program.logger.LogRunning("证券代码{0}, 无行情数据,将不更新当前价位及浮动盈亏数据", 订单Row1.证券代码);
                }
            }



            this.label市值合计.Text = Program.serverDb.订单.Get市值合计().ToString();
            this.label浮动盈亏.Text = Program.serverDb.订单.Get浮动盈亏().ToString();

            decimal 当日委托交易费用 = 0;

            foreach (AASClient.AASServiceReference.JyDataSet.委托Row 委托Row1 in Program.jyDataSet.委托.Where(r => r.成交数量 > 0))
            {
                当日委托交易费用 += 委托Row1.Get交易费用();
            }

            //decimal 当日委托交易费用 = Program.jyDataSet.委托.Get交易费用();
            decimal 毛利 = Program.serverDb.已平仓订单.Get毛利();

            this.label实现盈亏.Text = (毛利 - 当日委托交易费用).ToString();
        }
Beispiel #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Program.HqDataTable.ContainsKey(this.comboBox证券代码.Text))
            {
                if (this.NeedPrice)
                {
                    DataTable DataTable1 = Program.HqDataTable[this.comboBox证券代码.Text];
                    DataRow   DataRow1   = DataTable1.Rows[0];
                    this.numericUpDown提示价格.Value = decimal.Parse((DataRow1["现价"] as string));

                    this.NeedPrice = false;
                }
            }

            this.label证券名称.Text = L2Api.Get名称(this.comboBox证券代码.Text);
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            decimal 委托价格 = Math.Round(this.numericUpDown价格.Value, L2Api.Get精度(this.textBox证券代码.Text), MidpointRounding.AwayFromZero);
            decimal 委托数量 = Math.Round(this.numericUpDown数量.Value, 0, MidpointRounding.AwayFromZero);


            string Ret = Program.AASServiceClient.SendOrder(this.textBox交易员.Text, this.textBox证券代码.Text, this.comboBox交易方向.SelectedIndex, 委托数量, 委托价格);

            string[] Data = Ret.Split('|');
            if (Data[1] != string.Empty)
            {
                MessageBox.Show(Data[1], "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }



            MessageBox.Show("下单成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
Beispiel #6
0
        private static void Refresh订单(AASServiceReference.DbDataSet.订单Row 订单Row1)
        {
            decimal XJ, ZS;

            if (regexStockChina.IsMatch(订单Row1.证券代码))
            {
                if (TDFData.DataSourceConfig.IsUseTDFData && TDFData.DataCache.GetInstance().MarketNewDict.ContainsKey(订单Row1.证券代码))
                {
                    var marketData = TDFData.DataCache.GetInstance().MarketNewDict[订单Row1.证券代码];
                    XJ = (decimal)marketData.Match / 10000;
                    ZS = (decimal)marketData.PreClose / 10000;

                    订单Row1.当前价位 = Math.Round((XJ == 0 ? ZS : XJ), 2, MidpointRounding.AwayFromZero);
                    订单Row1.刷新浮动盈亏();
                }
                else if (Program.HqDataTable.ContainsKey(订单Row1.证券代码))
                {
                    DataTable DataTable1 = Program.HqDataTable[订单Row1.证券代码];
                    DataRow   DataRow1   = DataTable1.Rows[0];
                    XJ          = decimal.Parse((DataRow1["现价"] as string));
                    ZS          = decimal.Parse((DataRow1["昨收"] as string));
                    订单Row1.当前价位 = Math.Round((XJ == 0 ? ZS : XJ), L2Api.Get精度(订单Row1.证券代码), MidpointRounding.AwayFromZero);
                    订单Row1.刷新浮动盈亏();
                }
            }
            else if (regexStockECoin.IsMatch(订单Row1.证券代码))
            {
                if (MarketAdapter.BinanceAdapter.Instance.PriceDict.ContainsKey(订单Row1.证券代码))
                {
                    XJ          = MarketAdapter.BinanceAdapter.Instance.PriceDict[订单Row1.证券代码];
                    订单Row1.当前价位 = XJ;
                    订单Row1.刷新浮动盈亏();
                }
                else
                {
                    MarketAdapter.BinanceAdapter.Instance.Subscribe(订单Row1.证券代码);
                }
            }
        }
Beispiel #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.comboBox证券代码.Text.Length == 6 &&
                char.IsNumber(this.comboBox证券代码.Text[0]) &&
                char.IsNumber(this.comboBox证券代码.Text[1]) &&
                char.IsNumber(this.comboBox证券代码.Text[2]) &&
                char.IsNumber(this.comboBox证券代码.Text[3]) &&
                char.IsNumber(this.comboBox证券代码.Text[4]) &&
                char.IsNumber(this.comboBox证券代码.Text[5]))
            {
                string 证券名称 = L2Api.Get名称(this.comboBox证券代码.Text);
                if (TDFData.DataSourceConfig.IsUseTDFData && TDFData.DataCache.GetInstance().MarketNewDict.ContainsKey(this.comboBox证券代码.Text))
                {
                    证券名称 = Manager.StockCodeManager.GetNameByCode(this.comboBox证券代码.Text);
                }

                if (证券名称 == string.Empty)
                {
                    MessageBox.Show("未取到证券名称");
                    return;
                }

                AASClient.AccountDataSet.价格提示Row 价格提示Row1 = Program.accountDataSet.价格提示.New价格提示Row();
                价格提示Row1.证券代码 = this.comboBox证券代码.Text;
                价格提示Row1.证券名称 = 证券名称;
                价格提示Row1.提示类型 = this.comboBox提示类型.SelectedIndex;
                价格提示Row1.提示价格 = Math.Round(this.numericUpDown提示价格.Value, L2Api.Get精度(this.comboBox证券代码.Text), MidpointRounding.AwayFromZero);
                价格提示Row1.提示等级 = this.comboBox提示等级.SelectedIndex;
                价格提示Row1.启用   = this.checkBox启用.Checked;
                Program.accountDataSet.价格提示.Add价格提示Row(价格提示Row1);
            }
            else
            {
                MessageBox.Show("证券代码错误");
            }
        }
Beispiel #8
0
        private void backgroundWorker行情_DoWork(object sender, DoWorkEventArgs e)
        {
            StringBuilder Result  = new StringBuilder(1024 * 1024);
            StringBuilder ErrInfo = new StringBuilder(256);

            string[] N = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };

            bool IsConnected = false;

            bool[] HasFetchMarketZqmc = { false, false };
            if (!TDFData.DataSourceConfig.IsUseTDXData)
            {
                if (this.backgroundWorker行情.CancellationPending)
                {
                    this.backgroundWorker行情.RunWorkerCompleted -= backgroundWorker行情_RunWorkerCompleted;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
            else
            {
                Program.HqServer = Program.AASServiceClient.Get行情服务器();
                int HqServerIndex = int.Parse(Program.accountDataSet.参数.GetParaValue("行情服务器", "0"));


                while (!this.backgroundWorker行情.CancellationPending)
                {
                    try
                    {
                        if (TDFData.DataSourceConfig.IsUseTDXData)
                        {
                            if (!isOpen)
                            {
                                //Program.logger.LogInfo("1.OpenTdx begin to run");
                                isOpen = L2Api.OpenTdx(ErrInfo);
                                if (!isOpen)
                                {
                                    Program.logger.LogInfo("OpenTdx Fail: " + ErrInfo.ToString());
                                }
                                else
                                {
                                    Program.logger.LogInfo("OpenTdx Success!");
                                }
                            }

                            if (!isOpen)
                            {
                                Program.logger.LogInfo("OpenTdx 失败,将在一秒后重试,错误信息:" + ErrInfo.ToString());
                                Thread.Sleep(1000);
                                continue;
                            }
                            if (!IsConnected)
                            {
                                #region 连接
                                Program.logger.LogRunning("程序正在连接行情服务器...");

                                string   HqServerString = Program.HqServer[HqServerIndex];
                                string[] HqServerInfo   = HqServerString.Split(new char[] { ':' });
                                IsConnected = L2Api.TdxL2Hq_Connect(HqServerInfo[1], int.Parse(HqServerInfo[2]), Result, ErrInfo);

                                if (!IsConnected)
                                {
                                    Program.logger.LogRunning("连接到{0}失败:{1}", HqServerString, ErrInfo);

                                    HqServerIndex = (HqServerIndex + 1) % Program.HqServer.Length;
                                }
                                else
                                {
                                    Program.logger.LogRunning(L2Api.ChangeDataTableToString(L2Api.ChangeDataStringToTable(Result.ToString())));
                                }
                                #endregion
                                Thread.Sleep(5000);
                            }
                            else
                            {
                                #region 获取证券代码
                                List <string> 十档证券代码   = new List <string>();
                                List <string> 逐笔成交证券代码 = new List <string>();

                                List <string> HKCodesMarket = new List <string>();
                                List <string> HKCodesTrans  = new List <string>();

                                List <bool> lstVisible = new List <bool>(hqFormCount);
                                this.Invoke(new Action(() => {
                                    for (int i = 0; i < this.hqForm.Length; i++)
                                    {
                                        lstVisible.Add(hqForm[i].Visible);
                                    }
                                }));

                                for (int i = 0; i < lstVisible.Count; i++)
                                {
                                    if (lstVisible[i])
                                    {
                                        string zqdm1 = Program.accountDataSet.参数.GetParaValue("证券代码" + i.ToString(), "000001");
                                        if (zqdm1.Length == 6)
                                        {
                                            if (!十档证券代码.Contains(zqdm1))
                                            {
                                                十档证券代码.Add(zqdm1);
                                            }
                                            if (!逐笔成交证券代码.Contains(zqdm1))
                                            {
                                                逐笔成交证券代码.Add(zqdm1);
                                            }
                                        }
                                        else if (zqdm1.Length == 5)
                                        {
                                            if (!HKCodesMarket.Contains(zqdm1))
                                            {
                                                HKCodesMarket.Add(zqdm1);
                                            }
                                            if (!HKCodesTrans.Contains(zqdm1))
                                            {
                                                HKCodesTrans.Add(zqdm1);
                                            }
                                        }
                                    }
                                }

                                if (this.backgroundWorker行情.CancellationPending)
                                {
                                    this.backgroundWorker行情.RunWorkerCompleted -= backgroundWorker行情_RunWorkerCompleted;
                                    break;
                                }

                                try
                                {
                                    foreach (AASClient.AccountDataSet.价格提示Row 价格提示Row1 in Program.accountDataSet.价格提示)
                                    {
                                        if (!十档证券代码.Contains(价格提示Row1.证券代码) && 价格提示Row1.启用)
                                        {
                                            十档证券代码.Add(价格提示Row1.证券代码);
                                        }
                                    }

                                    var codes = Program.serverDb.订单.Select(_ => _.证券代码).ToList();
                                    codes.ForEach(_ => {
                                        if (!十档证券代码.Contains(_))
                                        {
                                            十档证券代码.Add(_);
                                        }
                                    });
                                    //if (HKCodesMarket.Count > 0)
                                    //    L2HkApi.Instance.Submit(HKCodesMarket.ToArray());
                                    //if (HKCodesTrans.Count > 0)
                                    //    L2HkApi.Instance.Submit(HKCodesTrans.ToArray());
                                }
                                catch (Exception) { }

                                if (Program.TempZqdm != null)
                                {
                                    if (!十档证券代码.Contains(Program.TempZqdm))
                                    {
                                        十档证券代码.Add(Program.TempZqdm);
                                    }
                                }
                                #endregion


                                #region 工作
                                for (int i = 0; i < 十档证券代码.Count && IsConnected; i++)
                                {
                                    string Zqdm1 = 十档证券代码[i];

                                    byte[]   Market = { L2Api.GetMarket(Zqdm1) };
                                    string[] Zqdm   = { Zqdm1 };
                                    short    Count  = 1;
                                    IsConnected = L2Api.TdxL2Hq_GetSecurityQuotes10(Market, Zqdm, ref Count, Result, ErrInfo);
                                    if (IsConnected && Count == 1)
                                    {
                                        Program.HqDataTable[Zqdm1] = L2Api.ChangeDataStringToTable(Result.ToString());
                                    }
                                    else
                                    {
                                        IsConnected = false;
                                        Program.logger.LogRunning("获取{0}十档报价失败:{1}", Zqdm1, ErrInfo);
                                        break;
                                    }
                                }



                                for (int i = 0; i < 逐笔成交证券代码.Count && IsConnected; i++)
                                {
                                    string Zqdm1 = 逐笔成交证券代码[i];

                                    short Count = 50;
                                    IsConnected = L2Api.TdxL2Hq_GetDetailTransactionData(L2Api.GetMarket(Zqdm1), Zqdm1, 0, ref Count, Result, ErrInfo);
                                    if (IsConnected)
                                    {
                                        Program.TransactionDataTable[Zqdm1] = L2Api.ChangeDataStringToTable(Result.ToString());
                                    }
                                    else
                                    {
                                        Program.logger.LogRunning("获取逐笔成交失败:{0}, 证券代码={1}", ErrInfo, Zqdm1);
                                        break;
                                    }
                                }


                                for (byte Market = 0; Market < 2 && IsConnected; Market++)
                                {
                                    if (!HasFetchMarketZqmc[Market])
                                    {
                                        short Start = 0;
                                        short Count = 1000;

                                        while (IsConnected = L2Api.TdxL2Hq_GetSecurityList(Market, Start, ref Count, Result, ErrInfo))
                                        {
                                            #region 获取所有证券

                                            DataTable DataTable1 = L2Api.ChangeDataStringToTable(Result.ToString());

                                            foreach (DataRow DataRow1 in DataTable1.Rows) //代码	一手股数	名称	保留	价格小数位数	昨收	保留	保留
                                            {
                                                string 证券代码 = DataRow1["代码"] as string;
                                                string 证券名称 = DataRow1["名称"] as string;
                                                int    证券精度 = int.Parse(DataRow1["价格小数位数"] as string);


                                                if ((Market == 0 && (证券代码[0] == '0' || 证券代码[0] == '1' || 证券代码[0] == '3')) ||
                                                    (Market == 1 && (证券代码[0] == '6' || 证券代码[0] == '5')))
                                                {
                                                    Program.证券名称[证券代码] = 证券名称;
                                                    Program.证券精度[证券代码] = 证券精度;
                                                }
                                            }

                                            Start += Count;


                                            if (this.backgroundWorker行情.CancellationPending)
                                            {
                                                this.backgroundWorker行情.RunWorkerCompleted -= backgroundWorker行情_RunWorkerCompleted;
                                                break;
                                            }

                                            if (Count < 1000)
                                            {
                                                HasFetchMarketZqmc[Market] = true;

                                                if (HasFetchMarketZqmc[0] && HasFetchMarketZqmc[1])
                                                {
                                                    this.backgroundWorker行情.ReportProgress(0);
                                                }

                                                break;
                                            }
                                            #endregion
                                        }
                                    }
                                }

                                bool hkConnect = L2MultiApi.Instance.ConnectionID != int.MinValue;
                                for (int i = 0; i < HKCodesMarket.Count; i++)
                                {
                                    string hkcode = HKCodesMarket[i];
                                }
                                #endregion

                                Thread.Sleep(100);
                            }
                        }
                        else
                        {
                            TDFData.DataCache.GetInstance().CheckCodes();
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg   = ex.Message;
                        var    inner = ex.InnerException == null ?  "" : ex.InnerException.Message;
                        Program.logger.LogRunning("行情查询线程出错:{0},\r\n    {1}\r\n    InnerException{2}", msg, ex.StackTrace, inner);
                        Thread.Sleep(20000);
                    }
                }
            }

            if (IsConnected)
            {
                L2Api.TdxL2Hq_Disconnect();
            }
        }
Beispiel #9
0
        private void backgroundWorker报价_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!this.backgroundWorker报价.CancellationPending)
            {
                this.backgroundWorker报价.ReportProgress(0);


                try
                {
                    if (DateTime.Now >= this.LastFetchDay.AddDays(1).AddHours(1))
                    {
                        Program.AASServiceClient.FectchAllTable(Program.Current平台用户.用户名);
                        this.LastFetchDay = DateTime.Today;
                    }



                    成交DataTableChanged 成交DataTableChanged1;
                    if (Program.成交表通知.TryDequeue(out 成交DataTableChanged1))
                    {
                        AASClient.AASServiceReference.JyDataSet.成交DataTable 成交DataTable1 = 成交DataTableChanged1.TableChanged as AASClient.AASServiceReference.JyDataSet.成交DataTable;
                        this.backgroundWorker报价.ReportProgress(4, 成交DataTable1);
                    }


                    委托DataTableChanged 委托DataTableChanged1;
                    if (Program.委托表通知.TryDequeue(out 委托DataTableChanged1))
                    {
                        AASClient.AASServiceReference.JyDataSet.委托DataTable 委托DataTable1 = 委托DataTableChanged1.TableChanged as AASClient.AASServiceReference.JyDataSet.委托DataTable;
                        this.backgroundWorker报价.ReportProgress(5, 委托DataTable1);
                    }

                    平台用户DataTableChanged 平台用户DataTableChanged1;
                    if (Program.平台用户表通知.TryDequeue(out 平台用户DataTableChanged1))
                    {
                        AASClient.AASServiceReference.DbDataSet.平台用户DataTable 平台用户DataTable1 = 平台用户DataTableChanged1.TableChanged as AASClient.AASServiceReference.DbDataSet.平台用户DataTable;
                        this.backgroundWorker报价.ReportProgress(1, 平台用户DataTable1);
                    }

                    额度分配DataTableChanged 额度分配DataTableChanged1;
                    if (Program.额度分配表通知.TryDequeue(out 额度分配DataTableChanged1))
                    {
                        AASClient.AASServiceReference.DbDataSet.额度分配DataTable 额度分配DataTable1 = 额度分配DataTableChanged1.TableChanged as AASClient.AASServiceReference.DbDataSet.额度分配DataTable;
                        this.backgroundWorker报价.ReportProgress(2, 额度分配DataTable1);
                    }

                    订单DataTableChanged 订单DataTableChanged1;
                    if (Program.订单表通知.TryDequeue(out 订单DataTableChanged1))
                    {
                        AASClient.AASServiceReference.DbDataSet.订单DataTable 订单DataTable1 = 订单DataTableChanged1.TableChanged as AASClient.AASServiceReference.DbDataSet.订单DataTable;

                        foreach (AASClient.AASServiceReference.DbDataSet.订单Row 订单Row1 in 订单DataTable1)
                        {
                            if (Program.HqDataTable.ContainsKey(订单Row1.证券代码))
                            {
                                DataTable DataTable1 = Program.HqDataTable[订单Row1.证券代码];
                                DataRow   DataRow1   = DataTable1.Rows[0];
                                decimal   XJ         = decimal.Parse((DataRow1["现价"] as string));
                                decimal   ZS         = decimal.Parse((DataRow1["昨收"] as string));
                                订单Row1.当前价位 = Math.Round((XJ == 0 ? ZS : XJ), L2Api.Get精度(订单Row1.证券代码), MidpointRounding.AwayFromZero);


                                //订单Row1.刷新浮动盈亏(Program.Current平台用户.手续费率);
                                订单Row1.刷新浮动盈亏();
                            }
                        }

                        this.backgroundWorker报价.ReportProgress(6, 订单DataTable1);
                    }

                    已平仓订单DataTableChanged 已平仓订单DataTableChanged1;
                    if (Program.已平仓订单表通知.TryDequeue(out 已平仓订单DataTableChanged1))
                    {
                        AASClient.AASServiceReference.DbDataSet.已平仓订单DataTable 已平仓订单DataTable1 = 已平仓订单DataTableChanged1.TableChanged as AASClient.AASServiceReference.DbDataSet.已平仓订单DataTable;
                        this.backgroundWorker报价.ReportProgress(7, 已平仓订单DataTable1);
                    }



                    Notify Notify1;
                    if (Program.交易通知.TryDequeue(out Notify1))
                    {
                        Program.logger.LogJy(Notify1.操作员, Notify1.证券代码, Notify1.证券名称, Notify1.委托编号, Notify1.买卖方向, Notify1.委托数量, Notify1.委托价格, Notify1.信息);
                    }



                    Thread.Sleep(100);
                }
                catch (Exception ex)
                {
                    Program.logger.LogRunning("报价线程异常:{0} {1}", ex.Message, ex.StackTrace);

                    Thread.Sleep(1000);
                }
            }
        }