//资金查询响应 private void TraderAdapter_OnRspQryTradingAccount(ThostFtdcTradingAccountField pTradingAccount, ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast) { try { if (pTradingAccount != null) { //查询到的资金信息保存到文件中 var temp = string.Format( "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29}", pTradingAccount.TradingDay, pTradingAccount.AccountID, pTradingAccount.Available, pTradingAccount.Balance, pTradingAccount.BrokerID, pTradingAccount.CashIn, pTradingAccount.CloseProfit, pTradingAccount.Commission, pTradingAccount.Credit, pTradingAccount.CurrMargin, pTradingAccount.DeliveryMargin, pTradingAccount.Deposit, pTradingAccount.ExchangeDeliveryMargin, pTradingAccount.ExchangeMargin, pTradingAccount.FrozenCash, pTradingAccount.FrozenCommission, pTradingAccount.FrozenMargin, pTradingAccount.Interest, pTradingAccount.InterestBase, pTradingAccount.Mortgage, pTradingAccount.PositionProfit, pTradingAccount.PreBalance, pTradingAccount.PreCredit, pTradingAccount.PreDeposit, pTradingAccount.PreMargin, pTradingAccount.PreMortgage, pTradingAccount.Reserve, pTradingAccount.SettlementID, pTradingAccount.Withdraw, pTradingAccount.WithdrawQuota); var moneyFile = MyUtils.AssemblyPath + "money.csv"; try { var dicMoney = new Dictionary <string, string>(); if (File.Exists(moneyFile)) { var sr = new StreamReader(moneyFile, Encoding.UTF8); string line; while ((line = sr.ReadLine()) != null) { dicMoney[line] = line; } sr.Close(); dicMoney[temp] = temp; File.Delete(moneyFile); var sw = new StreamWriter(moneyFile, true, Encoding.UTF8); foreach (var s in dicMoney) { sw.WriteLine(s.Value); } sw.Close(); } else { const string title = "交易日,投资者帐号,可用资金,期货结算准备金,经纪公司代码,资金差额,平仓盈亏,手续费,信用额度,当前保证金总额,投资者交割保证金,入金金额,交易所交割保证金,交易所保证金,冻结的资金,冻结的手续费,冻结的保证金,利息收入,利息基数,质押金额,持仓盈亏,上次结算准备金,上次信用额度,上次存款额,上次占用的保证金,上次质押金额,基本准备金,结算编号,出金金额,可取资金"; var sw = new StreamWriter(moneyFile, true, Encoding.UTF8); sw.WriteLine(title); sw.WriteLine(temp); sw.Close(); } } catch (Exception ex) { var errorMsg = ex.Message + ex.Source + ex.StackTrace; MessageBox.Show(string.Format("错误:处理{0}出现异常,异常信息:{1}", moneyFile, errorMsg)); } MyUtils.UpdateAccountInfo(pTradingAccount); } if (bIsLast) { Thread.Sleep(1000); ReqQryInvestorPositionDetail(); } } catch (Exception ex) { MessageBox.Show("查询资金回报异常:" + ex.Message); } }
private void TraderAdapter_OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestId, bool bIsLast) { try { if (MyUtils.IsWrongRspInfo(pRspInfo)) { MyUtils.ReportError(pRspInfo, "登录回报错误"); return; } if (bIsLast) { var temp = string.Format( "登录回报:经纪公司代码:{0},郑商所时间:{1},大商所时间:{2},中金所时间:{3},前置编号:{4},登录成功时间:{5},最大报单引用:{6},会话编号:{7},上期所时间:{8},交易系统名称:{9},交易日:{10},用户代码:{11}", pRspUserLogin.BrokerID, pRspUserLogin.CZCETime, pRspUserLogin.DCETime, pRspUserLogin.FFEXTime, pRspUserLogin.FrontID, pRspUserLogin.LoginTime, pRspUserLogin.MaxOrderRef, pRspUserLogin.SessionID, pRspUserLogin.SHFETime, pRspUserLogin.SystemName, pRspUserLogin.TradingDay, pRspUserLogin.UserID); _frontId = pRspUserLogin.FrontID; _sessionId = pRspUserLogin.SessionID; _tradingDay = pRspUserLogin.TradingDay; if (string.IsNullOrEmpty(pRspUserLogin.MaxOrderRef)) { CurrentOrderRef = 0; } else { CurrentOrderRef = Convert.ToInt32(pRspUserLogin.MaxOrderRef); } //比较交易所时间和本地时间的偏移值 DateTime shfeTime; try { shfeTime = Convert.ToDateTime(pRspUserLogin.SHFETime); } catch (Exception) { try { shfeTime = Convert.ToDateTime(pRspUserLogin.CZCETime); } catch (Exception) { try { shfeTime = Convert.ToDateTime(pRspUserLogin.DCETime); } catch (Exception) { throw new Exception("交易所时间格式不正确"); } } } MyUtils.ExchangeTimeOffset = ExchangeTime.Instance.GetSecFromDateTime(shfeTime) - ExchangeTime.Instance.GetSecFromDateTime(DateTime.Now); Thread.Sleep(1000); ReqSettlementInfoConfirm(); //结算确认 MyUtils.IsTraderReady = true; } else { MessageBox.Show("登录失败"); return; } } catch (Exception ex) { MessageBox.Show("登录失败," + ex.Message); } }