예제 #1
0
파일: SYAttrbute.cs 프로젝트: jutao023/Wes
        private void productFakeQuote()
        {
            int len = maxQuoteLen;

            if (realQuoteBuy != null && realQuoteBuy.Length > 0 && (realQuoteSell == null || realQuoteSell.Length == 0))
            {
                double b   = realQuoteBuy[0].price;
                double s   = b + 1;
                double min = minPrice;
                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
            else if (realQuoteSell != null && realQuoteSell.Length > 0 && (realQuoteBuy == null || realQuoteBuy.Length == 0))
            {
                double b   = realQuoteSell[0].price - 1;
                double s   = b + 1;
                double min = minPrice;
                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
            else if ((realQuoteSell == null || realQuoteSell.Length == 0) && (realQuoteBuy == null || realQuoteBuy.Length == 0))
            {
                double s   = openPrice + 1;
                double b   = openPrice;
                double min = minPrice;
                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
            else
            {
                double s   = realQuoteBuy[0].price;
                double b   = realQuoteSell[0].price;
                double min = minPrice;
                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
        }
예제 #2
0
파일: SYAttrbute.cs 프로젝트: jutao023/Wes
        private void productFakeQuote()
        {
            int    len = maxQuoteLen;
            double min = minPrice;

            if (realQuoteBuy != null && realQuoteBuy.Length > 0 && (realQuoteSell == null || realQuoteSell.Length == 0))
            {
                double b = realQuoteBuy[0].price;
                if (b > upLimitPrice || b < openPrice)
                {
                    b = openPrice;
                }
                double s = b + min;

                if (floatLen > 0)
                {
                    b = Math.Round(b, floatLen);
                    s = Math.Round(s, floatLen);
                }

                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
            else if (realQuoteSell != null && realQuoteSell.Length > 0 && (realQuoteBuy == null || realQuoteBuy.Length == 0))
            {
                double s = realQuoteSell[0].price;
                if (s > upLimitPrice || s < openPrice)
                {
                    s = openPrice;
                }
                double b = s - min;

                if (floatLen > 0)
                {
                    b = Math.Round(b, floatLen);
                    s = Math.Round(s, floatLen);
                }
                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
            else if ((realQuoteSell == null || realQuoteSell.Length == 0) && (realQuoteBuy == null || realQuoteBuy.Length == 0))
            {
                double s = openPrice + min;
                double b = openPrice;
                if (floatLen > 0)
                {
                    b = Math.Round(b, floatLen);
                    s = Math.Round(s, floatLen);
                }

                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
            else
            {
                double s = realQuoteSell[0].price;
                double b = realQuoteBuy[0].price;
                if (floatLen > 0)
                {
                    b = Math.Round(b, floatLen);
                    s = Math.Round(s, floatLen);
                }
                if ((s > upLimitPrice || s < openPrice) && (b > upLimitPrice || b < openPrice))
                {
                    s = openPrice + min;
                    b = openPrice;
                }
                else if (s > upLimitPrice || s < openPrice)
                {
                    s = b + min;
                }
                else if (b > upLimitPrice || b < openPrice)
                {
                    b = s - min;
                }
                else
                {
                    if (s - b > 2 * min)
                    {
                        b = s - min;
                    }
                }
                for (int i = 0; i < len; i++)
                {
                    QuoteItem tmps = quoteSell[i];
                    tmps.price  = s;
                    tmps.amount = 0;

                    QuoteItem tmpb = quoteBuy[i];
                    tmpb.price  = b;
                    tmpb.amount = 0;

                    s += min;
                    b -= min;
                }
            }
        }
예제 #3
0
파일: SYAttrbute.cs 프로젝트: jutao023/Wes
        /// <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);
            }
        }
예제 #4
0
파일: SYAttrbute.cs 프로젝트: jutao023/Wes
        /// <summary>
        /// 加载交易信息
        /// </summary>
        public sealed override bool Load()
        {
            try
            {
                // 加载配置信息
                LoadConfig();

                #region 成员属性赋值
                //真实盘口深度
                maxRealQuoteLen = 10;
                //伪盘口深度
                maxQuoteLen = maxRealQuoteLen + 1;
                //交易对
                symbol = coinSymbol + "/CNY";
                //设置线程的休眠等级
                SetTimer(timerGrade);

                string mi    = minPrice.ToString();
                int    index = mi.IndexOf('.');
                if (index < mi.Length - 1)
                {
                    string flen = mi.Substring(index + 1);
                    floatLen = flen.Length;
                }
                #endregion

                // 获取当日涨跌停信息
                if (getPriceLimitToday() == false)
                {
                    return(false);
                }

                #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

                return(true);
            } catch (Exception ex)
            {
                OnError(EnumExceptionCode.交易异常, "加载配置信息异常即将交易停止!\r\n" + ex.ToString());
                return(false);
            }
        }