Ejemplo n.º 1
0
 public Arbitrage(Trade pTrade, Quote pQuote)
 {
     _t = pTrade;
     _q = pQuote;
     this.Load += UserControl_Load;
     InitializeComponent();
 }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            FormLogin fLogin = new FormLogin();
            if (fLogin.ShowDialog(this) == DialogResult.Cancel)
            {
                this.Close();
                return;
            }

            _t = fLogin.trade;
            _q = fLogin.quote;
            _t.OnRtnCancel += trade_OnRtnCancel;
            _t.OnRtnError += trade_OnRtnError;
            _t.OnRtnExchangeStatus += trade_OnRtnExchangeStatus;
            _t.OnRtnNotice += trade_OnRtnNotice;
            _t.OnRtnOrder += trade_OnRtnOrder;
            _t.OnRtnTrade += trade_OnRtnTrade;
            if (_q != null)
                _q.OnRtnTick += quote_OnRtnTick;

            SetConfig("server", fLogin.Server);
            SetConfig("investor", fLogin.trade.Investor);

            fLogin.Close();

            this.Text += string.Format("({0}@{1})", GetConfig("investor"), GetConfig("server"));

            //初始化表格
            InitView(this.kryptonDataGridViewTick, this.kryptonDataGridViewOrder, this.kryptonDataGridViewTrade, this.kryptonDataGridViewPosition);
            this.kryptonDataGridViewOrder.CellDoubleClick += kryptonDataGridViewOrder_CellDoubleClick;
            this.kryptonDataGridViewPosition.CellDoubleClick += kryptonDataGridViewPosition_CellDoubleClick;
            this.kryptonDataGridViewOrder.CellFormatting += kryptonDataGridView_CellFormatting;
            this.kryptonDataGridViewTrade.CellFormatting += kryptonDataGridView_CellFormatting;
            this.kryptonDataGridViewPosition.CellFormatting += kryptonDataGridView_CellFormatting;
            this.kryptonComboBoxInstrument.SelectedIndexChanged += kryptonComboBox1_SelectedIndexChanged;
            this.kryptonComboBoxInstrument.Enter += kryptonComboBoxInstrument_Enter;
            this.kryptonComboBoxInstrument.DropDown += kryptonComboBoxInstrument_Enter;
            this.kryptonLabel5.Click += kryptonLabel5_Click;
            this.kryptonButtonCancel.Click += kryptonButtonCancel_Click;
            this.kryptonButtonFAK.Click += kryptonButtonOrder_Click;
            this.kryptonButtonFOK.Click += kryptonButtonOrder_Click;
            this.kryptonButtonLimit.Click += kryptonButtonOrder_Click;
            this.kryptonButtonMarket.Click += kryptonButtonOrder_Click;

            //样式
            foreach (var v in Enum.GetNames(typeof(PaletteModeManager)))
            {
                var item = this.ToolStripMenuItemStyle.DropDownItems.Add(v);
                item.Click += (obj, arg) =>
                {
                    RecalcNonClient();
                    this.kryptonManager1.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), ((ToolStripDropDownItem)obj).Text);
                };
            }

            //创建确认选项
            for (int i = 0; i < _confirmNames.Length; ++i)
            {
                ToolStripMenuItem item = new ToolStripMenuItem
                {
                    Name = _confirmNames[i],
                    Text = _confirmTexts[i],
                    Checked = true,
                    CheckOnClick = true,
                };
                this.ToolStripMenuItemOption.DropDownItems.Add(item);
            }
            this.ToolStripMenuItemOption.DropDownItems.Add("-");//增加隔断

            //过滤显示
            _dtPosition.DefaultView.RowFilter = "Position > 0";

            //加载插件
            if (Directory.Exists(Application.StartupPath + "\\plugin"))
                foreach (var file in new DirectoryInfo(Application.StartupPath + "\\plugin").GetFiles("*.dll"))
                {
                    Assembly ass = Assembly.LoadFile(file.FullName);
                    //加载hf_plat报错:增加对hf_plat_core的引用
                    var t = ass.GetTypes().FirstOrDefault(n => n.BaseType == typeof(UserControl));
                    if (t != null && !t.FullName.StartsWith("Telerik."))
                    {
                        this.tabControl1.TabPages.Add(t.FullName, t.Name);
                        TabPage tp = this.tabControl1.TabPages[t.FullName];
                        var uc = (UserControl)Activator.CreateInstance(t, _t, _q);
                        uc.Dock = DockStyle.Fill;
                        tp.Controls.Add(uc);
                    }
                }
            if (File.Exists(Application.StartupPath + "\\hf_plat_terminal.dll"))
                //foreach (var file in new DirectoryInfo(Application.StartupPath + "\\strategy").GetFiles("*.dll"))
                {
                    Assembly ass = Assembly.LoadFile(Application.StartupPath + "\\hf_plat_terminal.dll");
                    //加载hf_plat报错:增加对hf_plat_core的引用
                    var t = ass.GetTypes().FirstOrDefault(n => n.BaseType == typeof(UserControl));
                    if (t != null)
                    {
                        this.tabControl1.TabPages.Add(t.FullName, t.Name);
                        TabPage tp = this.tabControl1.TabPages[t.FullName];
                        var uc = (UserControl)Activator.CreateInstance(t, _t, _q);
                        uc.Dock = DockStyle.Fill;
                        tp.Controls.Add(uc);
                    }
                }
            //if (File.Exists(Application.StartupPath + "\\strategy\\hf_plat_core.dll"))
            //{
            //	Assembly ass = Assembly.LoadFile(Application.StartupPath + "\\strategy\\hf_plat_core.dll");
            //	var t = ass.GetType("hf_plat_core.Plat");
            //	var uc = (UserControl)Activator.CreateInstance(t, _t, _q);
            //	this.tabControl1.TabPages.Add(t.FullName, t.Name);
            //	TabPage tp = this.tabControl1.TabPages[t.FullName];
            //	uc.Dock = DockStyle.Fill;
            //	tp.Controls.Add(uc);
            //}

            _timer.Tick += _timer_Tick;
            _timer.Start();

            //恢复配置
            if (!string.IsNullOrEmpty(GetConfig("WindowState")))
                this.WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), GetConfig("WindowState"));
            if (this.WindowState != FormWindowState.Maximized)
            {
                if (!string.IsNullOrEmpty(GetConfig("Left")))
                    this.Left = int.Parse(GetConfig("Left"));
                if (!string.IsNullOrEmpty(GetConfig("Top")))
                    this.Top = int.Parse(GetConfig("Top"));
                if (!string.IsNullOrEmpty(GetConfig("Height")))
                    this.Height = int.Parse(GetConfig("Height"));
                if (!string.IsNullOrEmpty(GetConfig("Width")))
                    this.Width = int.Parse(GetConfig("Width"));
            }
            if (!string.IsNullOrEmpty(GetConfig("GlobalPaletteMode")))
                this.kryptonManager1.GlobalPaletteMode = (PaletteModeManager)Enum.Parse(typeof(PaletteModeManager), GetConfig("GlobalPaletteMode"));	//更新样式

            //选项
            foreach (var v in _confirmNames)
            {
                ((ToolStripMenuItem)this.ToolStripMenuItemOption.DropDownItems[v]).Checked = string.IsNullOrEmpty(GetConfig(v)) || bool.Parse(GetConfig(v));
            }
        }
Ejemplo n.º 3
0
        private void kryptonButtonLogin_Click(object sender, EventArgs e)
        {
            ShowMsg("登录中...");
            string front = (string)_dt.Rows.Find(this.kryptonComboBoxServer.Text)[1];
            string[] fs = front.Split('|');

            if (!string.IsNullOrEmpty(fs[3]))
            {
                quote = new Quote(string.Format("{0}_Quote_proxy.dll", fs[0]))
                {
                    Broker = fs[1],
                    Server = fs[3],
                    Investor = this.kryptonTextBoxInvestor.Text,
                    Password = this.kryptonTextBoxPassword.Text,
                };
                quote.OnFrontConnected += quote_OnFrontConnected;
                quote.OnRspUserLogin += quote_OnRspUserLogin;
            }

            trade = new Trade(string.Format("{0}_Trade_proxy.dll", fs[0]))
            {
                Server = fs[2],
                Investor = this.kryptonTextBoxInvestor.Text,
                Password = this.kryptonTextBoxPassword.Text,
                Broker = fs[1],
            };
            trade.OnFrontConnected += trade_OnFrontConnected;
            trade.OnRspUserLogin += trade_OnRspUserLogin;
            trade.OnRtnExchangeStatus += trade_OnRtnExchangeStatus;
            trade.ReqConnect();
        }
Ejemplo n.º 4
0
 void trade_OnRspUserLogin(object sender, Trade2015.IntEventArgs e)
 {
     if (e.Value == 0)
     {
         ShowMsg("登录成功");
         Thread.Sleep(1500);
         //交易登录成功后,登录行情
         if (quote == null)
             LoginSuccess();
         else
             quote.ReqConnect();
     }
     else
     {
         ShowMsg("登录错误");
         trade.ReqUserLogout();
         trade = null;
         quote = null;
     }
 }
Ejemplo n.º 5
0
		//输入:q1ctp /t1ctp /q2xspeed /t2speed
		private static void Main(string[] args)
		{
			Trade t;
			Quote q;
		R:
			Console.WriteLine("选择接口:\t1-CTP  2-xSpeed  3-Femas  4-股指仿真  5-外汇仿真  6-郑商商品期权仿真");
			char c = Console.ReadKey(true).KeyChar;

			switch (c)
			{
				case '1': //CTP
					t = new Trade("ctp_trade_proxy.dll")
					{
						Server = "tcp://101.95.8.178:51205", 
						Broker = "4040",
					};
					q = new Quote("ctp_quote_proxy.dll")
					{
						Server = "tcp://101.95.8.178:51213",
						Broker = "4040",
					};
					//t = new Trade("ctp_trade_proxy.dll")
					//{
					//	Server = "tcp://211.95.40.130:51205", 
					//	Broker = "1017",
					//};
					//q = new Quote("ctp_quote_proxy.dll")
					//{
					//	Server = "tcp://211.95.40.130:51213",
					//	Broker = "1017",
					//};
					break;
				case '2': //xSpeed
					t = new Trade("xSpeed_trade_proxy.dll")
					{
						Server = "tcp://203.187.171.250:10910",
						Broker = "0001",
					};
					q = new Quote("xSpeed_quote_proxy.dll")
					{
						Server = "tcp://203.187.171.250:10915",
						Broker = "0001",
					};
					break;
				case '3': //femas
					t = new Trade("femas_trade_proxy.dll")
					{
						Server = "tcp://116.228.53.149:6666",
						Broker = "0001",
					};
					q = new Quote("femas_quote_proxy.dll")
					{
						Server = "tcp://116.228.53.149:6888",
						Broker = "0001",
					};
					break;
				case '4': //CTP
					t = new Trade("ctp_trade_proxy.dll")
					{
						Server = "tcp://124.207.185.88:41205",
						Broker = "1010",
					};
					q = new Quote("ctp_quote_proxy.dll")
					{
						Server = "tcp://124.207.185.88:41213",
						Broker = "1010",
					};
					break;
				case '5': //CTP
					t = new Trade("femas_trade_proxy.dll")
					{
						Server = "tcp://117.184.207.111:7036",
						Broker = "2713",
					};
					q = new Quote("femas_quote_proxy.dll")
					{
						Server = "tcp://117.184.207.111:7230",
						Broker = "2713",
					};
					break;
				case '6': //CTP
					t = new Trade("ctp_trade_proxy.dll")
					{
						Server = "tcp://106.39.36.72:51205",
						Broker = "1010",
					};
					q = new Quote("ctp_quote_proxy.dll")
					{
						Server = "tcp://106.39.36.72:51213",
						Broker = "1010",
					};
					break;
				default:
					Console.WriteLine("请重新选择");
					goto R;
			}
			Console.WriteLine("请输入帐号:");
			t.Investor = q.Investor = Console.ReadLine();
			Console.WriteLine("请输入密码:");
			t.Password = q.Password = Console.ReadLine();

			q.OnFrontConnected += (sender, e) =>
			{
				Console.WriteLine("OnFrontConnected");
				q.ReqUserLogin();
			};
			q.OnRspUserLogin += (sender, e) => Console.WriteLine("OnRspUserLogin:{0}", e.Value);
			q.OnRspUserLogout += (sender, e) => Console.WriteLine("OnRspUserLogout:{0}", e.Value);
			q.OnRtnError += (sender, e) => Console.WriteLine("OnRtnError:{0}=>{1}", e.ErrorID, e.ErrorMsg);
			//q.OnRtnTick += (sender, e) => Console.WriteLine("OnRtnTick:{0}", e.Tick);


			t.OnFrontConnected += (sender, e) => t.ReqUserLogin();
			t.OnRspUserLogin += (sender, e) =>
			{
				Console.WriteLine("OnRspUserLogin:{0}", e.Value);
				if (e.Value == 0)
					q.ReqConnect();
			};
			t.OnRspUserLogout += (sender, e) => Console.WriteLine("OnRspUserLogout:{0}", e.Value);
			t.OnRtnCancel += (sender, e) => Console.WriteLine("OnRtnCancel:{0}", e.Value.OrderID);
			t.OnRtnError += (sender, e) => Console.WriteLine("OnRtnError:{0}=>{1}", e.ErrorID, e.ErrorMsg);
			t.OnRtnExchangeStatus += (sender, e) => Console.WriteLine("OnRtnExchangeStatus:{0}=>{1}", e.Exchange, e.Status);
			t.OnRtnNotice += (sender, e) => Console.WriteLine("OnRtnNotice:{0}", e.Value);
			t.OnRtnOrder += (sender, e) =>
			{
				Console.WriteLine("OnRtnOrder:{0}", e.Value);
				_orderId = e.Value.OrderID;
			};
			t.OnRtnTrade += (sender, e) => Console.WriteLine("OnRtnTrade:{0}", e.Value.TradeID);

			t.ReqConnect();
			Thread.Sleep(3000);

			if (!t.IsLogin)
				goto R;
			Console.WriteLine(t.DicInstrumentField.Aggregate("\r\n合约", (cur, n) => cur + "\t" + n.Value.InstrumentID));
					
			string inst = string.Empty;
			Console.WriteLine("请输入合约:");
			inst = Console.ReadLine();
			q.ReqSubscribeMarketData(inst);

		Inst:
			Console.WriteLine("q:退出  1-BK  2-SP  3-SK  4-BP  5-撤单");
			Console.WriteLine("a-交易所状态  b-委托  c-成交  d-持仓  e-合约  f-权益 g-换合约");

			DirectionType dire = DirectionType.Buy;
			OffsetType offset = OffsetType.Open;
			c = Console.ReadKey().KeyChar;
			switch (c)
			{
				case '1':
					dire = DirectionType.Buy;
					offset = OffsetType.Open;
					break;
				case '2':
					dire = DirectionType.Sell;
					offset = OffsetType.Close;
					break;
				case '3':
					dire = DirectionType.Sell;
					offset = OffsetType.Open;
					break;
				case '4':
					dire = DirectionType.Buy;
					offset = OffsetType.Close;
					break;
				case '5':
					t.ReqOrderAction(253);
					break;
				case 'a':
					Console.WriteLine(t.DicExcStatus.Aggregate("\r\n交易所状态", (cur, n) => cur + "\r\n" + n.Key + "=>" + n.Value));
					break;
				case 'b':
					Console.ForegroundColor = ConsoleColor.Cyan;
					Console.WriteLine(t.DicOrderField.Aggregate("\r\n委托", (cur, n) => cur + "\r\n"
						+ n.Value.GetType().GetFields().Aggregate(string.Empty, (f, v) => f + string.Format("{0,12}", v.GetValue(n.Value)))));
					break;
				case 'c':
					Console.ForegroundColor = ConsoleColor.DarkCyan;
					Console.WriteLine(t.DicTradeField.Aggregate("\r\n成交", (cur, n) => cur + "\r\n"
						+ n.Value.GetType().GetFields().Aggregate(string.Empty, (f, v) => f + string.Format("{0,12}", v.GetValue(n.Value)))));
					break;
				case 'd': //持仓
					Console.ForegroundColor = ConsoleColor.DarkGreen;
					Console.WriteLine(t.DicPositionField.Aggregate("\r\n持仓", (cur, n) => cur + "\r\n"
						+ n.Value.GetType().GetFields().Aggregate(string.Empty, (f, v) => f + string.Format("{0,12}", v.GetValue(n.Value)))));
					break;
				case 'e':
					Console.WriteLine(t.DicInstrumentField.Aggregate("\r\n合约", (cur, n) => cur + "\r\n"
						+ n.Value.GetType().GetFields().Aggregate(string.Empty, (f, v) => f + string.Format("{0,12}", v.GetValue(n.Value)))));
					break;
				case 'f':
					Console.WriteLine(t.TradingAccount.GetType().GetFields().Aggregate("\r\n权益\t", (cur, n) => cur + ","
						+ n.GetValue(t.TradingAccount).ToString()));
					break;
				case 'g':
					Console.WriteLine("请输入合约:");
					inst = Console.ReadLine();
					q.ReqSubscribeMarketData(inst);
					break;
				case 'q':
					q.ReqUserLogout();
					t.ReqUserLogout();
					Thread.Sleep(2000); //待接口处理后续操作
					Environment.Exit(0);
					break;
			}
			if (c >= '1' && c <= '4')
			{
				Console.WriteLine("请选择委托类型: 1-限价  2-市价  3-FAK  4-FOK");
				OrderType ot = OrderType.Limit;
				switch (Console.ReadKey().KeyChar)
				{
					case '2':
						ot = OrderType.Market;
						break;
					case '3':
						ot = OrderType.FAK;
						break;
					case '4':
						ot = OrderType.FOK;
						break;
				}
				MarketData tick;
				if (q.DicTick.TryGetValue(inst, out tick))
				{
					double price = dire == DirectionType.Buy ? tick.AskPrice : tick.BidPrice;
					_orderId = -1;
					Console.WriteLine(t.ReqOrderInsert(inst, dire, offset, price, 1, pType: ot));
					for (int i = 0; i < 3; ++i)
					{
						Thread.Sleep(200);
						if (-1 != _orderId)
						{
							Console.WriteLine("委托标识:" + _orderId);
							break;
						}
					}
				}
			}
			goto Inst;
		}