private void GetQuote_Click(object sender, EventArgs e) { if (this.STOCKCODE.Text.Length < 6) { MessageBox.Show("查询股票代码应该是6位!"); return;/// 代码错误 } if (0 == m_StockTrade.CurTradeID) { MessageBox.Show("请先登录服务器再操作!"); return;/// 没有登录 } ITradeRecord StockRecord = m_StockTrade.GetStockQuote(m_StockTrade.CurTradeID, this.STOCKCODE.Text); if (null == StockRecord) { MessageBox.Show("获取指定股票实时5档行情失败!"); return;/// 获取指定股票实时5档行情失败 } if (0 == StockRecord.RecordCount) { MessageBox.Show("获取指定股票实时5档行情数据无记录!"); return;/// 没有记录 } /// 弹出JSON格式数据包 MessageBox.Show(StockRecord.GetJsonString()); }
/// <summary> /// 委托交易提交成功通知 /// </summary> /// <param name="nReqID" Desc="本组件维护的交易请求序列号"></param> /// <param name="eExchangeType Desc="交易市场类型""></param> /// <param name="vRecord" Desc="交易结果对象"></param> public void OrderOKEvent(uint nReqID, EZMExchangeType eExchangeType, object vRecord) { ITradeRecord TradeRecord = (ITradeRecord)vRecord; if (null != TradeRecord) { uint nFieldCount = TradeRecord.FieldCount; uint nRecordCount = TradeRecord.RecordCount; if (nRecordCount > 0) { /// 弹出JSON格式数据包 MessageBox.Show(TradeRecord.GetJsonString()); /// 这儿测试马上取消委托,注意有些券商返回的委托成功记录第一个不是委托编号,需要调用GetValueByName来获取委托编号 string strOrderID = TradeRecord.GetValueByName(0, "委托编号").ToString(); ITradeRecord CancelRecord = m_spiTrade.CancelOrder(eExchangeType, strOrderID); if (null != CancelRecord) { /// 弹出JSON格式数据包 MessageBox.Show(CancelRecord.GetJsonString()); uint nRC = CancelRecord.RecordCount; /// 判断取消返回记录是否正常取消 CancelRecord.Clear(); CancelRecord = null; } } TradeRecord.Clear(); TradeRecord = null; } }
/// <summary> /// 委托交易提交成功通知 /// </summary> /// <param name="nReqID" Desc="本组件维护的交易请求序列号"></param> /// <param name="eExchangeType Desc="交易市场类型""></param> /// <param name="vRecord" Desc="交易结果对象"></param> public void OrderOKEvent(uint nReqID, EZMExchangeType eExchangeType, object vRecord) { ITradeRecord TradeRecord = (ITradeRecord)vRecord; if (null != TradeRecord) { uint nFieldCount = TradeRecord.FieldCount; uint nRecordCount = TradeRecord.RecordCount; if (nRecordCount > 0) { /// 弹出JSON格式数据包 MessageBox.Show(TradeRecord.GetJsonString()); /// 测试马上取消委托 ITradeRecord CancelRecord = m_spiTrade.CancelOrder(eExchangeType, (uint)TradeRecord.GetValueInt(0, 0)); if (null != CancelRecord) { /// 弹出JSON格式数据包 MessageBox.Show(CancelRecord.GetJsonString()); uint nRC = CancelRecord.RecordCount; /// 判断取消返回记录是否正常取消 CancelRecord.Clear(); CancelRecord = null; } } TradeRecord.Clear(); TradeRecord = null; } }
private void BUYBUT_Click(object sender, EventArgs e) { if (this.STOCKCODE.Text.Length < 6) { MessageBox.Show("查询股票代码应该是6位!"); return;/// 代码错误 } if (0 == m_StockTrade.CurTradeID) { MessageBox.Show("请先登录服务器再操作!"); return;/// 没有登录 } ITradeRecord StockRecord = m_StockTrade.GetStockQuote(m_StockTrade.CurTradeID, this.STOCKCODE.Text); if (null == StockRecord) { MessageBox.Show("获取指定股票实时5档行情失败!"); return;/// 获取指定股票实时5档行情失败 } if (0 == StockRecord.RecordCount) { MessageBox.Show("获取指定股票实时5档行情数据无记录!"); return;/// 没有记录 } /// 弹出JSON格式数据包 MessageBox.Show(StockRecord.GetJsonString()); /// 取当前价 var vBuy4 = StockRecord.GetValueFloat(0, 5); #if SYNC_OPT /// 同步提交委托,知道返回结果 EZMExchangeType eExchangeType = EZMExchangeType.EXCHANGETYPE_UNKNOWN; ITradeRecord OrderRecord = m_StockTrade.SyncCommitOrder(true, EZMStockOrderType.STOCKORDERTYPE_BUY, EZMOrderPriceType.ORDERPRICETYPE_LIMIT, this.STOCKCODE.Text, vBuy4, 500, out eExchangeType); if (null != OrderRecord) { if (OrderRecord.RecordCount > 0) { /// 弹出JSON格式数据包 MessageBox.Show(OrderRecord.GetJsonString()); /// 取消委托,需要获取前面委托成功的ID uint nOrderID = (uint)OrderRecord.GetValueInt(0, 0); m_StockTrade.CancelOrder(eExchangeType, nOrderID); } } #else /// 下面演示批量买入操作,通过AddOrder重复调用可以实现提交多条委托,然后调用CommitOrder一次性提交到服务器 var vBuy5 = StockRecord.GetValueByName(0, "买五价"); /// 限价买 uint nReq1 = m_StockTrade.AddOrder(EZMStockOrderType.STOCKORDERTYPE_BUY, EZMOrderPriceType.ORDERPRICETYPE_LIMIT, this.STOCKCODE.Text, (float)vBuy5, 500); uint nReq2 = m_StockTrade.AddOrder(EZMStockOrderType.STOCKORDERTYPE_BUY, EZMOrderPriceType.ORDERPRICETYPE_LIMIT, this.STOCKCODE.Text, vBuy4, 500); /// 真正提交委托操作,每个委托结果通过事件来通知,通过AddOrder返回的请求ID标识 m_StockTrade.CommitOrder(m_StockTrade.CurTradeID, true, EZMRunPriType.RUNPRITYPE_NORMAL); #endif StockRecord.Clear(); StockRecord = null; }
private void e52FjXBrXj() { try { this.indexReader = new BinaryReader((Stream) new FileStream(this.settings.TAQIndexFile.FullName, FileMode.Open, FileAccess.Read)); this.dataReader = new BinaryReader((Stream) new FileStream(this.settings.TAQDataFile.FullName, FileMode.Open, FileAccess.Read)); this.doNext = true; while (this.indexReader.PeekChar() != -1) { TradeIndexRecord tradeIndexRecord = this.aw5F84pdO9(); string str = ""; for (int index = 0; index < 10; ++index) { str = str + (object)Convert.ToChar(tradeIndexRecord.SYMBOL[index]); } Instrument instrument = this.ikWF6aB2Pa(str.Replace(RNaihRhYEl0wUmAftnB.aYu7exFQKN(12280), "")); if (instrument != null) { DateTime date = this.GetDate(tradeIndexRecord.TDATE); for (int num = tradeIndexRecord.BEGREC; num <= tradeIndexRecord.ENDREC; ++num) { ITradeRecord tradeRecord = this.ReadTradeDataRecord(num); Trade trade = new Trade(date.AddSeconds((double)tradeRecord.Time), tradeRecord.Price, tradeRecord.Size); instrument.Add(trade); } } this.EmitProgressEvent(); if (!this.doNext) { break; } } DataManager.Server.Flush(); } catch (Exception ex) { int num = (int)MessageBox.Show(((object)ex).ToString()); } finally { this.EmitStoppedEvent(); } }
private void GETHISDATA_Click(object sender, EventArgs e) { int CurSel = this.HISDATA.SelectedIndex; /// 获取17年5月8号到119号的历史数据 ITradeRecord StockRecord = m_StockTrade.QueryHisTradeData(m_StockTrade.CurTradeID, (EZMHisOrderType)(CurSel + 1), "20171113", "20171117"); if (null != StockRecord) { /// 遍历获取的数据 uint nFieldCount = StockRecord.FieldCount; uint nRecordCount = StockRecord.RecordCount; /// 弹出JSON格式数据包 MessageBox.Show(StockRecord.GetJsonString()); StockRecord.Clear(); StockRecord = null; } }
/// <summary> /// 登录服务器成功通知 /// </summary> /// <param name="vTrade" Desc="交易接口对象"></param> /// <param name="nTradeID" Desc="交易ID标识"></param> /// <param name="strHost" Desc="当前登录的交易服务器主机"></param> /// <param name="nPort" Desc="当前登录的交易服务器端口"></param> /// <param name="bLoginOK" Desc="是否登录成功标记"></param> public void LoginEvent(object vTrade, ushort nTradeID, string strHost, ushort nPort, bool bLoginOK) { if (null == m_spiTrade) { m_spiTrade = (IStockTrade)vTrade; } if (bLoginOK) { /// 异步事件处理中,请尽量不要有阻塞操作,避免影响底层流程正常处理。弹出消息框仅限于调试程序 if (1 == m_nTradeIndex) { MessageBox.Show("异步连接1成功!下面开始获取股东代码信息!"); } else if (2 == m_nTradeIndex) { MessageBox.Show("异步连接2成功!下面开始获取股东代码信息!"); } /// 可以检测连接状态有效性 bool bValid = m_spiTrade.ConnectValid; /// 获取股东信息对象 ITradeRecord ShareHolder = m_spiTrade.ShareHolderCode; if (null != ShareHolder) { MessageBox.Show(ShareHolder.GetJsonString()); ShareHolder = null; } MessageBox.Show("下面开始演示批量获取股票实时5档行情"); /// 异步获取多只股票的5档实时行情 m_spiTrade.GetStockQuotes(m_spiTrade.CurTradeID, "000001;000002;600001", EZMRunPriType.RUNPRITYPE_ABOVE_NORMAL); } else { /// 弹出登录错误提示 MessageBox.Show(m_spiTrade.LastErrDesc); } }
/// <summary> /// 查询股票实时5档行情返回数据通知 /// </summary> /// <param name="nReqID" Desc="本组件维护的交易请求序列号"></param> /// <param name="StockCode" Desc="单个股票编码"></param> /// <param name="vRecord" Desc="行情数据包"></param> public void StockQuoteEvent(uint nReqID, string StockCode, object vRecord) { ITradeRecord TradeRecord = (ITradeRecord)vRecord; if (null != TradeRecord) { uint nFieldCount = TradeRecord.FieldCount; uint nRecordCount = TradeRecord.RecordCount; /// 弹出JSON格式数据包 MessageBox.Show(TradeRecord.GetJsonString()); for (uint i = 0; i < nRecordCount; i++) { /// 遍历数据集合 for (uint j = 0; j < nFieldCount; j++) { /// 获取指定行和列的数据 var temVal = TradeRecord.GetValue(i, j); var temType = TradeRecord.GetDataType(j); } } } }
private void SELL_Click(object sender, EventArgs e) { if (0 == m_StockTrade.CurTradeID) { return;/// 没有登录 } ITradeRecord StockRecord = m_StockTrade.QueryTradeData(m_StockTrade.CurTradeID, EZMStockQueryType.STOCKQUERYTYPE_STOCK); if (null == StockRecord) { return; } uint nRecordCount = StockRecord.RecordCount; if (0 == nRecordCount) { MessageBox.Show("没有持股"); return; } /// 弹出JSON格式数据包 MessageBox.Show(StockRecord.GetJsonString()); for (uint nIndex = 0; nIndex < nRecordCount; nIndex++) { var varVal = StockRecord.GetValueByName(nIndex, "可用股份"); uint nCount = (uint)varVal; if (0 == nCount) { continue;/// 无可用股份 } string strStockName = StockRecord.GetValueByName(nIndex, "证券名称").ToString(); string strHolderCode = StockRecord.GetValueByName(nIndex, "股东代码").ToString(); string strStockCode = StockRecord.GetValueByName(nIndex, "证券代码").ToString(); /// 先获取当前证券的实时5档行情 ITradeRecord QuoteRecord = m_StockTrade.GetStockQuote(m_StockTrade.CurTradeID, strStockCode); if (null == QuoteRecord) { continue; } if (0 == QuoteRecord.RecordCount) { QuoteRecord.Clear(); QuoteRecord = null; continue; } /// 弹出JSON格式数据包 MessageBox.Show(QuoteRecord.GetJsonString()); varVal = QuoteRecord.GetValueByName(0, "卖一价"); float fSell = (float)varVal; EZMExchangeType eExchangeType = EZMExchangeType.EXCHANGETYPE_UNKNOWN; #if SYNC_OPT /// 同步操作,直到提交委托服务器返回结果 ITradeRecord SellRecord = m_StockTrade.SyncCommitOrder(true, EZMStockOrderType.STOCKORDERTYPE_SALE, EZMOrderPriceType.ORDERPRICETYPE_LIMIT, strStockCode, fSell, nCount, eExchangeType); if (null == SellRecord) { /// 提交失败,取错误描述 string strLastErr = m_StockTrade.LastErrDesc; QuoteRecord.Clear(); QuoteRecord = null; continue; } if (0 == SellRecord.RecordCount) { /// 提交委托异常 QuoteRecord.Clear(); QuoteRecord = null; continue; } /// 弹出JSON格式数据包 MessageBox.Show(SellRecord.GetJsonString()); /// 得到交易服务器返回的委托编号ID /// 方便测试,马上取消委托卖出 string strOrderID = SellRecord.GetValueByName(0, "委托编号").ToString(); m_StockTrade.CancelOrder(eExchangeType, strOrderID); #else /// 返回的请求ID,会由事件通知的时候传回,从而知道每个委托的实际结果 uint nReqID = m_StockTrade.AddOrder(EZMStockOrderType.STOCKORDERTYPE_SALE, EZMOrderPriceType.ORDERPRICETYPE_LIMIT, strStockCode, fSell, nCount, eExchangeType); #endif QuoteRecord.Clear(); QuoteRecord = null; } /// 批量提交委托,结果通过事件通知得到 m_StockTrade.CommitOrder(m_StockTrade.CurTradeID, true, EZMRunPriType.RUNPRITYPE_NORMAL); StockRecord.Clear(); StockRecord = null; }
private void GETTRADEDATA_Click(object sender, EventArgs e) { EZMStockQueryType eQueryType = EZMStockQueryType.STOCKQUERYTYPE_UNKNOWN; int CurSel = this.TRADEDATA.SelectedIndex; switch (CurSel) { case 0: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_CAPITAL; break; case 1: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_STOCK; break; case 2: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_TODAYORDER; break; case 3: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_TODAYTRADE; break; case 4: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_TODAYCANREVOKE; break; case 5: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_SHAREHOLDERCODE; break; case 6: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_BALANCEOFFINANCING; break; case 7: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_BORROWFUNDLEFT; break; case 8: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_CANBORROWFUND; break; case 9: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_CANNEWSTOCK; break; case 10: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_CANNEWSTOCKLIMIT; break; case 11: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_ASSIGNNUMBER; break; case 12: eQueryType = EZMStockQueryType.STOCKQUERYTYPE_BALLOT; break; default: MessageBox.Show("错误查询类型!"); break; } ITradeRecord StockRecord = m_StockTrade.QueryTradeData(m_StockTrade.CurTradeID, eQueryType); if (null != StockRecord) { /// 遍历获取的数据 uint nFieldCount = StockRecord.FieldCount; uint nRecordCount = StockRecord.RecordCount; /// 弹出JSON格式数据包 MessageBox.Show(StockRecord.GetJsonString()); StockRecord.Clear(); StockRecord = null; } }
private void CONNECT_BTN_Click(object sender, EventArgs e) { /// 自动保持连接 m_StockTrade.AutoKeepConn = true; /// 设置为普通账号,true为信用账号 m_StockTrade.CreditAccount = false; /// 设置成交自动回报定时器1000毫秒,设为0表示不启用 m_StockTrade.ReportSuccessTimer = 1000; /// 设置券商 int CurSel = this.BROKERTYPE.SelectedIndex; m_StockTrade.BrokerType = BrokerMap[CurSel]; /// 设置登录账号类型 EZMLoginAccountType eAccountType = EZMLoginAccountType.LOGINIACCOUNTTYPE_MNCS; CurSel = this.ACCOUNTTYPE.SelectedIndex; if (1 == CurSel) { eAccountType = EZMLoginAccountType.LOGINIACCOUNTTYPE_CAPITAL; } else if (2 == CurSel) { eAccountType = EZMLoginAccountType.LOGINIACCOUNTTYPE_CUSTOMER; } m_StockTrade.AccountType = eAccountType; /// 设置登录服务器 m_StockTrade.CurServerHost = this.SERVERADDR.Text; m_StockTrade.CurServerPort = ushort.Parse(this.SERVERPORT.Text); /// 设置服务器交易账户和密码 m_StockTrade.LoginID = this.LOGINID.Text; m_StockTrade.TradePassword = this.LOGINPW.Text; if (0 == this.LOGINPW.Text.Length) { MessageBox.Show("请先输入登录密码!"); return; } /// 设置其他参数 m_StockTrade.TradeAccount = this.TRADEACCOUNT.Text; /// 交易账号,一般为资金账号 m_StockTrade.DepartmentID = ushort.Parse(this.DEPID.Text); /// 营业部ID #if SYNC_OPT /// 指定同步连接,直到返回结果 bool bRet = m_StockTrade.LogIn(false); if (bRet) { /// 无错误,获得登录成功的交易连接标识 ushort nTradeID = m_StockTrade.CurTradeID; MessageBox.Show("登录成功,下面开始获取股东代码信息!"); /// 获得股东信息 ITradeRecord TradeRecord = m_StockTrade.ShareHolderCode; if (null != TradeRecord) { /// 获得记录集的列数和行数 uint nFieldCount = TradeRecord.FieldCount; uint nRecordCount = TradeRecord.RecordCount; /// 弹出JSON格式数据包 MessageBox.Show(TradeRecord.GetJsonString()); for (uint i = 0; i < nRecordCount; i++) { /// 根据列字段名直接取数据,获取股东代码 var StockCode = TradeRecord.GetValueByName(i, "股东代码"); /// 遍历数据集合 for (uint j = 0; j < nFieldCount; j++) { /// 获取指定行和列的数据 var temVal = TradeRecord.GetValue(i, j); var temType = TradeRecord.GetDataType(j); } } } } #else /// 指定异步连接,事件回调的时候会传递自己的交易接口对象 bool bRet = m_StockTrade.LogIn(true); #endif if (!bRet) { /// 连接失败时获取错误描述和类型 string strErrDesc = m_StockTrade.LastErrDesc; EZMTradeErrType ErrType = m_StockTrade.LastErrType; MessageBox.Show(strErrDesc); } }
private void CONNECT_BTN_Click(object sender, EventArgs e) { /// 启用日志输出,便于调试程序 m_StockTrade.EnableLog = true; /// 自动保持连接 m_StockTrade.AutoKeepConn = true; /// 模拟测试 m_StockTrade.BrokerType = EZMBrokerType.BROKERTYPE_MNCS; /// 设置登录服务器 m_StockTrade.CurServerHost = this.SERVERADDR.Text; m_StockTrade.CurServerPort = ushort.Parse(this.SERVERPORT.Text); /// 设置模拟服务器交易账户和密码 m_StockTrade.LoginID = this.LOGINID.Text; m_StockTrade.TradePassword = this.LOGINPW.Text; if (0 == this.LOGINPW.Text.Length) { MessageBox.Show("请先输入登录密码!"); return; } /// 设置其他参数 m_StockTrade.TradeAccount = this.TRADEACCOUNT.Text;/// 交易账号,一般为资金账号 m_StockTrade.DepartmentID = ushort.Parse(this.DEPID.Text); #if SYNC_OPT /// 指定同步连接,直到返回结果 bool bRet = m_StockTrade.LogIn(false); if (bRet) { /// 无错误,获得登录成功的交易连接标识 ushort nTradeID = m_StockTrade.CurTradeID; MessageBox.Show("登录成功,下面开始获取股东代码信息!"); /// 获得股东信息 ITradeRecord TradeRecord = m_StockTrade.ShareHolderCode; if (null != TradeRecord) { /// 获得记录集的列数和行数 uint nFieldCount = TradeRecord.FieldCount; uint nRecordCount = TradeRecord.RecordCount; /// 弹出JSON格式数据包 MessageBox.Show(TradeRecord.GetJsonString()); for (int i = 0; i < nRecordCount; i++) { /// 根据列字段名直接取数据,获取股东代码 var StockCode = TradeRecord.GetValueByName(i, "股东代码"); /// 遍历数据集合 for (int j = 0; j < nFieldCount; j++) { /// 获取指定行和列的数据 var temVal = TradeRecord.GetValue(i, j); var temType = TradeRecord.GetDataType(j); } } } } #else /// 指定异步连接,事件回调的时候会传递自己的交易接口对象 bool bRet = m_StockTrade.LogIn(true); #endif if (!bRet) { /// 连接失败时获取错误描述和类型 string strErrDesc = m_StockTrade.LastErrDesc; EZMTradeErrType ErrType = m_StockTrade.LastErrType; MessageBox.Show(strErrDesc); } }