Пример #1
0
 void DrawChart(long date, dynamic price)
 {
     if (GetCheckOnTimeByAPI(date.ToString()))
     {
         Short.Pop();
         Long.Pop();
         Trend.Pop();
     }
     Short.Push(Short.Count > 0 ? EMA.Make(specify.Short, Short.Count, price, Short.Peek()) : EMA.Make(price));
     Long.Push(Long.Count > 0 ? EMA.Make(specify.Long, Long.Count, price, Long.Peek()) : EMA.Make(price));
     Trend.Push(Trend.Count > 0 ? EMA.Make(specify.Trend, Trend.Count, price, Trend.Peek()) : EMA.Make(price));
 }
Пример #2
0
        internal void DrawChart(string time, int price)
        {
            if (GetCheckOnTimeByAPI(time))
            {
                Short.Pop();
                Long.Pop();
                Trend.Pop();
            }
            Short.Push(EMA.Make(specify.Short, Short.Count, price, Short.Peek()));
            Long.Push(EMA.Make(specify.Long, Long.Count, price, Long.Peek()));
            Trend.Push(EMA.Make(specify.Trend, Trend.Count, price, Trend.Peek()));
            double popShort = Short.Pop(), popLong = Long.Pop(), gap = popShort - popLong - (Short.Peek() - Long.Peek());

            Short.Push(popShort);
            Long.Push(popLong);

            if (specify.Short < Short.Count && specify.Long < Long.Count && specify.Trend < Trend.Count && price < Trend.Peek() && gap > 0 && (price <= Price || Price == 0) && price <= BuyPrice)
            {
                Price = API.OnReceiveOrder(Code, price);
            }
        }
Пример #3
0
        public override void OnReceiveDrawChart(object sender, SendConsecutive e)
        {
            if (GetCheckOnDate(e.Date))
            {
                Short.Pop();
                Long.Pop();
                Trend.Pop();
            }
            Trend.Push(Trend.Count > 0 ? EMA.Make(Line.Item3, Trend.Count, e.Price, Trend.Peek()) : EMA.Make(e.Price));
            Short.Push(Short.Count > 0 ? EMA.Make(Line.Item1, Short.Count, e.Price, Short.Peek()) : EMA.Make(e.Price));
            Long.Push(Long.Count > 0 ? EMA.Make(Line.Item2, Long.Count, e.Price, Long.Peek()) : EMA.Make(e.Price));

            if (e.Volume != 0 && e.Date.Length > 8 && Short.Count > 1 && Long.Count > 1)
            {
                double popShort = Short.Pop(), popLong = Long.Pop(), gap = popShort - popLong - (Short.Peek() - Long.Peek());
                Short.Push(popShort);
                Long.Push(popLong);
                var date = e.Date.Substring(6, 4);

                if (date.CompareTo(Base.Start) > 0 && date.CompareTo(Base.Transmit) < 0 && Strategics is Catalog.TrendsToCashflow tc &&
                    DateTime.TryParseExact(e.Date.Substring(0, 12), Base.FullDateFormat, CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime cInterval))
                {
                    if (Balance.Quantity > tc.ReservationQuantity - 1 && (Offer ?? int.MaxValue) < e.Price &&
                        OrderNumber.Any(o => o.Key[0] == '8' && o.Value == e.Price - GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee    += (uint)(e.Price * tc.ReservationQuantity * (Commission + Base.Tax));
                        Balance.Revenue  += (long)((e.Price - (Balance.Purchase ?? 0D)) * tc.ReservationQuantity);
                        Balance.Quantity -= tc.ReservationQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("8") && o.Value == e.Price - GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital -= profit.Value * tc.ReservationQuantity;
                            Offer    = profit.Value;
                        }
                    }
                    else if ((Bid ?? int.MinValue) > e.Price && OrderNumber.Any(o => o.Key[0] == '7' && o.Value == e.Price + GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee += (uint)(e.Price * Commission * tc.ReservationQuantity);
                        Balance.Purchase
                            = (double)((e.Price * tc.ReservationQuantity + (Balance.Purchase ?? 0D) * Balance.Quantity) / (Balance.Quantity + tc.ReservationQuantity));
                        Balance.Quantity += tc.ReservationQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("7") && o.Value == e.Price + GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital += profit.Value * tc.ReservationQuantity;
                            Bid      = profit.Value;
                        }
                    }
                    else if (Balance.Quantity > tc.TradingQuantity - 1 && OrderNumber.Any(o => o.Key[0] == '2' && o.Value == e.Price - GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee    += (uint)(e.Price * tc.TradingQuantity * (Commission + Base.Tax));
                        Balance.Revenue  += (long)((e.Price - (Balance.Purchase ?? 0D)) * tc.TradingQuantity);
                        Balance.Quantity -= tc.TradingQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("2") && o.Value == e.Price - GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital -= profit.Value * tc.TradingQuantity;
                        }
                    }
                    else if (OrderNumber.Any(o => o.Key.StartsWith("1") && o.Value == e.Price + GetQuoteUnit(e.Price, Market)))
                    {
                        CumulativeFee    += (uint)(e.Price * Commission * tc.TradingQuantity);
                        Balance.Purchase  = (double)((e.Price * tc.TradingQuantity + (Balance.Purchase ?? 0D) * Balance.Quantity) / (Balance.Quantity + tc.TradingQuantity));
                        Balance.Quantity += tc.TradingQuantity;
                        var profit = OrderNumber.First(o => o.Key.StartsWith("1") && o.Value == e.Price + GetQuoteUnit(e.Price, Market));

                        if (OrderNumber.Remove(profit.Key))
                        {
                            Capital += profit.Value * tc.TradingQuantity;
                        }
                    }
                    else if (Balance.Quantity > tc.TradingQuantity - 1 && OrderNumber.ContainsValue(e.Price) == false &&
                             e.Price > Trend.Peek() * (1 + tc.PositionRevenue) && e.Price > (Balance.Purchase ?? 0D) &&
                             gap < 0 && (tc.Interval == 0 || tc.Interval > 0 && cInterval.CompareTo(NextOrderTime) > 0))
                    {
                        var unit = GetQuoteUnit(e.Price, Market);

                        if (OrderNumber.ContainsValue(e.Price + unit) == false)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.신규매도)] = e.Price + unit;
                        }

                        if (tc.Interval > 0)
                        {
                            NextOrderTime = Base.MeasureTheDelayTime(tc.Interval, cInterval);
                        }
                    }
                    else if (tc.TradingQuantity > 0 && OrderNumber.ContainsValue(e.Price) == false && e.Price < Trend.Peek() * (1 - tc.PositionAddition) &&
                             gap > 0 && (tc.Interval == 0 || tc.Interval > 0 && cInterval.CompareTo(NextOrderTime) > 0))
                    {
                        var unit = GetQuoteUnit(e.Price, Market);

                        if (OrderNumber.ContainsValue(e.Price - unit) == false)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.신규매수)] = e.Price - unit;
                        }

                        if (tc.Interval > 0)
                        {
                            NextOrderTime = Base.MeasureTheDelayTime(tc.Interval, cInterval);
                        }
                    }
                }
                else if (date.CompareTo(Base.Transmit) > 0 && Strategics is Catalog.TrendsToCashflow cf)
                {
                    OrderNumber.Clear();
                    long revenue = Balance.Revenue - CumulativeFee, unrealize = (long)((e.Price - (Balance.Purchase ?? 0D)) * Balance.Quantity);
                    var  avg = EMA.Make(++Accumulative, revenue - TodayRevenue + unrealize - TodayUnrealize, Before);

                    if (cf.ReservationQuantity > 0 && Balance.Quantity > cf.ReservationQuantity - 1)
                    {
                        var stock = Market;
                        int quantity = Balance.Quantity / cf.ReservationQuantity, price = e.Price, sell = (int)((Balance.Purchase ?? 0D) * (1 + cf.ReservationRevenue)),
                            buy = (int)((Balance.Purchase ?? 0D) * (1 - cf.Addition)), upper = (int)(price * 1.3), lower = (int)(price * 0.7),
                            bPrice = Base.GetStartingPrice(lower, stock), sPrice = Base.GetStartingPrice(sell, stock);
                        sPrice = sPrice < lower ? lower + GetQuoteUnit(sPrice, stock) : sPrice;

                        while (sPrice < upper && quantity-- > 0)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.예약매도)] = sPrice;

                            for (int i = 0; i < cf.Unit; i++)
                            {
                                sPrice += GetQuoteUnit(sPrice, stock);
                            }
                        }
                        while (bPrice < upper && bPrice < buy)
                        {
                            OrderNumber[Base.GetOrderNumber((int)OrderType.예약매수)] = bPrice;

                            for (int i = 0; i < cf.Unit; i++)
                            {
                                bPrice += GetQuoteUnit(bPrice, stock);
                            }
                        }
                        Bid   = OrderNumber.Count > 0 && OrderNumber.Any(o => o.Key.StartsWith("7")) ? OrderNumber.Where(o => o.Key.StartsWith("7")).Max(o => o.Value) : 0;
                        Offer = OrderNumber.Count > 0 && OrderNumber.Any(o => o.Key.StartsWith("8")) ? OrderNumber.Where(o => o.Key.StartsWith("8")).Min(o => o.Value) : 0;
                    }
                    SendMessage = new Catalog.Strategics.Statistics
                    {
                        Key        = string.Concat("TC.", cf.AnalysisType),
                        Date       = e.Date.Substring(0, 6),
                        Cumulative = revenue + unrealize,
                        Base       = SendMessage.Base > Capital ? SendMessage.Base : Capital,
                        Statistic  = (int)avg,
                        Price      = (int)Trend.Peek()
                    };
                    Before         = avg;
                    TodayRevenue   = revenue;
                    TodayUnrealize = unrealize;
                }
            }