Example #1
0
        public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("交易登录失败:" + pRspInfo.ErrorMsg);
                return;
            }
            LogCenter.Log("交易登录成功");
            AccountCenter.Instance.IsTDLogin = true;
            this.instruments.Clear();
            LogCenter.Log("请求查询合约");
            int i = this.ReqQryInstrument(new ThostFtdcQryInstrumentField(), 0);

            if (i != 0)
            {
                LogCenter.Error("请求查询合约错误:" + CTPErrorHelper.GetError(i));
            }
            var field = new ThostFtdcSettlementInfoConfirmField
            {
                BrokerID    = AccountCenter.Instance.Account.BrokerID,
                InvestorID  = AccountCenter.Instance.Account.InvestorID,
                ConfirmDate = DateTime.Today.ToString(),
                ConfirmTime = DateTime.Now.ToLongTimeString()
            };

            LogCenter.Log("投资者结算结果确认");
            i = this.ReqSettlementInfoConfirm(field, 0);
            if (i != 0)
            {
                LogCenter.Error("投资者结算结果确认错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #2
0
        public void InsertOrder(InputOrder order)
        {
            LogCenter.Log("下单:" + order.ToString());
            var field = new ThostFtdcInputOrderField
            {
                BrokerID            = order.BrokerID,
                InvestorID          = order.InvestorID,
                Direction           = (EnumDirectionType)order.Direction,
                CombOffsetFlag_0    = (EnumOffsetFlagType)order.OffsetFlag,
                InstrumentID        = order.InstrumentID,
                LimitPrice          = order.Price,
                VolumeTotalOriginal = order.Volume,
                UserID = order.GroupID,

                CombHedgeFlag_0     = EnumHedgeFlagType.Speculation,
                ForceCloseReason    = EnumForceCloseReasonType.NotForceClose,
                ContingentCondition = EnumContingentConditionType.Immediately,
                TimeCondition       = EnumTimeConditionType.GFD,
                VolumeCondition     = EnumVolumeConditionType.AV,
                OrderPriceType      = EnumOrderPriceTypeType.LimitPrice,
                MinVolume           = 1,
                IsAutoSuspend       = 1,
            };
            int i = this.ReqOrderInsert(field, 0);

            if (i != 0)
            {
                LogCenter.Error("输入报单错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #3
0
 public override void OnRspUnSubMarketData(ThostFtdcSpecificInstrumentField pSpecificInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID != 0)
     {
         LogCenter.Error("取消订阅行情错误:" + pRspInfo.ErrorMsg);
     }
 }
Example #4
0
        public void ReqTradingAccount()
        {
            var field = new ThostFtdcQryTradingAccountField();
            int i     = this.ReqQryTradingAccount(field, 0);

            if (i != 0)
            {
                LogCenter.Error("查询资金账户错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #5
0
 public static void Speak(string content)
 {
     try
     {
         speecher.Speak(content);
     }
     catch (Exception e)
     {
         LogCenter.Error(e.Message);
     }
 }
Example #6
0
        public void ReqPositionDetial()
        {
            this.positionDetails.Clear();
            var qryPositionDetialField = new ThostFtdcQryInvestorPositionDetailField();
            int i = this.ReqQryInvestorPositionDetail(qryPositionDetialField, 0);

            if (i != 0)
            {
                LogCenter.Error("查询投资者持仓明细错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #7
0
 public static void UnSubscribe(string instrumentID)
 {
     subscribeSet.Remove(instrumentID);
     if (Instance != null && AccountCenter.Instance.IsMDLogin)
     {
         int i = Instance.UnSubscribeMarketData(new string[] { instrumentID });
         if (i != 0)
         {
             LogCenter.Error("退订行情错误:" + CTPErrorHelper.GetError(i));
         }
     }
 }
Example #8
0
        public override void OnRspUserLogin(ThostFtdcRspUserLoginField pRspUserLogin, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("行情登录失败:" + pRspInfo.ErrorMsg);
                return;
            }
            LogCenter.Log("行情登录成功");
            AccountCenter.Instance.IsMDLogin = true;
            int i = this.SubscribeMarketData(subscribeSet.ToArray());

            if (i != 0)
            {
                LogCenter.Error("订阅行情错误:" + CTPErrorHelper.GetError(i));
            }
        }
Example #9
0
        public override void OnFrontConnected()
        {
            LogCenter.Log("行情连接成功");
            var loginField = new ThostFtdcReqUserLoginField
            {
                BrokerID = AccountCenter.Instance.Account.BrokerID,
                UserID   = AccountCenter.Instance.Account.InvestorID,
                Password = AccountCenter.Instance.Account.Password
            };
            int i = this.ReqUserLogin(loginField, 0);

            if (i != 0)
            {
                LogCenter.Error("行情登录失败:" + CTPErrorHelper.GetError(i));
            }
        }
Example #10
0
        public override void OnRspQryInvestorPositionDetail(ThostFtdcInvestorPositionDetailField pInvestorPositionDetail, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo != null && pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("查询投资者持仓明细错误:" + pRspInfo.ErrorMsg);
                return;
            }
            if (pInvestorPositionDetail == null)
            {
                return;
            }
            var detial = new InvestorPositionDetail
            {
                InstrumentID          = pInvestorPositionDetail.InstrumentID,
                BrokerID              = pInvestorPositionDetail.BrokerID,
                InvestorID            = pInvestorPositionDetail.InvestorID,
                HedgeFlag             = (HedgeFlag)pInvestorPositionDetail.HedgeFlag,
                Direction             = (DirectionType)pInvestorPositionDetail.Direction,
                OpenDate              = pInvestorPositionDetail.OpenDate,
                TradeID               = pInvestorPositionDetail.TradeID,
                Volume                = pInvestorPositionDetail.Volume,
                OpenPrice             = pInvestorPositionDetail.OpenPrice,
                TradingDay            = pInvestorPositionDetail.TradingDay,
                SettlementID          = pInvestorPositionDetail.SettlementID,
                TradeType             = (TradeType)pInvestorPositionDetail.TradeType,
                CombInstrumentID      = pInvestorPositionDetail.CombInstrumentID,
                ExchangeID            = pInvestorPositionDetail.ExchangeID,
                CloseProfitByDate     = pInvestorPositionDetail.CloseProfitByDate,
                CloseProfitByTrade    = pInvestorPositionDetail.CloseProfitByTrade,
                PositionProfitByDate  = pInvestorPositionDetail.PositionProfitByDate,
                PositionProfitByTrade = pInvestorPositionDetail.PositionProfitByTrade,
                Margin                = pInvestorPositionDetail.Margin,
                ExchMargin            = pInvestorPositionDetail.ExchMargin,
                MarginRateByMoney     = pInvestorPositionDetail.MarginRateByMoney,
                MarginRateByVolume    = pInvestorPositionDetail.MarginRateByVolume,
                LastSettlementPrice   = pInvestorPositionDetail.LastSettlementPrice,
                SettlementPrice       = pInvestorPositionDetail.SettlementPrice,
                CloseVolume           = pInvestorPositionDetail.CloseVolume,
                CloseAmount           = pInvestorPositionDetail.CloseAmount,
            };

            this.positionDetails.Add(detial);
            if (bIsLast)
            {
                PositionViewModel.Instance.Update(this.positionDetails);
            }
        }
Example #11
0
 public override void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo != null && pRspInfo.ErrorID != 0)
     {
         LogCenter.Error("请求查询合约错误:" + pRspInfo.ErrorMsg);
         return;
     }
     if (pInstrument.ProductClass == EnumProductClassType.Futures)
     {
         this.instruments.Add(new Instrument(pInstrument));
     }
     if (bIsLast)
     {
         LogCenter.Log("收到期货合约数量:" + this.instruments.Count);
         InstrumentCenter.Instance.SetInstruments(this.instruments.OrderBy(p => p.InstrumentID).ToArray());
     }
 }
Example #12
0
        /// <summary>
        /// 错误日志记录(异步)
        /// </summary>
        /// <param name="model"></param>
        public static void AsyncErrorLog(ErrorModel model)
        {
            try
            {
                Task.Run(() =>
                {
                    try
                    {
                        var logger           = new LogCenter();
                        var errModel         = new LogService.ErrorModel();
                        errModel.Event       = "ErrorLog";
                        errModel.SubName     = model.SubName;
                        errModel.message     = model.message;
                        errModel.ErrorMsg    = model.ErrorMsg;
                        errModel.StackTrace  = model.StackTrace;
                        errModel.TargetName  = model.SubName;
                        errModel.SourceName  = model.SourceName;
                        errModel.ErrorUrl    = model.ErrorUrl;
                        errModel.RequestFrom = model.RequestFrom;
                        errModel.Ip          = model.Ip;
                        errModel.BrowserName = model.BrowserName;
                        errModel.BrowserVer  = model.BrowserVer;
                        errModel.UserAgent   = model.UserAgent;
                        errModel.AccId       = model.AccId;
                        errModel.Flag        = model.Flag;

                        logger.Error(errModel);
                    }
                    catch (Exception)
                    {
                    }
                });
            }
            catch (Exception)
            {
            }
        }
Example #13
0
 public override void OnFrontDisconnected(int nReason)
 {
     LogCenter.Error("行情断开:{0} {1}", nReason, CTPErrorHelper.GetFrontDisconnectedReason(nReason));
     AccountCenter.Instance.IsMDLogin = false;
 }
Example #14
0
        public override void OnRspQryTradingAccount(ThostFtdcTradingAccountField pTradingAccount, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo != null && pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("请求查询资金账户错误:" + pRspInfo.ErrorMsg);
                return;
            }
            if (pTradingAccount == null)
            {
                LogCenter.Error("请求查询资金账户错误,返回值为空");
                return;
            }
            var tradingAccount = new TradingAccount
            {
                BrokerID                       = pTradingAccount.BrokerID,
                AccountID                      = pTradingAccount.AccountID,
                PreMortgage                    = pTradingAccount.PreMortgage,
                PreCredit                      = pTradingAccount.PreCredit,
                PreDeposit                     = pTradingAccount.PreDeposit,
                PreBalance                     = pTradingAccount.PreBalance,
                PreMargin                      = pTradingAccount.PreMargin,
                InterestBase                   = pTradingAccount.InterestBase,
                Interest                       = pTradingAccount.Interest,
                Deposit                        = pTradingAccount.Deposit,
                Withdraw                       = pTradingAccount.Withdraw,
                FrozenMargin                   = pTradingAccount.FrozenMargin,
                FrozenCash                     = pTradingAccount.FrozenCash,
                FrozenCommission               = pTradingAccount.FrozenCommission,
                CurrMargin                     = pTradingAccount.CurrMargin,
                CashIn                         = pTradingAccount.CashIn,
                Commission                     = pTradingAccount.Commission,
                CloseProfit                    = pTradingAccount.CloseProfit,
                PositionProfit                 = pTradingAccount.PositionProfit,
                Balance                        = pTradingAccount.Balance,
                Available                      = pTradingAccount.Available,
                WithdrawQuota                  = pTradingAccount.WithdrawQuota,
                Reserve                        = pTradingAccount.Reserve,
                TradingDay                     = pTradingAccount.TradingDay,
                SettlementID                   = pTradingAccount.SettlementID,
                Credit                         = pTradingAccount.Credit,
                Mortgage                       = pTradingAccount.Mortgage,
                ExchangeMargin                 = pTradingAccount.ExchangeMargin,
                DeliveryMargin                 = pTradingAccount.DeliveryMargin,
                ExchangeDeliveryMargin         = pTradingAccount.ExchangeDeliveryMargin,
                ReserveBalance                 = pTradingAccount.ReserveBalance,
                CurrencyID                     = pTradingAccount.CurrencyID,
                PreFundMortgageIn              = pTradingAccount.PreFundMortgageIn,
                PreFundMortgageOut             = pTradingAccount.PreFundMortgageOut,
                FundMortgageIn                 = pTradingAccount.FundMortgageIn,
                FundMortgageOut                = pTradingAccount.FundMortgageOut,
                FundMortgageAvailable          = pTradingAccount.FundMortgageAvailable,
                MortgageableFund               = pTradingAccount.MortgageableFund,
                SpecProductMargin              = pTradingAccount.SpecProductMargin,
                SpecProductFrozenMargin        = pTradingAccount.SpecProductFrozenMargin,
                SpecProductCommission          = pTradingAccount.SpecProductCommission,
                SpecProductFrozenCommission    = pTradingAccount.SpecProductFrozenCommission,
                SpecProductPositionProfit      = pTradingAccount.SpecProductPositionProfit,
                SpecProductCloseProfit         = pTradingAccount.SpecProductCloseProfit,
                SpecProductPositionProfitByAlg = pTradingAccount.SpecProductPositionProfitByAlg,
                SpecProductExchangeMargin      = pTradingAccount.SpecProductExchangeMargin,
            };

            TradingAccountViewModel.Instance.Update(tradingAccount);
        }
Example #15
0
 public override void OnRspOrderInsert(ThostFtdcInputOrderField pInputOrder, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     LogCenter.Error("报单录入请求响应:{0} {1}", pRspInfo.ErrorMsg, pRspInfo.ErrorID);
 }
Example #16
0
        public override void OnRspQryInvestorPosition(ThostFtdcInvestorPositionField pInvestorPosition, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (pRspInfo != null && pRspInfo.ErrorID != 0)
            {
                LogCenter.Error("请求查询投资者持仓错误:" + pRspInfo.ErrorMsg);
                return;
            }
            if (pInvestorPosition == null)
            {
                return;
            }
            var position = new InvestorPosition
            {
                InstrumentID       = pInvestorPosition.InstrumentID,
                BrokerID           = pInvestorPosition.BrokerID,
                InvestorID         = pInvestorPosition.InvestorID,
                PosiDirection      = (PosiDirection)pInvestorPosition.PosiDirection,
                HedgeFlag          = (HedgeFlag)pInvestorPosition.HedgeFlag,
                PositionDate       = (PositionDateType)pInvestorPosition.PositionDate,
                YdPosition         = pInvestorPosition.YdPosition,
                Position           = pInvestorPosition.Position,
                LongFrozen         = pInvestorPosition.LongFrozen,
                ShortFrozen        = pInvestorPosition.ShortFrozen,
                LongFrozenAmount   = pInvestorPosition.LongFrozenAmount,
                ShortFrozenAmount  = pInvestorPosition.ShortFrozenAmount,
                OpenVolume         = pInvestorPosition.OpenVolume,
                CloseVolume        = pInvestorPosition.CloseVolume,
                OpenAmount         = pInvestorPosition.OpenAmount,
                CloseAmount        = pInvestorPosition.CloseAmount,
                PositionCost       = pInvestorPosition.PositionCost,
                PreMargin          = pInvestorPosition.PreMargin,
                UseMargin          = pInvestorPosition.UseMargin,
                FrozenMargin       = pInvestorPosition.FrozenMargin,
                FrozenCash         = pInvestorPosition.FrozenCash,
                FrozenCommission   = pInvestorPosition.FrozenCommission,
                CashIn             = pInvestorPosition.CashIn,
                Commission         = pInvestorPosition.Commission,
                CloseProfit        = pInvestorPosition.CloseProfit,
                PositionProfit     = pInvestorPosition.PositionProfit,
                PreSettlementPrice = pInvestorPosition.PreSettlementPrice,
                SettlementPrice    = pInvestorPosition.SettlementPrice,
                TradingDay         = pInvestorPosition.TradingDay,
                SettlementID       = pInvestorPosition.SettlementID,
                OpenCost           = pInvestorPosition.OpenCost,
                ExchangeMargin     = pInvestorPosition.ExchangeMargin,
                CombPosition       = pInvestorPosition.CombPosition,
                CombLongFrozen     = pInvestorPosition.CombLongFrozen,
                CombShortFrozen    = pInvestorPosition.CombShortFrozen,
                CloseProfitByDate  = pInvestorPosition.CloseProfitByDate,
                CloseProfitByTrade = pInvestorPosition.CloseProfitByTrade,
                TodayPosition      = pInvestorPosition.TodayPosition,
                MarginRateByMoney  = pInvestorPosition.MarginRateByMoney,
                MarginRateByVolume = pInvestorPosition.MarginRateByVolume,
                StrikeFrozen       = pInvestorPosition.StrikeFrozen,
                StrikeFrozenAmount = pInvestorPosition.StrikeFrozenAmount,
                AbandonFrozen      = pInvestorPosition.AbandonFrozen,
            };

            this.positions.Add(position);
            if (bIsLast)
            {
                PositionViewModel.Instance.Update(this.positions);
            }
        }
Example #17
0
 public override void OnRspError(ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     LogCenter.Error("交易错误:{0} {1}", pRspInfo.ErrorMsg, pRspInfo.ErrorID);
 }