internal EsunnyTraderListener()
            {
                InitCallbackList();

                //创建回调
                _instance = (IntPtr)EsunnyWrapper.InvokeAPI(IntPtr.Zero, EsunnyWrapperAction.CreateTradeSpi, this.callbackStruct);
            }
예제 #2
0
 public void SubQuote(TEsQuoteReqField sub)
 {
     //TEsQuoteReqField sub = new TEsQuoteReqField();
     //sub.CmbType = 0;
     //sub.SubQuote = EsunnySubQuoteType.订阅;
     //sub.Exchange = EsunnyExchangeType.CZCE;
     //sub.Contract1 = symbolCode;
     EsunnyWrapper.InvokeAPI(this._instance, EsunnyWrapperAction.SubQuote, sub);
 }
            void OnLogin(TEsRspField rsp)
            {
                if (rsp.ErrorCode == 0)
                {
                    this.trader.isLogin = true;

                    StringBuilder s = new StringBuilder();
                    EsunnyWrapper.InvokeAPI(this.trader._instance, EsunnyWrapperAction.GetTradingDay, s);

                    Trace.WriteLine("交易日:" + s);
                }
                else
                {
                    PInvokeUtility.GetUnicodeString(rsp.ErrorInfo);
                    this.trader.isLogin = false;
                }


                EventProcessor.BeginInvoke(this.trader.LoginResponse, this.trader, new EsunnyEventArgs <TEsRspField>(rsp));
            }
예제 #4
0
        //public TEsOrderInsertReqField InsertOrder(TradingOrderParameter parameter)
        //{
        //  Symbol symbol = parameter.Symbol;

        //  TEsOrderInsertReqField req = new TEsOrderInsertReqField();

        //  if (symbol.IsCustomCombinSymbol)
        //  {

        //  }
        //  else
        //  {

        //    if (symbol.Market != null)
        //    {
        //      //交易所
        //      req.Exchange = EsunnyConvert.ConvertToEsunny(symbol.Market.MarketCode);
        //    }

        //    if (symbol.SymbolType == SymbolType.CommoditiesSpreadFutures)
        //    {
        //      CombinSymbol combinSymbol = symbol as CombinSymbol;

        //      if (combinSymbol.Items[0].SymbolBlock.BlockCode == combinSymbol.Items[1].SymbolBlock.BlockCode)
        //      {
        //        //跨期
        //        req.CmbType = EsunnyCombinOrderType.Spread;
        //      }
        //      else
        //      {
        //        //跨商品
        //        req.CmbType = EsunnyCombinOrderType.SpreadCommodity;
        //      }

        //      req.Contract1 = combinSymbol.Items[0].ExchangeSymbolCode.ToUpper();
        //      req.Contract2 = combinSymbol.Items[1].ExchangeSymbolCode.ToUpper();
        //    }
        //    else
        //    {
        //      //普通单
        //      req.CmbType = EsunnyCombinOrderType.Normal;
        //      req.Contract1 = symbol.ExchangeSymbolCode.ToUpper();
        //    }


        //    req.Direct = EsunnyConvert.ConvertToEsunny(parameter.Direction);
        //    req.Offset = EsunnyConvert.ConvertToEsunny(parameter.Offset);
        //    req.OrderPrice = Convert.ToDouble(parameter.Price);
        //    req.OrderVol = Convert.ToInt32(parameter.Volume);
        //    req.RequestID = this._requestID++;

        //    req.OrderType = EsunnyOrderType.LimitOrder;
        //    req.Hedge = EsunnyHedgeType.Speculation;

        //    InvokeAPI(EsunnyWrapperAction.OrderInsert, req);
        //  }

        //  return req;
        //}


        int InvokeAPI(EsunnyWrapperAction action, object req)
        {
            return(EsunnyWrapper.InvokeAPI(this._instance, action, req));

            //IntPtr p = IntPtr.Zero;

            //if (req != null)
            //{
            //  p = Marshal.AllocHGlobal(Marshal.SizeOf(req));

            //  Marshal.StructureToPtr(req, p, true);
            //}

            //int result = EsunnyWrapper.Process(this._instance, action, p);

            //if (req != null)
            //{
            //  Marshal.DestroyStructure(p, req.GetType());
            //}
        }
예제 #5
0
        public EsunnyTrader()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("4A35B623174363F3A1BDD4D66D1F66AC7A368C423BB68CAFD0C78CDBA812DAAD9AAD1C1052E60447B35F0E2237A83160554F");

            int cert = EsunnyWrapper.InvokeAPI(IntPtr.Zero, EsunnyWrapperAction.CertEsunnyApi, builder);

            if (cert == 0)
            {
                throw new LicenseException(typeof(EsunnyTrader));
            }

            builder = new StringBuilder(50);
            EsunnyWrapper.InvokeAPI(IntPtr.Zero, EsunnyWrapperAction.GetEsunnyApiVersion, builder);

            string ver = builder.ToString();

            Trace.WriteLine(ver);
        }
예제 #6
0
        public void Connect(string frontAddress, int port, string userID, string password)
        {
            this.userID   = userID;
            this.password = password;


            //this._instance = EsunnyWrapper.CreateTradeApi();
            this._instance = (IntPtr)EsunnyWrapper.InvokeAPI(IntPtr.Zero, EsunnyWrapperAction.CreateTradeApi, null);

            //监听器
            _listener        = new EsunnyTraderListener();
            _listener.trader = this;
            EsunnyWrapper.InvokeAPI(this._instance, EsunnyWrapperAction.TradeSetSpi, this._listener.Instance);

            TEsAddressField addr = new TEsAddressField();

            addr.Ip   = frontAddress;
            addr.Port = port;

            EsunnyWrapper.InvokeAPI(this._instance, EsunnyWrapperAction.TradeOpen, addr);
        }
예제 #7
0
        public void Connect(string frontAddress, int port)
        {
            this.frontAddress = frontAddress;
            this.port         = port;

            //创建实例
            this._instance = (IntPtr)EsunnyWrapper.InvokeAPI(IntPtr.Zero, EsunnyWrapperAction.CreateQuoteApi, null);

            //创建监听器
            _listener = new EsunnyQuoteListener();
            _listener._esunnyQuote = this;
            EsunnyWrapper.InvokeAPI(this._instance, EsunnyWrapperAction.QuoteSetSpi, this._listener.Instance);

            //设置行情服务器地址
            TEsAddressField addr = new TEsAddressField();

            addr.Ip   = frontAddress;
            addr.Port = port;

            //开始建立连接
            EsunnyWrapper.InvokeAPI(this._instance, EsunnyWrapperAction.QuoteOpen, addr);
        }
예제 #8
0
            internal EsunnyQuoteListener()
            {
                InitCallbackList();

                _instance = (IntPtr)EsunnyWrapper.InvokeAPI(IntPtr.Zero, EsunnyWrapperAction.CreateQuoteSpi, this.callbackStruct);
            }