Example #1
0
 private void OnRtnInstrumentStatus_callback(IntPtr pTraderApi, ref CThostFtdcInstrumentStatusField pInstrumentStatus)
 {
     if (null != OnRtnInstrumentStatus)
     {
         OnRtnInstrumentStatus(this, new OnRtnInstrumentStatusArgs(pTraderApi, ref pInstrumentStatus));
     }
 }
Example #2
0
        private void OnRtnInstrumentStatus(IntPtr pTraderApi, ref CThostFtdcInstrumentStatusField pInstrumentStatus)
        {
            tdlog.Info("{0},{1},{2},{3},{4},{5},{6},{7}",
                pInstrumentStatus.ExchangeID, pInstrumentStatus.InstrumentID,
                pInstrumentStatus.InstrumentStatus, pInstrumentStatus.EnterReason,
                pInstrumentStatus.EnterTime,pInstrumentStatus.TradingSegmentSN,
                pInstrumentStatus.ExchangeInstID,pInstrumentStatus.SettlementGroupID);

            //通知单例
            CTPAPI.GetInstance().FireOnRtnInstrumentStatus(pInstrumentStatus);

            // 到IF的交割日,是否会收到两个有关IF的记录?如果在此进行清理是否会有问题?
            // 只会收到一条
            // 遍历是否过期
            if (pInstrumentStatus.InstrumentStatus == TThostFtdcInstrumentStatusType.Closed)
            {
                List<SingleOrder> tmpList = new List<SingleOrder>();
                string symbol = null;
                foreach(var order in _Orders4Cancel.Keys)
                {
                    // 如果与上次处理的是同一合约,就立即处理
                    if (symbol == order.Symbol)
                    {
                        EmitExpired(order);
                        tmpList.Add(order);
                        continue;
                    }

                    string altSymbol = order.Instrument.GetSymbol(Name);
                    string altExchange = order.Instrument.GetSecurityExchange(Name);

                    CThostFtdcInstrumentField _Instrument;
                    if (_dictInstruments.TryGetValue(altSymbol, out _Instrument))
                    {
                        altExchange = _Instrument.ExchangeID;
                        symbol = order.Symbol;
                    }

                    if (altExchange == pInstrumentStatus.ExchangeID)
                    {
                        EmitExpired(order);
                        tmpList.Add(order);
                    }
                }

                // 只能用一个临时列表来清理
                foreach (var o in tmpList)
                {
                    _Orders4Cancel.Remove(o);
                }
                tmpList.Clear();
            }
        }
Example #3
0
 public void FireOnRtnInstrumentStatus(CThostFtdcInstrumentStatusField pInstrumentStatus)
 {
     if (null != OnRtnInstrumentStatus)
     {
         OnRtnInstrumentStatus(pInstrumentStatus);
     }
 }
Example #4
0
 void OnRtnInstrumentStatus(CThostFtdcInstrumentStatusField pInstrumentStatus)
 {
     // 由于只在有新消息过来时才会收到,所以可能认为不好测试,看不出效果
     // 在测试时,把插件属性的ResumeType改成THOST_TERT_RESTART,然后连接CTP就可以看到效果了。
     Console.WriteLine("==交易所状态");
     Console.WriteLine("{0},{1},{2}",
             pInstrumentStatus.ExchangeID, pInstrumentStatus.InstrumentID,
             pInstrumentStatus.InstrumentStatus);
 }
        private void OnRtnInstrumentStatus(IntPtr pTraderApi, ref CThostFtdcInstrumentStatusField pInstrumentStatus)
        {
            tdlog.Info("{0},{1},{2},{3}",
                pInstrumentStatus.ExchangeID, pInstrumentStatus.InstrumentID,
                pInstrumentStatus.InstrumentStatus, pInstrumentStatus.EnterReason);

            //通知单例
            CTPAPI.GetInstance().FireOnRtnInstrumentStatus(pInstrumentStatus);
        }
Example #6
0
 public OnRtnInstrumentStatusArgs(IntPtr pTraderApi, ref CThostFtdcInstrumentStatusField pInstrumentStatus)
 {
     this.pTraderApi = pTraderApi;
     this.pInstrumentStatus = pInstrumentStatus;
 }
        private void OnRtnInstrumentStatus(IntPtr pTraderApi, ref CThostFtdcInstrumentStatusField pInstrumentStatus)
        {
            tdlog.Info("{0},{1},{2},{3},{4},{5},{6},{7}",
                pInstrumentStatus.ExchangeID, pInstrumentStatus.InstrumentID,
                pInstrumentStatus.InstrumentStatus, pInstrumentStatus.EnterReason,
                pInstrumentStatus.EnterTime,pInstrumentStatus.TradingSegmentSN,
                pInstrumentStatus.ExchangeInstID,pInstrumentStatus.SettlementGroupID);

            //通知单例
            CTPAPI.GetInstance().FireOnRtnInstrumentStatus(pInstrumentStatus);

            // 到IF的交割日,是否会收到两个有关IF的记录?如果在此进行清理是否会有问题?
            // 只会收到一条
            // 遍历是否过期
            if (pInstrumentStatus.InstrumentStatus == TThostFtdcInstrumentStatusType.Closed)
            {
                Dictionary<GenericOrderItem, CThostFtdcOrderField> tmp = new Dictionary<GenericOrderItem, CThostFtdcOrderField>();
                foreach (var pair in orderMap.OrderItem_OrderField)
                {
                    if(pair.Value.ExchangeID == pInstrumentStatus.ExchangeID)
                    {
                        int cnt = pair.Key.GetLegNum();
                        foreach(var pair2 in orderMap.Order_OrderItem)
                        {
                            // 得找到OpenQuant层的单子
                            if(pair.Key == pair2.Value)
                            {
                                --cnt;
                                EmitExpired(pair2.Key);
                                if (cnt <= 0)
                                    break;
                            }
                        }
                        tmp[pair.Key] = pair.Value;
                    }
                }

                foreach (var pair in tmp)
                {
                    OnLastStatus(pair.Key, pair.Value.OrderSysID, pair.Value.OrderRef);
                }
                tmp.Clear();
            }
        }