Exemple #1
0
        public async Task Trade(CoursePoint curCourse)
        {
            _isBusy = true;
            await CheckComplOrders();

            var trackResult = Tracker.Track(curCourse);

            if (DbgSett.Options.Contains(DbgSett.DbgOption.ShowCourse))
            {
                Log.CreateLog("Trade", string.Format("Mode={0} Pt{1}", Tracker.Leap.Mode, trackResult));
            }
            switch (trackResult)
            {
            case EndPoint.None:
                if (Tracker.Leap.Mode == TrackMode.Neutral)
                {
                    TrySell(curCourse);
                }
                break;

            case EndPoint.UpEnd:
                TrySell(curCourse); break;

            case EndPoint.DownEnd:
                if (AllowBuy(curCourse))
                {
                    Buyer.Buy(curCourse, Tracker);
                }
                break;
            }
            _isBusy = false;
        }
Exemple #2
0
        public EndPoint SetNeutral(CoursePoint course, double delta)
        {
            if (Math.Abs(LastPt.Course - course.Course) < delta)
            {
                return(EndPoint.None);
            }
            Mode = TrackMode.Neutral;
            if (Mode == TrackMode.Error) // первый запуск
            {
                if (Mode == TrackMode.Down)
                {
                    DownEnd = course;
                    return(EndPoint.None);
                }
                else
                {
                    UpEnd = course;
                    return(EndPoint.None);
                }
            }
            // основной режим

            if (course.Course - LastPt.Course < 0)
            {
                DownEnd = course;
                return(EndPoint.DownEnd);
            }
            UpBegin = course;
            return(EndPoint.UpEnd);
        }
Exemple #3
0
 public void Buy(CoursePoint buyPoint, CourseTracker tracker)
 {
     if (DbgSett.Options.Contains(DbgSett.DbgOption.ShowBuy))
     {
         Log.CreateLog("Buy", string.Format("{0} {1}", buyPoint, tracker.Leap.Mode));
     }
     _Order           = new Order(tracker.Market.Name, buyPoint.Course, Balance / PartsInvest);
     _Order.PlaceDate = buyPoint.Date; // для отладки по истории, в реальном случае поле затрется
     _apiDriver.Buy(_Order);
 }
Exemple #4
0
 private void TrySell(CoursePoint pt)
 {
     if (pt.Course < MinSell)
     {
         return;
     }
     foreach (var seller in Sellers)
     {
         seller.TrySell(pt);
     }
 }
Exemple #5
0
        private bool AllowBuy(CoursePoint pt)
        {
            if (pt.Course > MaxBuy)
            {
                return(false);
            }
            if (!Sellers.Any())
            {
                return(true);
            }
            double minPrice = Sellers.Min(s => s.BuyOrder.Price);
            double gap      = KSellDist * Tracker.Sett.Delta * Math.Sqrt(Sellers.Count);

            return(pt.Course < minPrice - gap);
        }
Exemple #6
0
        public async Task TrySell(CoursePoint point)
        {
            if (point.Course - BuyOrder.Price < BuyOrder.Price * _delta)
            {
                return;
            }
            SellOrder = new Order(BuyOrder.Pair, point.Course, BuyOrder.Amount);
            await _apiDriver.Sell(SellOrder);

            if (DbgSett.Options.Contains(DbgSett.DbgOption.ShowSell))
            {
                var mrg = point.Course - BuyOrder.Price * (1 + _delta);
                Log.CreateLog("Sell", string.Format("sell:{0} buy:{1} kd={2:0.000 00} mrg={3:0.000 00} mrg={4:0.000 00}",
                                                    point, BuyOrder.Point, (point.Course - BuyOrder.Price) / (_delta * BuyOrder.Price), mrg, mrg / BuyOrder.Price * 100));
            }
        }
Exemple #7
0
        public EndPoint SetDown(CoursePoint course, double delta)
        {
            switch (Mode)
            {
            case TrackMode.Neutral:
                Mode      = TrackMode.Down;
                DownBegin = course;
                return(EndPoint.None);

            case TrackMode.Up:
                Mode = TrackMode.Down;
                if (Math.Abs(LastPt.Course - course.Course) < delta)
                {
                    return(EndPoint.None);
                }
                UpEnd = course;
                return(EndPoint.UpEnd);

            default: return(EndPoint.None);
            }
        }