예제 #1
0
        public BrokerInfo GetBrokerInfo()
        {
            BrokerInfo brokerInfo = new BrokerInfo();

            if (IsConnected)
            {
                if (_bTdConnected)
                {
                    //tdlog.Info("GetBrokerInfo");
                }
                else
                {
                    //if (nGetBrokerInfoCount < 5)
                    //{
                    //    tdlog.Info("GetBrokerInfo,交易没有连接,查询无效,5次后将不显示");
                    //    ++nGetBrokerInfoCount;
                    //}
                    return(null);
                }

                BrokerAccount brokerAccount = new BrokerAccount(m_TradingAccount.AccountID);

                // account fields
                brokerAccount.BuyingPower = m_TradingAccount.Available;

                Type        t      = typeof(CZQThostFtdcTradingAccountField);
                FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance);
                foreach (FieldInfo field in fields)
                {
                    brokerAccount.AddField(field.Name, field.GetValue(m_TradingAccount).ToString());
                }

                DataRow[] rows = _dbInMemInvestorPosition.SelectAll();

                foreach (DataRow dr in rows)
                {
                    BrokerPosition brokerPosition = new BrokerPosition {
                        Symbol = dr[DbInMemInvestorPosition.InstrumentID].ToString()
                    };

                    int pos = (int)dr[DbInMemInvestorPosition.Position];

                    TZQThostFtdcPosiDirectionType PosiDirection = (TZQThostFtdcPosiDirectionType)dr[DbInMemInvestorPosition.PosiDirection];
                    if (TZQThostFtdcPosiDirectionType.Long == PosiDirection)
                    {
                        brokerPosition.LongQty = pos;
                    }
                    else if (TZQThostFtdcPosiDirectionType.Short == PosiDirection)
                    {
                        brokerPosition.ShortQty = pos;
                    }
                    else
                    {
                        if (pos >= 0)//净NET这个概念是什么情况?
                        {
                            brokerPosition.LongQty = pos;
                        }
                        else
                        {
                            brokerPosition.ShortQty = -pos;
                        }
                    }
                    brokerPosition.Qty = brokerPosition.LongQty - brokerPosition.ShortQty;
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.PosiDirection, PosiDirection.ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.HedgeFlag, ((TZQThostFtdcHedgeFlagType)dr[DbInMemInvestorPosition.HedgeFlag]).ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.PositionDate, ((TZQThostFtdcPositionDateType)dr[DbInMemInvestorPosition.PositionDate]).ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.LongFrozen, dr[DbInMemInvestorPosition.LongFrozen].ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.ShortFrozen, dr[DbInMemInvestorPosition.ShortFrozen].ToString());
                    brokerAccount.AddPosition(brokerPosition);
                }
                brokerInfo.Accounts.Add(brokerAccount);
            }

            return(brokerInfo);
        }
예제 #2
0
        public BrokerInfo GetBrokerInfo()
        {
            BrokerInfo brokerInfo = new BrokerInfo();

            if (IsConnected)
            {
                Console.WriteLine(string.Format("GetBrokerInfo:{0}", Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));
                //TraderApi.TD_ReqQryTradingAccount(m_pTdApi);
                //TraderApi.TD_ReqQryInvestorPosition(m_pTdApi, null);
                //timerAccount.Enabled = false;
                //timerAccount.Enabled = true;
                //timerPonstion.Enabled = false;
                //timerPonstion.Enabled = true;

                BrokerAccount brokerAccount = new BrokerAccount(m_TradingAccount.AccountID);

                // account fields
                brokerAccount.BuyingPower = m_TradingAccount.Available;

                Type        t      = typeof(CZQThostFtdcTradingAccountField);
                FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance);
                foreach (FieldInfo field in fields)
                {
                    brokerAccount.AddField(field.Name, field.GetValue(m_TradingAccount).ToString());
                }

                DataRow[] rows = _dbInMemInvestorPosition.SelectAll();

                foreach (DataRow dr in rows)
                {
                    BrokerPosition brokerPosition = new BrokerPosition {
                        Symbol = dr[DbInMemInvestorPosition.InstrumentID].ToString()
                    };

                    int pos = (int)dr[DbInMemInvestorPosition.Position];

                    TZQThostFtdcPosiDirectionType PosiDirection = (TZQThostFtdcPosiDirectionType)dr[DbInMemInvestorPosition.PosiDirection];
                    if (TZQThostFtdcPosiDirectionType.Long == PosiDirection)
                    {
                        brokerPosition.LongQty = pos;
                    }
                    else if (TZQThostFtdcPosiDirectionType.Short == PosiDirection)
                    {
                        brokerPosition.ShortQty = pos;
                    }
                    else
                    {
                        if (pos >= 0)//净NET这个概念是什么情况?
                        {
                            brokerPosition.LongQty = pos;
                        }
                        else
                        {
                            brokerPosition.ShortQty = -pos;
                        }
                    }
                    brokerPosition.Qty = brokerPosition.LongQty - brokerPosition.ShortQty;
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.PosiDirection, PosiDirection.ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.HedgeFlag, ((TZQThostFtdcHedgeFlagType)dr[DbInMemInvestorPosition.HedgeFlag]).ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.PositionDate, ((TZQThostFtdcPositionDateType)dr[DbInMemInvestorPosition.PositionDate]).ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.LongFrozen, dr[DbInMemInvestorPosition.LongFrozen].ToString());
                    brokerPosition.AddCustomField(DbInMemInvestorPosition.ShortFrozen, dr[DbInMemInvestorPosition.ShortFrozen].ToString());
                    brokerAccount.AddPosition(brokerPosition);
                }
                brokerInfo.Accounts.Add(brokerAccount);
            }

            return(brokerInfo);
        }