示例#1
0
 //连接行情端
 private bool MarketConnect()
 {
     socketWorker = new SocketWorker();
     socketWorker.Init(this, coinSymbol);
     if (socketWorker.Connect())
     {
         Print("建立行情 socket 连接成功!");
         isConnect = true;
         return(true);
     }
     Print("建立行情 socket 连接失败!");
     runStatus = EnumRunStatus.行情连接异常;
     return(false);
 }
示例#2
0
        /// <summary>
        /// 加载交易信息
        /// </summary>
        public sealed override bool Load()
        {
            try
            {
                #region 成员属性赋值

                //用户ID
                userId = 100;
                //用户名
                userName = "";
                //密码
                password = "";

                //设置  开仓倍数 (必成交)
                mustMore = 1;
                //设置 开仓倍数  (非成交)
                OtherMore = 1;

                //真实盘口深度
                maxRealQuoteLen = 10;
                //伪盘口深度
                maxQuoteLen = maxRealQuoteLen + 1;

                //产品编号
                coinSymbol = "XDFYX";
                //交易对
                symbol = coinSymbol + "/CNY";
                //最小变动单位
                minPrice = 0.01;
                //线程休眠等级
                timerGrade = 1;
                //
                mustToBuy = 30;
                //
                mustToSell = 30;
                //
                otherToBuy = 80;
                //
                otherToSell = 80;

                maxOrderCount = 60;

                //设置线程的休眠等级
                SetTimer(timerGrade);

                #endregion

                #region 交易价格信息处理
                //查询当日交易的价格区间
                coinSymbolMarket = SYRequest.QureyCoinSymbolMarket(coinSymbol);
                if (coinSymbolMarket == null)
                {
                    Print("获取当日涨跌停信息失败,策略启动失败!");
                    return(false);
                }
                if (coinSymbolMarket.beginPrice == null || coinSymbolMarket.maxPrice == null || coinSymbolMarket.minPrice == null)
                {
                    Print("获取当日涨跌停信息有误,策略启动失败!");
                    return(false);
                }

                // 开盘价
                openPrice = (double)decimal.Round((decimal)coinSymbolMarket.beginPrice, 2);
                // 最高限价
                upLimitPrice = (double)decimal.Round((decimal)coinSymbolMarket.maxPrice, 2);
                // 最低限价
                lowLimitPrice = (double)decimal.Round((decimal)coinSymbolMarket.minPrice, 2);

                Print("获取当日涨跌停信息成功!");
                #endregion

                #region 更新用户持仓信息
                //查询所有持仓
                position = SYRequest.QureyPosition(userId, coinSymbol);
                if (position == null || position.balance == 0)
                {
                    Print("该账户不存在仓位信息!");
                }
                else
                {
                    Print("获取到所有仓位信息信息!");
                }
                #endregion

                #region 盘口信息更新
                //查询盘口信息
                Quote q = SYRequest.QureyQuote(symbol);
                realQuoteBuy  = q.bid.items.ToArray();
                realQuoteSell = q.ask.items.ToArray();
                int len = maxQuoteLen;
                quoteBuy  = new QuoteItem[len];
                quoteSell = new QuoteItem[len];
                for (int i = 0; i < len; i++)
                {
                    quoteBuy[i]  = new QuoteItem();
                    quoteSell[i] = new QuoteItem();
                }

                productFakeQuote();
                #endregion

                #region 建立行情连接
                socketWorker = new SocketWorker();
                if (!socketWorker.Connect())
                {
                    Print("建立行情 socket 连接失败,策略启动失败!");
                    return(false);
                }
                socketWorker.Init(this, symbol);
                Print("建立行情 socket 连接成功!");
                #endregion

                return(true);
            } catch (Exception ex)
            {
                OnError(EnumExceptionCode.其他异常, ex.ToString());
                return(false);
            }
        }