示例#1
0
        VolumePrice getBuyPrice()
        {
            try
            {
                Random      rd = new Random();
                VolumePrice vp = new VolumePrice();
                vp.volume = rd.Next(1, otherToBuy * OtherMore + 1);

                if (realQuoteBuy.Length < maxRealQuoteLen)
                {
                    if (realQuoteBuy.Length > 0)
                    {
                        vp.price = quoteBuy[realQuoteBuy.Length - 1].price - minPrice;
                        return(vp);
                    }
                    vp.price = quoteBuy[realQuoteBuy.Length].price;
                    return(vp);
                }

                int index = rd.Next(0, lev_buy.Length);
                vp.price = quoteBuy[lev_buy[index]].price;
                return(vp);
            }
            catch
            {
                return(null);
            }
        }
示例#2
0
        VolumePrice getSellPrice()
        {
            try
            {
                Random      rd = new Random();
                VolumePrice vp = new VolumePrice();
                vp.volume = rd.Next(1, otherToSell * OtherMore + 1);

                if (realQuoteSell.Length < maxRealQuoteLen)
                {
                    if (realQuoteSell.Length > 0)
                    {
                        vp.price = realQuoteSell[realQuoteSell.Length - 1].price + minPrice;
                        return(vp);
                    }
                    vp.price = quoteSell[realQuoteSell.Length].price;
                    return(vp);
                }

                int index = rd.Next(0, lev_sell.Length);
                vp.price = quoteSell[lev_sell[index]].price;
                return(vp);
            }catch
            {
                return(null);
            }
        }
示例#3
0
        VolumePrice getBuyPrice()
        {
            try
            {
                Random      rd = new Random();
                VolumePrice vp = new VolumePrice();
                vp.volume = rd.Next(1, otherToBuy * OtherMore + 1);

                if (realQuoteBuy == null || realQuoteBuy.Length == 0)
                {
                    vp.price = quoteSell[0].price;
                    return(vp);
                }


                int len = quoteBuy.Length;
                if (len > realQuoteBuy.Length)
                {
                    len = realQuoteBuy.Length;
                }

                for (int i = 0; i < len; i++)
                {
                    double q  = quoteBuy[i].price;
                    double rq = realQuoteBuy[i].price;
                    if (q - rq > 0.0001 || q - rq < -0.0001)
                    {
                        vp.price = q;
                        return(vp);
                    }
                }

                if (realQuoteBuy.Length < maxRealQuoteLen)
                {
                    vp.price = quoteBuy[realQuoteBuy.Length - 1].price - minPrice;
                    return(vp);
                }
                int index = rd.Next(0, lev_buy.Length);
                vp.price = quoteBuy[lev_buy[index]].price;
                return(vp);
            }
            catch
            {
                return(null);
            }
        }
示例#4
0
        VolumePrice getMustSellPrice()
        {
            try
            {
                Random      rd  = new Random();
                VolumePrice mvp = new VolumePrice();
                mvp.volume = rd.Next(1, mustToSell * mustMore);
                if (realQuoteBuy.Length == 0)
                {
                    return(null);
                }

                mvp.price = realQuoteBuy[0].price;
                return(mvp);
            }
            catch
            {
                return(null);
            }
        }
示例#5
0
        VolumePrice getMustBuyPrice()
        {
            try
            {
                if (realQuoteSell == null || realQuoteSell.Length == 0)
                {
                    return(null);
                }

                Random      rd  = new Random();
                VolumePrice mvp = new VolumePrice();
                mvp.volume = rd.Next(1, mustToBuy * mustMore);
                mvp.price  = realQuoteSell[0].price;
                return(mvp);
            }
            catch
            {
                return(null);
            }
        }
示例#6
0
        public override void OnTimer()
        {
            try
            {
                timerCount++;

                #region 委托单
                //开仓  空
                if (timerCount % 5 == 0)
                {
                    limitCount++;
                    VolumePrice vp = getSellPrice();
                    // 盘口单
                    if (vp != null)
                    {
                        Sell(vp.volume, vp.price);
                    }
                    // 成交单
                    vp = getMustBuyPrice();
                    if (vp != null)
                    {
                        Buy(vp.volume, vp.price, true);
                    }
                }

                //开仓  多
                if ((timerCount - 2) % 5 == 0)
                {
                    limitCount++;
                    VolumePrice vp = getBuyPrice();
                    if (vp != null)
                    {
                        Buy(vp.volume, vp.price);
                    }
                    //成交单
                    vp = getMustSellPrice();
                    if (vp != null)
                    {
                        Sell(vp.volume, vp.price, true);
                    }
                }

                #endregion

                if (limitCount % 3 == 0)
                {
                    cancelSurpOrder(1);
                }

                #region 撤除沉余单
                // 查询所有未成交订单
                if (timerCount % maxOrderCount == 0)
                {
                    List <Order> orders = getAllOrder(coinSymbol);
                    if (orders != null && orders.Count > 0)
                    {
                        //拆分报单
                        OrderSplit(orders);
                        //撤除沉余单
                        cancelSurpOrder();
                    }
                }
                #endregion
            }
            catch
            {
            }
        }