Esempio n. 1
0
 private void OnRspUserLogin(ref CtpResponse rsp)
 {
     CtpLoginInfo = rsp.Item1.AsRspUserLogin;
     if (CtpLoginInfo != null && CtpConvert.CheckRspInfo(rsp.Item2))
     {
         UserLogin            = new RspUserLoginField();
         UserLogin.TradingDay = CtpConvert.GetDate(CtpLoginInfo.TradingDay);
         UserLogin.LoginTime  = CtpConvert.GetTime(CtpLoginInfo.LoginTime);
         UserLogin.UserID     = CtpLoginInfo.UserID;
         UserLogin.SessionID  = $"{CtpLoginInfo.FrontID}:{CtpLoginInfo.SessionID}";
         _publisher.Post(ConnectionStatus.Logined, UserLogin);
         if (string.IsNullOrEmpty(CtpLoginInfo.MaxOrderRef))
         {
             _orderRefId = 1;
         }
         else
         {
             _orderRefId = int.Parse(CtpLoginInfo.MaxOrderRef) + 1;
         }
         DoSettlementInfoConfirm();
     }
     else
     {
         SendError(rsp.Item2, nameof(OnRspUserLogin));
         _publisher.Post(ConnectionStatus.Disconnected);
     }
 }
Esempio n. 2
0
        private void OnRspUserLogin(ref CtpResponse rsp)
        {
            ctpLoginInfo = rsp.Item1.AsRspUserLogin;
            if (ctpLoginInfo != null && CtpConvert.CheckRspInfo(rsp.Item2))
            {
                if (!Connected)
                {
                    UserLogin            = new RspUserLoginField();
                    UserLogin.TradingDay = CtpConvert.GetDate(ctpLoginInfo.TradingDay);
                    UserLogin.LoginTime  = CtpConvert.GetTime(ctpLoginInfo.LoginTime);
                    UserLogin.UserID     = ctpLoginInfo.UserID;
                    UserLogin.SessionID  = $"{ctpLoginInfo.FrontID}:{ctpLoginInfo.SessionID}";
                    UserLogin.Text       = string.IsNullOrEmpty(ctpLoginInfo.MaxOrderRef) ? "1" : ctpLoginInfo.MaxOrderRef;
                    _orderRef            = int.Parse(UserLogin.Text);
                    _publisher.Post(ConnectionStatus.Logined, UserLogin);
#if CTPMINI
                    Connected = true;
                    _publisher.Post(ConnectionStatus.Confirmed);
                    _publisher.Post(ConnectionStatus.Done, UserLogin);
#else
                    DoSettlementInfoConfirm();
#endif
                }
                else
                {
                    spi.ProcessLog(new LogField(LogLevel.Debug, $"Ctpse trader({User.UserID}) login success"));
                }
            }
            else
            {
                SendError(rsp.Item2, nameof(OnRspUserLogin));
                _publisher.Post(ConnectionStatus.Disconnected);
            }
        }
Esempio n. 3
0
        private void ProcessQuery(ref CtpResponse rsp)
        {
            switch (rsp.TypeId)
            {
            case CtpResponseType.OnRspQryOrder:
                _queryManager?.Post(QueryType.ReqQryOrder, rsp);
                break;

            case CtpResponseType.OnRspQryTrade:
                _queryManager?.Post(QueryType.ReqQryTrade, rsp);
                break;

            case CtpResponseType.OnRspQryTradingAccount:
                _queryManager?.Post(QueryType.ReqQryTradingAccount, rsp);
                break;

            case CtpResponseType.OnRspQryInvestorPosition:
                _queryManager?.Post(QueryType.ReqQryInvestorPosition, rsp);
                break;

            case CtpResponseType.OnRspQryInstrument:
                _queryManager?.Post(QueryType.ReqQryInstrument, rsp);
                break;
            }
        }
Esempio n. 4
0
        private void OnRtnInstrumentStatus(ref CtpResponse rsp)
        {
            var status = rsp.Item1.AsInstrumentStatus;
            var field  = CtpConvert.GetInstrumentStatus(status);

            Spi.ProcessRtnInstrumentStatus(field);
        }
Esempio n. 5
0
        private void OnFrontDisconnected(ref CtpResponse rsp)
        {
            if (rsp.Item1.AsInt == null)
            {
                return;
            }

            var reason = rsp.Item1.AsInt.Value;

            SendError(reason, $"{User.UserID}");
        }
Esempio n. 6
0
        private void OnFrontConnected(ref CtpResponse rsp)
        {
            if (_lastDisconnectReason != NetworkReadError)
            {
                _publisher.Post(ConnectionStatus.Connected);
            }
#if CTPSE
            DoAuthenticate();
#else
            DoLogin();
#endif
        }
Esempio n. 7
0
        private void OnFrontConnected(ref CtpResponse rsp)
        {
            spi.ProcessLog(new LogField(LogLevel.Debug, $"Ctpse trader({User.UserID}) connected"));

            if (!Connected)
            {
                _publisher.Post(ConnectionStatus.Connected);
            }
#if CTPSE || CTPMINI
            DoAuthenticate();
#else
            DoLogin();
#endif
        }
Esempio n. 8
0
        private void OnRspAuthenticate(ref CtpResponse rsp)
        {
            var data = rsp.Item1.AsRspAuthenticate;

            if (data != null && CtpConvert.CheckRspInfo(rsp.Item2))
            {
                _publisher.Post(ConnectionStatus.Authorized);
                DoLogin();
            }
            else
            {
                SendError(rsp.Item2, nameof(OnRspAuthenticate));
                _publisher.Post(ConnectionStatus.Disconnected);
            }
        }
Esempio n. 9
0
 private void OnFrontConnected(ref CtpResponse rsp)
 {
     if (_lastDisconnectReason != NetworkReadError)
     {
         _publisher.Post(ConnectionStatus.Connected);
     }
     if (!string.IsNullOrEmpty(Server.AuthCode) && !string.IsNullOrEmpty(Server.UserProductInfo))
     {
         DoAuthenticate();
     }
     else
     {
         DoLogin();
     }
 }
Esempio n. 10
0
        private void OnRspSettlementInfoConfirm(ref CtpResponse rsp)
        {
            var data = rsp.Item1.AsSettlementInfoConfirm;

            if (data != null && CtpConvert.CheckRspInfo(rsp.Item2))
            {
                Connected = true;
                _publisher.Post(ConnectionStatus.Confirmed);
                _publisher.Post(ConnectionStatus.Done, UserLogin);
            }
            else
            {
                SendError(rsp.Item2, nameof(OnRspSettlementInfoConfirm));
                _publisher.Post(ConnectionStatus.Disconnected);
            }
        }
Esempio n. 11
0
 private void OnFrontDisconnected(ref CtpResponse rsp)
 {
     Connected = false;
     if (rsp.Item1.AsInt != null)
     {
         var reason = rsp.Item1.AsInt.Value;
         if (reason != _lastDisconnectReason)
         {
             SendError(reason, nameof(OnFrontDisconnected));
         }
         _lastDisconnectReason = reason;
         if (_lastDisconnectReason == NetworkReadError)
         {
             return;
         }
     }
     _publisher.Post(ConnectionStatus.Disconnected);
 }
        private void ProcessPosition(CtpResponse rsp)
        {
            var data = rsp.Item1.AsInvestorPosition;

            if (data == null)
            {
                return;
            }
            if (CtpConvert.CheckRspInfo(rsp.Item2))
            {
                _client.Spi.ProcessQryPosition(CtpConvert.GetPositionField(data), rsp.IsLast);
            }
            else
            {
                _client.SendError(rsp.Item2, nameof(ProcessPosition));
                _client.Spi.ProcessQryPosition(null, true);
            }
        }
        private void ProcessAccount(CtpResponse rsp)
        {
            var data = rsp.Item1.AsTradingAccount;

            if (data == null)
            {
                return;
            }
            if (CtpConvert.CheckRspInfo(rsp.Item2))
            {
                _client.Spi.ProcessQryAccount(CtpConvert.GetAccountField(data), rsp.IsLast);
            }
            else
            {
                _client.SendError(rsp.Item2, nameof(ProcessAccount));
                _client.Spi.ProcessQryAccount(null, true);
            }
        }
 private void ProcessInstrument(CtpResponse rsp)
 {
     try {
         var data = rsp.Item1.AsInstrument;
         if (data == null)
         {
             return;
         }
         if (CtpConvert.CheckRspInfo(rsp.Item2))
         {
             _client.Spi.ProcessQryInstrument(CtpConvert.GetInstrumentField(data), rsp.IsLast);
         }
         else
         {
             _client.SendError(rsp.Item2, nameof(ProcessInstrument));
             _client.Spi.ProcessQryInstrument(null, true);
         }
     }
     catch (Exception e) {
         _client.SendError(-1, e.Message);
         _client.Spi.ProcessQryInstrument(null, true);
     }
 }
Esempio n. 15
0
        private void OnRspAuthenticate(ref CtpResponse rsp)
        {
            var data = rsp.Item1.AsRspAuthenticate;

            if (data != null && CtpConvert.CheckRspInfo(rsp.Item2))
            {
                if (!Connected)
                {
                    _publisher.Post(ConnectionStatus.Authorized);
                }
                else
                {
                    spi.ProcessLog(new LogField(LogLevel.Debug, $"Ctp trader({User.UserID}) authorized"));
                }

                DoLogin();
            }
            else
            {
                SendError(rsp.Item2, nameof(OnRspAuthenticate));
                _publisher.Post(ConnectionStatus.Disconnected);
            }
        }
Esempio n. 16
0
 public abstract void ProcessResponse(ref CtpResponse rsp);
Esempio n. 17
0
 private void OnRspError(ref CtpResponse rsp)
 {
     SendError(rsp.Item1.AsRspInfo, nameof(OnRspError));
 }
 public OrderRspEvent(CtpResponse response)
 {
     Response = response;
 }
 public void Post(CtpResponse rsp)
 {
     _action.Post(new OrderRspEvent(rsp));
 }
 private void OnRtnInstrumentStatus(ref CtpResponse rsp)
 {
 }
Esempio n. 21
0
 private void OnRspQryDepthMarketData(ref CtpResponse rsp)
 {
 }
Esempio n. 22
0
 private void OnRspError(ref CtpResponse rsp)
 {
     _queryManager.Post(QueryType.ReqError, rsp);
     SendError(rsp.Item1.AsRspInfo, nameof(OnRspError));
 }
 public void Post(CtpResponse rsp)
 {
     _action.Post(new QueryEvent(rsp));
 }
 public QueryEvent(CtpResponse rsp)
 {
     Response = rsp;
     Type     = null;
 }
Esempio n. 25
0
 private void ProcessDeal(ref CtpResponse rsp)
 {
     _processor.Post(rsp);
 }
 private void ProcessQuery(ref CtpResponse rsp)
 {
     _queryManager?.Post(rsp);
 }